R/epmc_ftxt_book.r

Defines functions epmc_ftxt_book

Documented in epmc_ftxt_book

#' Fetch Europe PMC books
#'
#' Use this function to retrieve book XML formatted full text for the Open
#' Access subset of the Europe PMC bookshelf.
#'
#' @param ext_id character, publication identifier. All book full texts are accessible
#' either by the PMID or the 'NBK' book number.

#' @export
#' @return xml_document
#'
#' @examples
#'   \dontrun{
#'   epmc_ftxt_book("NBK32884")
#'   }
epmc_ftxt_book <- function(ext_id = NULL) {
  if (is.null(ext_id))
    stop("Please provide an id. All book full texts are accessible either by the
         PMID or the 'NBK' book number")
  # call api
  req <- httr::RETRY("GET", base_uri(), path = paste(rest_path(), ext_id,
    "bookXML", sep = "/"))
  # check for http status
  httr::stop_for_status(req)
  # load xml into r
  httr::content(req, as = "text", encoding = "utf-8") %>%
    xml2::read_xml()
}

Try the europepmc package in your browser

Any scripts or data that you put into this service are public.

europepmc documentation built on Sept. 21, 2023, 1:07 a.m.