Learn R Programming

rsdmx (version 0.5-1)

readSDMX: readSDMX

Description

readSDMX is the main function to use to read SDMX data

Usage

readSDMX(file, isURL,
                provider, agencyId, resource, resourceId, version,
                flowRef, key, key.mode, start, end)

Arguments

file
path to SDMX-ML document that needs to be parsed
isURL
a value of class "logical" either the path is an url, and data has to be downloaded from a SDMXweb-repository. Default value is TRUE. Ignored in case readSDMX is used with helpers (based on the embedded list of SDMXServiceProvider
provider
an object of class "SDMXServiceProvider". If specified, file and isURL arguments will be ignored.
agencyId
an object of class "character" representing a provider id. It has to be match a default provider as listed ingetSDMXServiceProviders()
resource
an object of class "character" giving the SDMX service request resource to query e.g. "data". Recognized if a valid provider or provide id has been specified as argument.
resourceId
an object of class "character" giving a SDMX service resource Id, e.g. the id of a data structure
version
an object of class "character" giving a SDMX resource version, e.g. the version of a dataflow.
flowRef
an object of class "character" giving the SDMX flow ref id. Recognized if valid provider or provide id has been specified as argument.
key
an object of class "character" or "list" giving the SDMX data key/filter to apply. Recognized if a valid provider or provide id has been specified as argument. If key.mode is equal to "R" (default value), filter has to be an ob
key.mode
an object of class "character" indicating if the key has to be provided as an R object, ie a object of class "list" representing the filter(s) to apply. Default value is "R". Alternative value is "SDMX"
start
an object of class "integer" or "character" giving the SDMX start time to apply. Recognized if a valid provider or provide id has been specified as argument.
end
an object of class "integer" or "character" giving the SDMX end time to apply. Recognized if a valid provider or provide id has been specified as argument.

Value

  • an object of class "SDMX"

Examples

Run this code
# SDMX datasets
 #--------------
 # Not run
   # (local dataset examples)
   #with SDMX 2.0
   tmp <- system.file("extdata","Example_Eurostat_2.0.xml", package="rsdmx")
   sdmx <- readSDMX(tmp, isURL = FALSE)
   stats <- as.data.frame(sdmx)
   head(stats)

   #with SDMX 2.1
   tmpnew <- system.file("extdata","Example_Eurostat_2.1.xml", package="rsdmx")
   sdmx <- readSDMX(tmpnew, isURL = FALSE)
   stats <- as.data.frame(sdmx)
   head(stats)
   ## End(**Not run**)

 # Not run by 'R CMD check'
   # (reliable remote datasource but with possible occasional unavailability)

   #examples using embedded providers
   sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG",
                     key = list("TOT", NULL, NULL), start = 2011, end = 2011)
   stats <- as.data.frame(sdmx)
   head(stats)

   #examples using 'file' argument
   #using url (Eurostat REST SDMX 2.1)
   url <- paste("http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/",
                 "cdh_e_fos/..PC.FOS1.BE/?startperiod=2011&endPeriod=2011",
                 sep = "")
   sdmx <- readSDMX(url)
   stats <- as.data.frame(sdmx)
   head(stats)

   ## End(**Not run**)

 # SDMX Concepts / ConceptSchemes
 #-------------------------------
 # Not run by 'R CMD check'
   # (reliable remote datasource but with possible occasional unavailability)
   csUrl <- paste("http://data.fao.org/sdmx/registry/conceptscheme",
                  "/FAO/ALL/LATEST/?detail=full&references=none&version=2.1",
                  sep = "")
   csobj <- readSDMX(csUrl)
   csdf <- as.data.frame(csobj)
   head(csdf)
   ## End(**Not run**)

 # SDMX Codelists
 #---------------
 # Not run by 'R CMD check'
   # (reliable remote datasource but with possible occasional unavailability)
   clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1"
   clobj <- readSDMX(clUrl)
   cldf <- as.data.frame(clobj)
   head(cldf)
   ## End(**Not run**)

 # SDMX DataStructureDefinition (DSD)
 #-----------------------------------
 # Not run by 'R CMD check'
   # (reliable remote datasource but with possible occasional unavailability)

   #using embedded providers
   dsd <- readSDMX(agencyId = "OECD", resource = "datastructure",
                   resourceId = "WATER_ABSTRACT")

   #get codelists from DSD
   cls <- slot(dsd, "codelists")
   codelists <- sapply(slot(cls,"codelists"), slot, "id") #get list of codelists

   #get a codelist
   codelist <- as.data.frame(cls, codelistId = "CL_WATER_ABSTRACT_SOURCE")

   #get concepts from DSD
   concepts <- as.data.frame(slot(dsd, "concepts"))

   ## End(**Not run**)

Run the code above in your browser using DataLab