Last active
December 3, 2019 11:57
-
-
Save njahn82/72173ce471124538726f1dfb674a1961 to your computer and use it in GitHub Desktop.
Elsevier invoice data check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(rcrossref) | |
| library(janitor) | |
| library(crminer) | |
| my_dois <- readxl::read_xlsx("dois_elsevier.xlsx") %>% | |
| clean_names() | |
| # call Crossref | |
| cr_df <- cr_works(my_dois$digital_object_identifier_doi, .progress = "text") | |
| # get CC licensed articles | |
| cc_df <- cr_df$data %>% | |
| select(doi, license, link) %>% | |
| unnest(cols = c(license)) %>% | |
| filter(grepl("creative", URL)) %>% | |
| rename(cc_license = URL, cc_content_version = content.version) | |
| # get XML full-text links for CC-licensed articles | |
| elsevier_tdm <- cc_df %>% | |
| unnest(cols = c(link)) %>% | |
| filter(content.type == "text/xml", | |
| intended.application == "text-mining", | |
| content.version == "vor") | |
| # defining a parsing function | |
| elsevier_parse <- function(tdm_url) { | |
| req <- crminer::crm_xml(tdm_url) | |
| email <- xml2::xml_find_first(req, "//ce:e-address") %>% | |
| xml2::xml_text() | |
| oa_sponsor_name <- xml2::xml_find_first(req, "//d1:coredata//d1:openaccessSponsorName") %>% | |
| xml2::xml_text() | |
| oa_sponsor_type <- xml2::xml_find_first(req, "//d1:coredata//d1:openaccessSponsorType") %>% | |
| xml2::xml_text() | |
| oa_article <- xml2::xml_find_first(req, "//d1:coredata//d1:openaccessArticle") %>% | |
| xml2::xml_text() | |
| oa_type <- xml2::xml_find_first(req, "//d1:coredata//d1:openaccessType") %>% | |
| xml2::xml_text() | |
| oa_archive <- xml2::xml_find_first(req, "//d1:coredata//d1:openArchiveArticle") %>% | |
| xml2::xml_text() | |
| data_frame(email, | |
| oa_sponsor_name, oa_sponsor_type, oa_article, oa_type, oa_archive, | |
| tdm_url) | |
| } | |
| # apply function on every XML full-text link to mine open access invoice data. | |
| elsevier_oa_info <- purrr::map(elsevier_tdm$URL, .f = purrr::safely(elsevier_parse)) | |
| # get data frame were the full-text API call was successful | |
| elsevier_oa_info_df <- purrr::map_df(elsevier_oa_info, "result") | |
| # merge it with data frame and export it | |
| els_df <- inner_join(elsevier_oa_info_df, elsevier_tdm, by = c("tdm_url" = "URL")) %>% | |
| select(1:10) | |
| left_join(my_dois, els_df, by = c("digital_object_identifier_doi" = "doi")) %>% | |
| write_csv("elsevier_output.csv") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment