R/get_article_id.R

Defines functions get_article_id

Documented in get_article_id

#' Get the ID of a scientific article hosted on Scielo
#'
#' \code{get_article_id()} extracts the ID of an article's URL
#'
#' @param url a character vector with the URL of an article hosted on Scielo.
#'
#' @export
#'
#' @return The function returns a \code{character} vector with the article ID.
#'
#' @examples
#' \donttest{
#' id <- get_article_id(url = "http://www.scielo.br/scielo.php?script=sci_arttext&
#' pid=S1981-38212016000200201&lng=en&nrm=iso&tlng=en")
#' }

get_article_id <- function(url){

  # Inputs
  if(!is.character(url) | length(url) != 1) stop("Invalid 'url'.")
  page <- rvest::html_session(url)
  if(httr::status_code(page) != 200) stop("Article not found.")

  # Return
  id_select(url)
}

Try the rscielo package in your browser

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

rscielo documentation built on Aug. 22, 2019, 5:03 p.m.