R/source.R

Defines functions get_source

Documented in get_source

#' Get a specific data url
#'
#' @param fp Framework programme number (note: H2020 corresponds to 8).
#' @param what Type of data \code{c("projects", "organizations", "reports")}.
#'
#' @return A link to the CORDIS CSV dataset in \url{https://data.europa.eu/}.
#' @export get_source
#'
#' @examples
#' get_source(8)
#' get_source(7, "reports")
#' get_source(6, "organizations")
get_source <- function(fp = 8, what = "projects") {
  stopifnot(fp %in% 1:8)
  stopifnot(what %in% c("projects", "organizations", "reports"))

  if (fp == 8) { # h2020 exception
    fp_slug <- "h2020"
  } else {
    fp_slug <- glue::glue("fp{ fp }")
  }

  cordis_url <- "https://cordis.europa.eu/data/"
  if (fp < 7) { # fp6 exception
    stopifnot(what %in% c("projects", "organizations"))
    cordis_url <- glue::glue("{ cordis_url }FP{ fp }/")
  }

  # glue the url
  data_url <- glue::glue("{ cordis_url }cordis-{ fp_slug }{ what }.csv")

  data_url %>%
    httr::http_error() %>%
    magrittr::not() %>%
    stopifnot()

  return(data_url)
}
zambujo/rcordis documentation built on June 14, 2020, 9:41 p.m.