-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscopus_search_additional_DOIs.R
75 lines (51 loc) · 2.42 KB
/
scopus_search_additional_DOIs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Search for additional DOIs after running
# `scopus_search_DOIs(save_date_time_file = TRUE)`.
# Save the additional DOIs in a CSV file, and
# save all DOIS in another CSV file.
scopus_search_additional_DOIs =
function( query,
search_period,
quota = 5, # Scopus API quota
path, # directory path
save_date_time_file = TRUE, # save date and time in a text file
verbose = TRUE, # print progress in R console
console_print_DOIs = FALSE # print DOIs in R console
) {
require(rscopus)
# Error if API key missing
if(!have_api_key()) {
stop('The login key for the Scopus API has not been read in. Find out more at \n',
' https://cran.r-project.org/web/packages/rscopus/vignettes/api_key.html')
}
# Read in 'scopus_search_DOIs' function
source('https://raw.githubusercontent.com/pablobernabeu/rscopus_plus/main/scopus_search_DOIs.R')
require(dplyr)
# Previous DOIs
date_time_last_access =
readLines(paste0(path, 'date and time of previous retrieval of DOIs.txt'))
last_file = paste0(path, 'DOIs, ', date_time_last_access, '.csv')
previous_DOIs = read.csv(last_file)
# Latest DOIs
# Use tryCatch() to handle errors in scopus_search_DOIs
results = tryCatch({
scopus_search_plus(query, search_period, quota, verbose = verbose)
}, error = function(e) { # Print error message to console
print(paste("Error in nested function 'scopus_search_DOIs':", e$message))
})
DOIs = results[complete.cases(results$doi), 'doi']
date_time = as.character(format(Sys.time(), '%Y-%m-%d %H%M'))
file = paste0(path, 'DOIs, ', date_time, '.csv')
write.csv(unique(DOIs), file, row.names = FALSE)
# Find the DOIs that were not in the previous retrieval
additional_DOIs = DOIs[!DOIs %in% previous_DOIs$x]
unique(additional_DOIs) %>%
write.csv(paste0(path, 'additional DOIs, ',
date_time, '.csv'),
row.names = FALSE)
if(isTRUE(save_date_time_file)) {
fileConn = file(paste0(path, 'date and time of previous retrieval of DOIs.txt'))
writeLines(date_time, fileConn)
close(fileConn)
}
if(isTRUE(console_print_DOIs)) cat(additional_DOIs, '', sep = '\n')
}