Create a gist now

Instantly share code, notes, and snippets.

library('rorcid')

get orcid ids

x <- orcid(query = "keyword:ecology", rows = 70)
ids <- x$data$`orcid-identifier.path`

get works

x <- orcid_id(orcid = ids, profile = "works")

filter by publication year

library('dplyr')
library('stringi')

define a function to do work

filter_works <- function(z) {
  xx <- z[['works']]
  if (is.null(xx)) {
    tbl_df(NULL)
  } else {
    if (is.null(suppressWarnings(xx$`work-citation.citation`))) {
      tbl_df(NULL)
    } else {
      df <- tbl_df(xx)
      df %>% 
        mutate(
          year = 
            as.numeric(
              stri_extract(
                stri_extract(`work-citation.citation`, regex = "year = \\{?[0-9]+\\}?"), regex = "[0-9]+"
              )
            )
        ) %>% 
        filter(year == 2015)
    }
  }
}

single

filter one

filter_works(x[[2]])
#> # A tibble: 4 x 31
#>   put-code short-description       work-type work-source language-code
#>      <chr>             <lgl>           <chr>       <lgl>         <lgl>
#> 1 24614652                NA JOURNAL_ARTICLE          NA            NA
#> 2 24614638                NA JOURNAL_ARTICLE          NA            NA
#> 3 18570846                NA JOURNAL_ARTICLE          NA            NA
#> 4 18570845                NA JOURNAL_ARTICLE          NA            NA
#> # ... with 26 more variables: country <lgl>, visibility <chr>,
#> #   work-title.translated-title <lgl>, work-title.title.value <chr>,
#> #   work-title.subtitle.value <chr>, journal-title.value <chr>,
#> #   work-citation.work-citation-type <chr>, work-citation.citation <chr>,
#> #   publication-date.media-type <lgl>, publication-date.year.value <chr>,
#> #   publication-date.month.value <chr>, publication-date.day.value <chr>,
#> #   work-external-identifiers.work-external-identifier <list>,
#> #   work-external-identifiers.scope <lgl>, url.value <chr>,
#> #   work-contributors.contributor <list>, source.source-client-id <lgl>,
#> #   source.source-orcid.value <lgl>, source.source-orcid.uri <lgl>,
#> #   source.source-orcid.path <chr>, source.source-orcid.host <lgl>,
#> #   source.source-name.value <chr>, source.source-date.value <dbl>,
#> #   created-date.value <dbl>, last-modified-date.value <dbl>, year <dbl>

many

filter many

res <- lapply(x, filter_works)
bind_rows(res)
#> # A tibble: 59 x 41
#>    put-code short-description       work-type work-source language-code
#>       <chr>             <lgl>           <chr>       <lgl>         <lgl>
#> 1  24614652                NA JOURNAL_ARTICLE          NA            NA
#> 2  24614638                NA JOURNAL_ARTICLE          NA            NA
#> 3  18570846                NA JOURNAL_ARTICLE          NA            NA
#> 4  18570845                NA JOURNAL_ARTICLE          NA            NA
#> 5  19971959                NA JOURNAL_ARTICLE          NA            NA
#> 6  19971958                NA JOURNAL_ARTICLE          NA            NA
#> 7  24381237                NA JOURNAL_ARTICLE          NA            NA
#> 8  24379820                NA JOURNAL_ARTICLE          NA            NA
#> 9  24381236                NA JOURNAL_ARTICLE          NA            NA
#> 10 24379819                NA JOURNAL_ARTICLE          NA            NA
#> # ... with 49 more rows, and 36 more variables: country <lgl>,
#> #   visibility <chr>, work-title.translated-title <lgl>,
#> #   work-title.title.value <chr>, work-title.subtitle.value <chr>,
#> #   journal-title.value <chr>, work-citation.work-citation-type <chr>,
#> #   work-citation.citation <chr>, publication-date.media-type <lgl>,
#> #   publication-date.year.value <chr>, publication-date.month.value <chr>,
#> #   publication-date.day.value <chr>,
#> #   work-external-identifiers.work-external-identifier <list>,
#> #   work-external-identifiers.scope <lgl>, url.value <chr>,
#> #   work-contributors.contributor <list>, source.source-client-id <lgl>,
#> #   source.source-orcid.value <lgl>, source.source-orcid.uri <lgl>,
#> #   source.source-orcid.path <chr>, source.source-orcid.host <lgl>,
#> #   source.source-name.value <chr>, source.source-date.value <dbl>,
#> #   created-date.value <dbl>, last-modified-date.value <dbl>, year <dbl>,
#> #   journal-title <lgl>, url <lgl>, work-title.subtitle <lgl>,
#> #   publication-date.day <lgl>, country.value <chr>,
#> #   country.visibility <chr>, publication-date.month <lgl>,
#> #   publication-date <lgl>, work-external-identifiers <lgl>,
#> #   work-contributors <lgl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment