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( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
An R interface to BMC search API and full text XML
API DOCS: http://www.biomedcentral.com/about/api
No API key is required to use the BMC API.
Installation instructions
Development Version
install.packages("devtools") devtools::install_github("ropensci/bmc")
library("bmc")
out <- bmc_search(terms = 'fire', limit=2) out@results$entries[[1]]
The object returned from bmc_search is an object of class bmc. The default print gives back a list of length N, where each element has the contents for the article in question. We can inspect further elements of the bmc object with the @ symbol. We can get the urls element...
out@urls
...which has the urls you can use to go the paper in a browser
browseURL(out@urls[1])
which opens the paper in your default browser
We can also inspect the ids element, which has a list equal to the number you requested, where each element is of length 2, with a arxId, and a url. These two are used to construct the download url if you use bmc_xml.
out@ids
You can either pass in a url to the uris parameter in the bmc_xml function, or pass in the output of the bmc_search function to bmc_xml using the first parameter obj. First, passing in a url:
uri <- 'http://www.biomedcentral.com/content/download/xml/1471-2393-14-71.xml' bmc_xml(uris=uri)
Now the output from bmc_search()
out <- bmc_search(terms = 'science', limit=5) dat <- bmc_xml(out) length(dat)
Inspect the xml
dat[[1]]
Once you have XML content, you can go to work with e.g., xpath.
uri <- 'http://www.biomedcentral.com/content/download/xml/1471-2393-14-71.xml' xml <- bmc_xml(uris=uri) library("XML") xpathApply(xml[[1]], "//abs", xmlValue)
bmc in R doing citation(package = 'bmc')This package is part of a richer suite called fulltext, along with several other packages, that provides the ability to search for and retrieve full text of open access scholarly articles. We recommend using fulltext as the primary R interface to bmc unless your needs are limited to this single source.
Get citation information for bmc in R by running: citation(package = 'bmc')
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.