Skip to content

Commit

Permalink
get_eurostat_json to pass arguments to GET. Fixes #99.
Browse files Browse the repository at this point in the history
  • Loading branch information
Janne Huovari committed Oct 1, 2017
1 parent ad3e78a commit 0fd5e31
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 46 deletions.
65 changes: 41 additions & 24 deletions R/get_eurostat_json.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
#' @title Get Data from Eurostat API in JSON
#' @title Get Data from Eurostat API in JSON
#' @description Retrieve data from Eurostat API in JSON format.
#' @details Data to retrieve from \href{http://ec.europa.eu/eurostat/web/json-and-unicode-web-services}{The Eurostat Web Services} can be specified with filters. Normally, it is better to use JSON query through \code{\link{get_eurostat}}, than to use \code{\link{get_eurostat_json}} directly.
#' @details Queries are limited to 50 sub-indicators at a time.
#' A time can be filtered with fixed "time" filter or with "sinceTimePeriod"
#' and "lastTimePeriod" filters. A \code{sinceTimePeriod = 2000} returns
#' observations from 2000 to a last available. A \code{lastTimePeriod = 10}
#' returns a 10 last observations.
#' @details
#' Data to retrieve from
#' \href{http://ec.europa.eu/eurostat/web/json-and-unicode-web-services}{The
#' Eurostat Web Services} can be specified with filters. Normally, it is
#' better to use JSON query through \code{\link{get_eurostat}}, than to use
#' \code{\link{get_eurostat_json}} directly.
#'
#' Queries are limited to 50 sub-indicators at a time. A time can be
#' filtered with fixed "time" filter or with "sinceTimePeriod" and
#' "lastTimePeriod" filters. A \code{sinceTimePeriod = 2000} returns
#' observations from 2000 to a last available. A \code{lastTimePeriod = 10}
#' returns a 10 last observations.
#'
#' To use a proxy to connect, a \code{\link[httr]{use_proxy}} can be
#' passed to \code{\link[httr]{GET}}. For example
#' \code{get_eurostat_json(id, filters,
#' config = httr::use_proxy(url, port, username, password))}.
#'
#' @param id A code name for the dataset of interested. See the table of
#' contents of eurostat datasets for more details.
#' @param filters A named list of filters. Names of list objects are
#' Eurostat variable codes and values are vectors of observation codes.
#' If \code{NULL} (default) the whole
#' dataset is returned. See details for more on filters and
#' limitations per query.
#' contents of eurostat datasets for more details.
#' @param filters A named list of filters. Names of list objects are Eurostat
#' variable codes and values are vectors of observation codes. If \code{NULL}
#' (default) the whole dataset is returned. See details for more on filters
#' and limitations per query.
#' @param lang A language used for metadata (en/fr/de).
#' @param type A type of variables, "code" (default), "label" or "both". The
#' "both" will return a data_frame with named vectors, labels as values
#' and codes as names.
#' @param stringsAsFactors if \code{TRUE} (the default) variables are
#' converted to factors in original Eurostat order. If \code{FALSE}
#' they are returned as a character.
#' @param type A type of variables, "code" (default), "label" or "both". The
#' "both" will return a data_frame with named vectors, labels as values and
#' codes as names.
#' @param stringsAsFactors if \code{TRUE} (the default) variables are converted
#' to factors in original Eurostat order. If \code{FALSE} they are returned as
#' a character.
#' @param ... Other arguments passed on to \code{\link[httr]{GET}}. For example
#' a proxy parameters, see details.
#' .
#'
#' @return A dataset as a data_frame.
#' @export
#' @author Przemyslaw Biecek, Leo Lahti, Janne Huovari and Markus Kainu \email{ropengov-forum@@googlegroups.com} \url{http://github.com/ropengov/eurostat}
#' @author Przemyslaw Biecek, Leo Lahti, Janne Huovari and Markus Kainu
#' \email{ropengov-forum@@googlegroups.com}
#' \url{http://github.com/ropengov/eurostat}
#' @examples
#' \dontrun{
#' tmp <- get_eurostat_json("cdh_e_fos")
#' yy <- get_eurostat_json(id = "nama_gdp_c", filters = list(geo=c("EU28", "FI"),
#' yy <- get_eurostat_json(id = "nama_gdp_c", filters = list(geo=c("EU28", "FI"),
#' unit="EUR_HAB",
#' indic_na="B1GM"))
#' indic_na="B1GM"))
#' }
#' @keywords utilities database
get_eurostat_json <- function(id, filters = NULL,
type = c("code", "label", "both"),
lang = c("en", "fr", "de"),
stringsAsFactors = default.stringsAsFactors()){
stringsAsFactors = default.stringsAsFactors(),
...){

#get response
url <- eurostat_json_url(id = id, filters = filters, lang = lang)
resp <- httr::GET(url)
resp <- httr::GET(url, ...)
status <- httr::status_code(resp)

# check status and get json
Expand Down
59 changes: 37 additions & 22 deletions man/get_eurostat_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0fd5e31

Please sign in to comment.