@@ -18,29 +18,35 @@ citation_search_xdd <- function(identifiers) {
1818 identifiers <- check_identifiers(identifiers )
1919
2020 identifiers_enc <- utils :: URLencode(identifiers , reserved = TRUE )
21- results <- list ()
22- for (i in 1 : length(identifiers_enc )) {
23- results [[i ]] <-
24- fromJSON(curl(
25- paste0(
26- " https://xdd.wisc.edu/api/snippets?term=" ,
27- identifiers [i ],
28- " &corpus=all"
29- )
30- ))
31- }
21+ results <- list ()
22+
23+ for (i in seq_along(identifiers_enc )) {
24+ results [[i ]] <- tryCatch({
25+ fromJSON(curl(
26+ paste0(
27+ " https://xdd.wisc.edu/api/snippets?term=" ,
28+ identifiers [i ],
29+ " &corpus=all"
30+ )
31+ ))
32+ }, error = function (e ) {
33+ message(" Failed to fetch identifier " , identifiers [i ], " : " , e $ message )
34+ NULL # store NULL for failed calls
35+ })
36+ }
37+
38+ # initialize df for storing results in orderly fashion
39+ xdd_results <- data.frame (
40+ article_id = character (),
41+ article_title = character (),
42+ dataset_id = character (),
43+ source = character ()
44+ )
3245
33- # initialize df for storing results in orderly fashion
34- xdd_results <- data.frame (
35- article_id = character (),
36- article_title = character (),
37- dataset_id = character (),
38- source = character ()
39- )
4046
4147 # extract select information from results
4248 for (i in 1 : length(results )) {
43- if (length(results [[i ]]$ success $ data ) == 0 ) {
49+ if (length(results [[i ]]$ success $ data ) == 0 | is.null( results [[ i ]]) ) {
4450 # if no returned results, do this
4551 df <- data.frame (
4652 article_title = NA ,
0 commit comments