Skip to content

Commit 647caab

Browse files
committed
robustify metrics retrieval
1 parent d6e9147 commit 647caab

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

server/preprocessing/other-scripts/metrics.R

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ get_altmetrics <- function(dois) {
3838
tryCatch(
3939
{
4040
metrics <- altmetric_data(altmetrics(doi = doi, apikey = apikey_altmetric))
41+
Sys.sleep(0.1) # to avoid hitting rate limits
4142
results <- rbind.fill(results, metrics)
4243
},
4344
error = function(err) {
@@ -95,18 +96,7 @@ add_citations <- function(metadata) {
9596

9697
cc <- tryCatch(
9798
{
98-
cc_list <- list()
99-
for (doi in valid_dois) {
100-
tryCatch({
101-
count <- cr_citation_count(doi = doi)
102-
cc_list <- append(cc_list, list(count))
103-
}, error = function(err) {
104-
mlog$debug(gsub("[\r\n]", "", paste(err, doi, sep = " ")))
105-
cc_list <- append(cc_list, list(list(doi = doi, count = NA)))
106-
})
107-
Sys.sleep(0.05)
108-
}
109-
cc <- do.call(rbind.fill, cc_list)
99+
cr_citation_count(doi = valid_dois, async = TRUE)
110100
},
111101
error = function(err) {
112102
mlog$debug(gsub("[\r\n]", "", paste(err, doi, sep = " ")))

0 commit comments

Comments
 (0)