Skip to content

Instantly share code, notes, and snippets.

@njahn82
njahn82 / cr_cites.R
Last active January 22, 2018 15:51
Crossref Citation
cr_cites <- function(doi) {
tt <- rcrossref::cr_works_(doi) %>%
jsonlite::fromJSON() %>%
.$message
dplyr::data_frame(doi, `is-referenced-by-count` = tt$`is-referenced-by-count`)
}
my_response <- purrr::map(dois, purrr::safely(cr_cites))
my_df <- purrr::map_df(my_response, "result")
@njahn82
njahn82 / fetch_elsevier.R
Last active February 8, 2018 06:48
Retrieve random CC BY 4.0 articles from Elsevier as PDF
library(rcrossref)
library(purrr)
# helper function to retrieve pdfs with curl, requires api key
elsevier_fetch <- function(doi) {
u <- paste0("http://api.elsevier.com/content/article/doi/",
doi,
"?httpAccept=application%2Fpdf"
)
file_out <- URLencode(paste0(doi, ".pdf"), reserved = TRUE)
file.create(file_out)
@njahn82
njahn82 / ugoe_projects.json
Created February 11, 2018 12:22
openaire dataset projects ugoe
{"title":"Groups, Representations and Analysis in Number Theory","grant_id":"648329","acronym":"GRANT","start_date":"2015-09-01","end_date":"2020-08-31","call_id":"ERC-2014-CoG","funding_level_0":"H2020","funding_level_1":"ERC","funding_level_2":"ERC-COG","ec39":"","ecarticle29_3":"false","oamandatepublications":"true","org_name":["GEORG-AUGUST-UNIVERSITAT GOTTINGENSTIFTUNG OFFENTLICHEN RECHTS"],"org_country":["DE"]}
{"title":"'Marriage and Cultural Diversity in the German Empire'","grant_id":"707072","acronym":"MARDIV","start_date":"2016-09-19","end_date":"2018-09-18","call_id":"H2020-MSCA-IF-2015","funding_level_0":"H2020","funding_level_1":"MSCA-IF-EF-ST","ec39":"","ecarticle29_3":"false","oamandatepublications":"true","org_name":["GEORG-AUGUST-UNIVERSITAT GOTTINGENSTIFTUNG OFFENTLICHEN RECHTS"],"org_country":["DE"]}
{"title":"Private Pieties, Mundane Islam and New Forms of Muslim Religiosity: Impact on Contemporary Social and Political Dynamics","grant_id":"693457","acronym":"PrivatePieties","start_date":
@njahn82
njahn82 / figshare_zenodo.r
Created April 3, 2018 13:03
Compare word usage in Zenodo and Figshare titles
#' libraries needed
library(tidyverse)
library(jsonlite)
library(tidytext)
library(quanteda)
#' import zenodo https://zenodo.org/record/1065507#.WsNkb9NubFw
zenodo <-
readr::read_tsv("data/zenodo-all-metadata-records_2017-01-17.tsv") %>%
dplyr::select(title, doi)
# import figshare https://figshare.com/articles/Figshare_Public_Metadata_until_02_12_2014/1320834
@njahn82
njahn82 / rcrossref_unnest.md
Created May 29, 2018 16:01
Unnest rcrossref example
library(tidyverse)
library(rcrossref)
rcrossref::cr_works(query = "bernd weisshaar") %>%
  .$data %>%
  select(DOI, author) %>%
  mutate(author_df = map(author, as_data_frame)) %>%
  unnest(author_df)
@njahn82
njahn82 / wikibase_openaire.md
Last active June 17, 2018 13:33
openaire data description

What is OpenAIRE?

  • supports the implementation of open access / open science mandates in Europe, especially those from the European Commission
  • interlinks scholarly works from more than 1,150 sources (e.g., repositories) with project information provided by the EC
  • makes these information discoverable

How to access data from OpenAIRE?

Web portal

@njahn82
njahn82 / reprex.md
Created August 8, 2018 09:56
Fetching journal info by title from Crossref
library(tidyverse)
#> ── Attaching packages ──────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1.9000     ✔ purrr   0.2.4     
#> ✔ tibble  1.4.2          ✔ dplyr   0.7.6     
#> ✔ tidyr   0.8.1          ✔ stringr 1.3.1     
#> ✔ readr   1.1.1          ✔ forcats 0.3.0
#> Warning: Paket 'dplyr' wurde unter R Version 3.5.1 erstellt
#> ── Conflicts ─────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
@njahn82
njahn82 / example.r
Created November 13, 2018 16:45
R4DS Join Excercise 13.4 Question 4
weather %>%
gather(6:14, key = "condition", value = "value") %>%
inner_join(flights) %>%
mutate(delayed = ifelse(dep_delay < 30, "on time", "delayed")) %>%
ggplot(aes(condition, value, color = delayed)) +
geom_boxplot() +
facet_wrap(~condition, scale = "free_y") +
scale_y_log10()
@njahn82
njahn82 / unpaywall_evidence.R
Last active March 5, 2019 21:18
Unpaywall evidence type
#' bq unpaywall dump
#'
#' connect to google bg with imported jsonl Unpaywall dump
library(DBI)
library(tidyverse)
library(bigrquery)
con <- dbConnect(
bigrquery::bigquery(),
project = "api-project-764811344545",
dataset = "oadoi_full"
@njahn82
njahn82 / results_short.csv
Created April 27, 2019 16:13
Upsetr conversion
ev_cat n
open (via free pdf) 2064941
open (via page says license) 729059
oa repository (via OAI-PMH title and first author match) 661745
oa journal (via doaj)&open (via page says license) 522859
oa journal (via doaj) 405607
oa journal (via doaj)&oa repository (via OAI-PMH doi match)&oa repository (via pmcid lookup)&open (via page says license) 390785
open (via crossref license) 336514
oa repository (via OAI-PMH doi match) 226068
oa repository (via OAI-PMH doi match)&oa repository (via pmcid lookup) 215211