rcitoid

Project Status: Active – The project has reached a stable, usable state and is being actively developed. cran checks R-check codecov rstudio mirror downloads cran version

library("knitr")
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
   lines <- options$output.lines
   if (is.null(lines)) {
     return(hook_output(x, options))  # pass to default hook
   }
   x <- unlist(strsplit(x, "\n"))
   more <- "..."
   if (length(lines)==1) {        # first n lines
     if (length(x) > lines) {
       # truncate the output, but add ....
       x <- c(head(x, lines), more)
     }
   } else {
     x <- c(if (abs(lines[1])>1) more else NULL,
            x[lines],
            if (length(x)>lines[abs(length(lines))]) more else NULL
           )
   }
   # paste these lines together
   x <- paste(c(x, ""), collapse = "\n")
   hook_output(x, options)
 })

knitr::opts_chunk$set(
  warning = FALSE,
  message = FALSE,
  collapse = TRUE,
  comment = "#>"
)

Client for the Citoid service https://www.mediawiki.org/wiki/Citoid

docs: https://en.wikipedia.org/api/rest_v1/#!/Citation/getCitation

There are two functions, both of which do the same things, except:

Even with cit_oid() though, you get a list of lists, and you may want to parse it to a data.frame. See an example below.

Install

Stable version

install.packages("rcitoid")

Development version

remotes::install_github("ropensci/rcitoid")

Load the package

library("rcitoid")

get citation data

use underscore method to get text

cit_oid_("10.1108/jd-12-2013-0166")

get citation data

DOI

cit_oid("10.1108/jd-12-2013-0166")

PMID

cit_oid(30446726)

PMCID

cit_oid("PMC4679344")

ISBN

cit_oid(1439895619)

parse to data.frame

because the resulting data is nested and can have missing data slots, it's probably easier to get raw text and manipulate from there.

library(dplyr)

pmid <- c(30446726, 30722046, 30687373, 30688010)
pmcid <- c("PMC4679344", "PMC6347797", "PMC6347793")
isbn <- 1439895619
dois <- c("10.1109/jsac.2011.110806", "10.1007/s00422-006-0078-4",
  "10.5040/9781474219624-0044", "10.1109/icemi.2009.5274826",
  "10.1109/wispnet.2017.8299996")
res <- cit_oid_(id = c(pmid, pmcid, isbn, dois))
tbl_df(bind_rows(lapply(res, jsonlite::fromJSON)))

Meta

ropensci_footer



ropensci/rcitoid documentation built on Sept. 14, 2022, 4:47 a.m.