Skip to content

Instantly share code, notes, and snippets.

@njahn82
Created March 4, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njahn82/b53c83e78116e0a221c3ebd374b6b8ea to your computer and use it in GitHub Desktop.
Save njahn82/b53c83e78116e0a221c3ebd374b6b8ea to your computer and use it in GitHub Desktop.
reprex_doi_validation
library(rcrossref)
library(purrr)

my_dois <-
  c(
    "skksks",
    "10.5281/zenodo.4032609",
    "10.1667/rr13708.1",
    "10.1016/s0021-9258(19)52311-0",
    "10.1093/med/9780199349302.003.0024",
    "10.4467/16890027ap.14.008.1445"
  )

# Is registered via doi.org

# Agency via doi.org

# call Crossref API
my_time_out <- function()
  3000
get_cr_md <- function(dois) {
  rcrossref::cr_works(dois, timeout_ms = my_time_out())[["data"]]
}
out <- purrr::map(my_dois, purrr::safely(get_cr_md))
#> Warning: 404 (client error): /works/skksks - Resource not found.
#> Warning: 404 (client error): /works/10.5281/zenodo.4032609 - Resource not found.
#> Warning: 404 (client error): /works/10.4467/16890027ap.14.008.1445 - Resource
#> not found.
# call failed
ok <-  purrr::map_lgl(purrr::map(out, "error"), is.null)
failed_calls <- my_dois[!ok]
failed_calls
#> character(0)

# succesfull calls
ok_dois <- my_dois[ok]
ok_dois
#> [1] "skksks"                             "10.5281/zenodo.4032609"            
#> [3] "10.1667/rr13708.1"                  "10.1016/s0021-9258(19)52311-0"     
#> [5] "10.1093/med/9780199349302.003.0024" "10.4467/16890027ap.14.008.1445"

# cr result
out_df <- purrr::map_df(out, "result")
out_df
#> # A tibble: 3 x 31
#>   alternative.id container.title created deposited published.print doi   indexed
#>   <chr>          <chr>           <chr>   <chr>     <chr>           <chr> <chr>  
#> 1 10.1667/RR137… Radiation Rese… 2014-1… 2019-08-… 2015-01         10.1… 2020-1…
#> 2 S002192581952… Journal of Bio… 2021-0… 2021-01-… 1955-09         10.1… 2021-0…
#> 3 <NA>           Chronic Pain M… 2016-0… 2017-11-… 2016-02         10.1… 2020-0…
#> # … with 24 more variables: issn <chr>, issue <chr>, issued <chr>,
#> #   member <chr>, page <chr>, prefix <chr>, publisher <chr>, score <chr>,
#> #   source <chr>, reference.count <chr>, references.count <chr>,
#> #   is.referenced.by.count <chr>, title <chr>, type <chr>, url <chr>,
#> #   volume <chr>, language <chr>, short.container.title <chr>, author <list>,
#> #   reference <list>, subject <chr>, link <list>, license <list>, isbn <chr>

# doi not in crossref
no_md_in_cr <- ok_dois[!ok_dois %in% out_df[["doi"]]]
no_md_in_cr
#> [1] "skksks"                         "10.5281/zenodo.4032609"        
#> [3] "10.4467/16890027ap.14.008.1445"

# doi in crossref
cr_dois <-  ok_dois[ok_dois %in% out_df[["doi"]]]

# not indexed as journal article
not_a_jrn_article <-
  cr_dois[out_df[["type"]] !=  "journal-article"]
not_a_jrn_article
#> [1] "10.1093/med/9780199349302.003.0024"

# dois for further tranformation and compliance check
cr_dois[out_df[["type"]] ==  "journal-article"]
#> [1] "10.1667/rr13708.1"             "10.1016/s0021-9258(19)52311-0"

# md for further tranformation and compliance check
out_df[out_df[["type"]] ==  "journal-article", ]
#> # A tibble: 2 x 31
#>   alternative.id container.title created deposited published.print doi   indexed
#>   <chr>          <chr>           <chr>   <chr>     <chr>           <chr> <chr>  
#> 1 10.1667/RR137… Radiation Rese… 2014-1… 2019-08-… 2015-01         10.1… 2020-1…
#> 2 S002192581952… Journal of Bio… 2021-0… 2021-01-… 1955-09         10.1… 2021-0…
#> # … with 24 more variables: issn <chr>, issue <chr>, issued <chr>,
#> #   member <chr>, page <chr>, prefix <chr>, publisher <chr>, score <chr>,
#> #   source <chr>, reference.count <chr>, references.count <chr>,
#> #   is.referenced.by.count <chr>, title <chr>, type <chr>, url <chr>,
#> #   volume <chr>, language <chr>, short.container.title <chr>, author <list>,
#> #   reference <list>, subject <chr>, link <list>, license <list>, isbn <chr>

Created on 2021-03-04 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment