rsdmx/0000755000176200001440000000000012654245164011420 5ustar liggesusersrsdmx/inst/0000755000176200001440000000000012654151640012370 5ustar liggesusersrsdmx/inst/doc/0000755000176200001440000000000012654151640013135 5ustar liggesusersrsdmx/inst/doc/quickstart.Rmd0000644000176200001440000001703412654151640016000 0ustar liggesusers # rsdmx quickstart guide The goal of this document is to get you up and running with rsdmx as quickly as possible. ``rsdmx`` provides a set of classes and methods to read data and metadata documents exchanged through the Statistical Data and Metadata Exchange (SDMX) framework. ## SDMX - a short introduction The SDMX framework provides two sets of standard specifications to facilitate the exchange of statistical data: * standard formats * web-service specifications SDMX allows to disseminate both **data** (a dataset) and **metadata** (the description of the dataset). For this, the SDMX standard provides various types of _documents_, also known as _messages_. Hence there will be: * **data** SDMX-ML _documents_. The two main _document_ types are the ``Generic`` and ``Compact`` ones. The latter aims to provide a more compact XML document. They are other data _document_ types derivating from the ones previously mentioned. * **metadata** SDMX-ML _documents_. The main metadata _document_ is known a ``Data Structure Definition`` (DSD). As its name indicates, it _describes_ the structure and organization of a dataset, and will generally include all the master/reference data used to characterize a dataset. The 2 main types of metadata are (1) the ``concepts``, which correspond to the _dimensions_ and/or _attributes_ of the dataset, and (2) the ``codelists`` which inventory the possible values to be used in the representation of _dimensions_ and _attributes_. For more information about the SDMX standards, you can visit the [SDMX website](http://sdmx.org/), or this [introduction by EUROSTAT](https://webgate.ec.europa.eu/fpfis/mwikis/sdmx/index.php/SDMX). ## How to deal with SDMX in R [rsdmx](http://cran.r-project.org/package=rsdmx) offers a low-level set of tools to read **data** and **metadata** in the SDMX-ML format. Its strategy is to make it very easy for the user. For this, a unique function named ``readSDMX`` has to be used, whatever it is a ``data`` or ``metadata`` document, or if it is ``local`` or ``remote`` datasource. What ``rsdmx`` does support: * a SDMX format abstraction library, with focus on the the main SDMX standard XML format (SDMX-ML), and the support of the three format standard versions (``1.0``, ``2.0``, ``2.1``) * an interface to SDMX web-services for a list of well-known data providers, such as OECD, EUROSTAT, ECB, UN FAO, UN ILO, etc (a list that should grow in a near future!). See it [in action](https://github.com/opensdmx/rsdmx/blob/master/vignettes/quickstart.Rmd#using-the-helper-approach)! Let's see then how to use ``rsdmx``! ## Install rsdmx ``rsdmx`` can be installed from CRAN or from its development repository hosted in Github. For the latter, you will need the ``devtools`` package and run: ```{r, eval=FALSE} devtools::install_github("opensdmx/rsdmx") ``` ## Load rsdmx To load rsdmx in R, do the following: ```{r} library(rsdmx) ``` ## Read dataset documents This section will introduce you on how to read SDMX *dataset* documents, either from _remote_ datasources, or from _local_ SDMX files. ### Read _remote_ datasets #### using the _raw_ approach (specifying the complete request URL) The following code snipet shows you how to read a dataset from a remote data source, taking as example the [OECD StatExtracts portal](http://stats.oecd.org): [http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011](http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011) ```{r} myUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011" dataset <- readSDMX(myUrl) stats <- as.data.frame(dataset) ``` You can try it out with other datasources, such as from the [**EUROSTAT portal**](http://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1): [http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011](http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011) The online rsdmx documentation also provides a list of data providers, either from international or national institutions, and [more request examples](https://github.com/opensdmx/rsdmx/wiki#read-remote-datasets). #### using the _helper_ approach Now, the service providers above mentioned are known by ``rsdmx`` which let users using ``readSDMX`` with the helper parameters. The list of service providers can be retrieved doing: ```{r} providers <- getSDMXServiceProviders(); as.data.frame(providers) ``` Note it is also possible to add an SDMX service provider at runtime. For registering a new SDMX service provider by default, please contact me! Let's see how it would look like for querying an ``OECD`` datasource: ```{r, message = FALSE} sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG", key = list("TOT", NULL, NULL), start = 2010, end = 2011) df <- as.data.frame(sdmx) head(df) ``` ### Read _local_ datasets This example shows you how to use ``rsdmx`` with _local_ SDMX files, previously downloaded from [EUROSTAT](http://ec.europa.eu/eurostat). ```{r} #bulk download from Eurostat tf <- tempfile(tmpdir = tdir <- tempdir()) #temp file and folder download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf) sdmx_files <- unzip(tf, exdir = tdir) #read local SDMX (set isURL = FALSE) sdmx <- readSDMX(sdmx_files[2], isURL = FALSE) stats <- as.data.frame(sdmx) ``` By default, ``readSDMX`` considers the data source is remote. To read a local file, add ``isURL = FALSE``. ## Read metadata documents This section will introduce you on how to read SDMX **metadata** documents, including ``concepts``, ``codelists`` and a complete ``data structure definition`` (DSD) ### Concepts Read concept schemes from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r, warning=FALSE} csUrl <- "http://data.fao.org/sdmx/registry/conceptscheme/FAO/ALL/LATEST/?detail=full&references=none&version=2.1" csobj <- readSDMX(csUrl) csdf <- as.data.frame(csobj) ``` ### Codelists Read codelists from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r} clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1" clobj <- readSDMX(clUrl) cldf <- as.data.frame(clobj) ``` ###Data Structure Definition (DSD) This example illustrates how to read a complete DSD using a [OECD StatExtracts portal](http://stats.oecd.org) data source. ```{r} dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1" dsd <- readSDMX(dsdUrl) ``` ``rsdmx`` is implemented in object-oriented way with ``S4`` classes and methods. The properties of ``S4`` objects are named ``slots`` and can be accessed with the ``slot`` method. The following code snippet allows to extract the list of ``codelists`` contained in the DSD document, and read one codelist as ``data.frame``. ```{r} #get codelists from DSD cls <- slot(dsd, "codelists") #get list of codelists codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id")) #get a codelist codelist <- as.data.frame(slot(dsd, "codelists"), codelistId = "CL_TABLE1_FLOWS") ``` In a similar way, the ``concepts`` of the dataset can be extracted from the DSD and read as ``data.frame``. ```{r} #get concepts from DSD concepts <- as.data.frame(slot(dsd, "concepts")) ``` rsdmx/inst/doc/quickstart.R0000644000176200001440000000466412654151640015464 0ustar liggesusers## ---- eval=FALSE--------------------------------------------------------- # devtools::install_github("opensdmx/rsdmx") ## ------------------------------------------------------------------------ library(rsdmx) ## ------------------------------------------------------------------------ myUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011" dataset <- readSDMX(myUrl) stats <- as.data.frame(dataset) ## ------------------------------------------------------------------------ providers <- getSDMXServiceProviders(); as.data.frame(providers) ## ---- message = FALSE---------------------------------------------------- sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG", key = list("TOT", NULL, NULL), start = 2010, end = 2011) df <- as.data.frame(sdmx) head(df) ## ------------------------------------------------------------------------ #bulk download from Eurostat tf <- tempfile(tmpdir = tdir <- tempdir()) #temp file and folder download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf) sdmx_files <- unzip(tf, exdir = tdir) #read local SDMX (set isURL = FALSE) sdmx <- readSDMX(sdmx_files[2], isURL = FALSE) stats <- as.data.frame(sdmx) ## ---- warning=FALSE------------------------------------------------------ csUrl <- "http://data.fao.org/sdmx/registry/conceptscheme/FAO/ALL/LATEST/?detail=full&references=none&version=2.1" csobj <- readSDMX(csUrl) csdf <- as.data.frame(csobj) ## ------------------------------------------------------------------------ clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1" clobj <- readSDMX(clUrl) cldf <- as.data.frame(clobj) ## ------------------------------------------------------------------------ dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1" dsd <- readSDMX(dsdUrl) ## ------------------------------------------------------------------------ #get codelists from DSD cls <- slot(dsd, "codelists") #get list of codelists codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id")) #get a codelist codelist <- as.data.frame(slot(dsd, "codelists"), codelistId = "CL_TABLE1_FLOWS") ## ------------------------------------------------------------------------ #get concepts from DSD concepts <- as.data.frame(slot(dsd, "concepts")) rsdmx/inst/doc/quickstart.html0000644000176200001440000005737512654151640016236 0ustar liggesusers rsdmx quickstart guide

rsdmx quickstart guide

The goal of this document is to get you up and running with rsdmx as quickly as possible.

rsdmx provides a set of classes and methods to read data and metadata documents exchanged through the Statistical Data and Metadata Exchange (SDMX) framework.

SDMX - a short introduction

The SDMX framework provides two sets of standard specifications to facilitate the exchange of statistical data:

SDMX allows to disseminate both data (a dataset) and metadata (the description of the dataset).

For this, the SDMX standard provides various types of documents, also known as messages. Hence there will be:

For more information about the SDMX standards, you can visit the SDMX website, or this introduction by EUROSTAT.

How to deal with SDMX in R

rsdmx offers a low-level set of tools to read data and metadata in the SDMX-ML format. Its strategy is to make it very easy for the user. For this, a unique function named readSDMX has to be used, whatever it is a data or metadata document, or if it is local or remote datasource.

What rsdmx does support:

Let's see then how to use rsdmx!

Install rsdmx

rsdmx can be installed from CRAN or from its development repository hosted in Github. For the latter, you will need the devtools package and run:

devtools::install_github("opensdmx/rsdmx")

Load rsdmx

To load rsdmx in R, do the following:

library(rsdmx)

Read dataset documents

This section will introduce you on how to read SDMX dataset documents, either from remote datasources, or from local SDMX files.

Read remote datasets

using the raw approach (specifying the complete request URL)

The following code snipet shows you how to read a dataset from a remote data source, taking as example the OECD StatExtracts portal: http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011

myUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011"
dataset <- readSDMX(myUrl)
stats <- as.data.frame(dataset)

You can try it out with other datasources, such as from the EUROSTAT portal: http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011

The online rsdmx documentation also provides a list of data providers, either from international or national institutions, and more request examples.

using the helper approach

Now, the service providers above mentioned are known by rsdmx which let users using readSDMX with the helper parameters. The list of service providers can be retrieved doing:

providers <- getSDMXServiceProviders();
as.data.frame(providers)
##   agencyId                                                          name
## 1      ECB                                         European Central Bank
## 2    ESTAT           Eurostat (Statistical office of the European Union)
## 3     OECD        Organisation for Economic Cooperation and Development 
## 4      FAO       Food and Agriculture Organization of the United Nations
## 5      ILO       International Labour Organization of the United Nations
## 6      UIS                                UNESCO Institute of Statistics
## 7      ABS                               Australian Bureau of Statistics
## 8      NBB                                      National Bank of Belgium
## 9    INSEE Institut national de la statistique et des études économiques
##           scale country
## 1 international    <NA>
## 2 international    <NA>
## 3 international    <NA>
## 4 international    <NA>
## 5 international    <NA>
## 6 international    <NA>
## 7      national     AUS
## 8      national     BEL
## 9      national     FRA

Note it is also possible to add an SDMX service provider at runtime. For registering a new SDMX service provider by default, please contact me!

Let's see how it would look like for querying an OECD datasource:

sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG",
                key = list("TOT", NULL, NULL), start = 2010, end = 2011)
df <- as.data.frame(sdmx)
head(df)
##   CO2 VAR GEN COU attrs.df obsTime obsValue OBS_STATUS
## 1 TOT B11 WMN AUS      P1Y    2010   107740       <NA>
## 2 TOT B11 WMN AUS      P1Y    2011   108865       <NA>
## 3 TOT B11 TOT AUS      P1Y    2010   206714       <NA>
## 4 TOT B11 TOT AUS      P1Y    2011   210704       <NA>
## 5 TOT B12 TOT AUS      P1Y    2010    29307       <NA>
## 6 TOT B12 TOT AUS      P1Y    2011    31204       <NA>

Read local datasets

This example shows you how to use rsdmx with local SDMX files, previously downloaded from EUROSTAT.

#bulk download from Eurostat
tf <- tempfile(tmpdir = tdir <- tempdir()) #temp file and folder
download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf)
sdmx_files <- unzip(tf, exdir = tdir)

#read local SDMX (set isURL = FALSE)
sdmx <- readSDMX(sdmx_files[2], isURL = FALSE)
stats <- as.data.frame(sdmx)

By default, readSDMX considers the data source is remote. To read a local file, add isURL = FALSE.

Read metadata documents

This section will introduce you on how to read SDMX metadata documents, including concepts, codelists and a complete data structure definition (DSD)

Concepts

Read concept schemes from FAO data portal

csUrl <- "http://data.fao.org/sdmx/registry/conceptscheme/FAO/ALL/LATEST/?detail=full&references=none&version=2.1"
csobj <- readSDMX(csUrl)
csdf <- as.data.frame(csobj)

Codelists

Read codelists from FAO data portal

clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1"
clobj <- readSDMX(clUrl)
cldf <- as.data.frame(clobj)

###Data Structure Definition (DSD)

This example illustrates how to read a complete DSD using a OECD StatExtracts portal data source.

dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1"
dsd <- readSDMX(dsdUrl)

rsdmx is implemented in object-oriented way with S4 classes and methods. The properties of S4 objects are named slots and can be accessed with the slot method. The following code snippet allows to extract the list of codelists contained in the DSD document, and read one codelist as data.frame.

#get codelists from DSD
cls <- slot(dsd, "codelists")

#get list of codelists
codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id"))

#get a codelist
codelist <- as.data.frame(slot(dsd, "codelists"), codelistId = "CL_TABLE1_FLOWS") 

In a similar way, the concepts of the dataset can be extracted from the DSD and read as data.frame.

#get concepts from DSD
concepts <- as.data.frame(slot(dsd, "concepts"))
rsdmx/tests/0000755000176200001440000000000012654150565012562 5ustar liggesusersrsdmx/tests/testthat/0000755000176200001440000000000012654150565014422 5ustar liggesusersrsdmx/tests/testthat/test_MessageGroup.R0000644000176200001440000000163012654150565020205 0ustar liggesusers# test_MessageGroup.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX MessageGroup methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXMessageGroup") test_that("MessageGroup - GenericData 2.0",{ file <- system.file("extdata", "SDMXMessageGroupExample_GenericData_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXMessageGroup(xmlObj) expect_is(ds, "SDMXMessageGroup") df <- as.data.frame(ds) expect_is(df, "data.frame") }) test_that("MessageGroup - CompactData 2.0",{ file <- system.file("extdata", "SDMXMessageGroupExample_CompactData_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXMessageGroup(xmlObj) expect_is(ds, "SDMXMessageGroup") df <- as.data.frame(ds) expect_is(df, "data.frame") }) rsdmx/tests/testthat/test_Header.R0000644000176200001440000000321712654150565016777 0ustar liggesusers# test_Header.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Header methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXHeader") test_that("SDMXHeader - 2.0",{ file <- system.file("extdata", "SDMXMessageExample_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) obj = SDMXHeader(xmlObj) expect_is(obj, "SDMXHeader") expect_equal(obj@ID, "data.organization.org") expect_false(obj@Test) expect_false(obj@Truncated) expect_equal(obj@Name, "thename") expect_equal(obj@Prepared, as.POSIXlt(strptime("2014-03-02T16:29:26", format = "%Y-%m-%dT%H:%M:%S"))) expect_is(obj@Sender, "list") expect_equal(obj@Sender$id, "ORGANIZATION") expect_equal(obj@Sender$name$en, "Organization") expect_equal(obj@Sender$name$fr, "Organisation") expect_equal(obj@Receiver$id, NA) expect_equal(obj@ReportingBegin, as.POSIXlt(strptime(ISOdate(2000,1,1), format = "%Y-%m-%d"))) expect_equal(obj@ReportingEnd, as.POSIXlt(strptime(ISOdate(2008,12,31), format = "%Y-%m-%d"))) }) test_that("SDMXHeader - 2.1",{ file <- system.file("extdata", "SDMXMessageExample_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) obj = SDMXHeader(xmlObj) expect_is(obj, "SDMXHeader") expect_equal(obj@ID, "176ea8e40bfc189c8113edf292a3abb4") expect_false(obj@Test) expect_equal(obj@Prepared, as.POSIXlt(strptime("2014-07-18T07:04:39", format = "%Y-%m-%dT%H:%M:%S"))) expect_is(obj@Sender, "list") expect_equal(obj@Sender$id, "ESTAT") expect_equal(obj@Sender$name$en, "Eurostat") expect_equal(obj@Receiver$id, "RECEIVER") }) rsdmx/tests/testthat/test_Soap.R0000644000176200001440000000111312654150565016502 0ustar liggesusers# test_SOAP.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX SOAP responses #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXSoapResponse") test_that("SOAP - CompactData",{ file <- system.file("extdata", "SDMX_SOAP_Example.xml", package = "rsdmx") xmlObj <- xmlParse(file) expect_true(isSoapRequestEnvelope(xmlObj)) xmlObj <- getSoapRequestResult(xmlObj) expect_false(isSoapRequestEnvelope(xmlObj)) ds <- SDMXCompactData(xmlObj) expect_is(ds, "SDMXCompactData") })rsdmx/tests/testthat/test_Type.R0000644000176200001440000000211412654150565016523 0ustar liggesusers# test_Type.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Type #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXType") #read test data file1 <- system.file("extdata", "SDMXMessageExample_2.0.xml", package = "rsdmx") file2 <- system.file("extdata", "SDMXMessageExample_2.1.xml", package = "rsdmx") xmlObj1 <- xmlParse(file1) xmlObj2 <- xmlParse(file2) test_that("type.SDMXType - 2.0",{ type1 <- type.SDMXType(xmlObj1) expect_equal(type1, "GenericDataType") }) test_that("type.SDMXType - 2.1",{ type2 <- type.SDMXType(xmlObj2) expect_equal(type2, "GenericDataType") }) test_that("SDMXType - 2.0",{ obj1 <- SDMXType(xmlObj1) expect_is(obj1, "SDMXType") }) test_that("SDMXType - 2.1",{ obj2 <- SDMXType(xmlObj2) expect_is(obj2, "SDMXType") }) test_that("getType - 2.0",{ obj1 <- SDMXType(xmlObj1) expect_equal(obj1@type, "GenericDataType") }) test_that("getType - 2.1",{ obj2 <- SDMXType(xmlObj2) expect_equal(obj2@type, "GenericDataType") }) rsdmx/tests/testthat/test_DataStructures.R0000644000176200001440000000413212654150565020561 0ustar liggesusers# test_DataStructures.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX DataStructures methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXDataStructures") test_that("DataStructures / KeyFamilies - 2.0",{ file <- system.file("extdata", "SDMXDataStructures_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXDataStructures(xmlObj) expect_is(ds, "SDMXDataStructures") expect_equal(length(ds@datastructures), 1L) ds.df <- as.data.frame(ds) expect_is(ds.df, "data.frame") expect_equal(nrow(ds.df), 1L) expect_equal(colnames(ds.df), c("id","agencyID","Name.en", "version", "uri", "urn", "isExternalReference", "isFinal", "validFrom", "validTo")) expect_equal(ds.df[1,"id"], "TRADE_DATASTRUCTURE") expect_equal(ds.df[1, "agencyID"], "FAO") expect_equal(ds.df[1, "Name.en"], "TRADE_DATASTRUCTURE") expect_equal(ds.df[1, "version"], "0.1") expect_equal(ds.df[1, "urn"], "urn:sdmx:org.sdmx.infomodel.DataStructure=FAO:TRADE_DATASTRUCTURE[0.1]") }) test_that("DataStructures / KeyFamilies - 2.1",{ file <- system.file("extdata", "SDMXDataStructures_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXDataStructures(xmlObj) expect_is(ds, "SDMXDataStructures") expect_equal(length(ds@datastructures), 1L) ds.df <- as.data.frame(ds) expect_is(ds.df, "data.frame") expect_equal(nrow(ds.df), 1L) expect_equal(colnames(ds.df), c("id","agencyID","Name.en", "version", "uri", "urn", "isExternalReference", "isFinal", "validFrom", "validTo")) expect_equal(ds.df[1,"id"], "ECB_EXR1") expect_equal(ds.df[1, "agencyID"], "ECB") expect_equal(ds.df[1, "Name.en"], "Exchange Rates") expect_equal(ds.df[1, "version"], "1.0") expect_equal(ds.df[1, "urn"], "urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=ECB:ECB_EXR1(1.0)") }) rsdmx/tests/testthat/test_DataStructureDefinition.R0000644000176200001440000000224012654150565022405 0ustar liggesusers# test_DataStructureDefinition.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX DataStructureDefinition (DSD) methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXDataStructureDefinition") test_that("DataStructureDefinition (DSD) - 2.0",{ file <- system.file("extdata", "SDMXDataStructureDefinition_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) dsd <- SDMXDataStructureDefinition(xmlObj) expect_is(dsd, "SDMXDataStructureDefinition") expect_is(dsd@concepts, "SDMXConcepts") expect_is(dsd@codelists, "SDMXCodelists") expect_is(dsd@datastructures, "SDMXDataStructures") }) test_that("DataStructureDefinition (DSD) - 2.1",{ file <- system.file("extdata", "SDMXDataStructureDefinition_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) dsd <- SDMXDataStructureDefinition(xmlObj) expect_is(dsd, "SDMXDataStructureDefinition") expect_is(dsd@concepts, "SDMXConcepts") expect_is(dsd@codelists, "SDMXCodelists") expect_is(dsd@datastructures, "SDMXDataStructures") }) rsdmx/tests/testthat/test_Namespaces.R0000644000176200001440000000200112654150565017654 0ustar liggesusers# test_Namespaces.R # Author: Emmanuel Blondel # # Description: Unit tests for Namespace functions #======================= require(rsdmx, quietly = TRUE) require(testthat) context("Namespaces") test_that("getNamespaces",{ file <- system.file("extdata", "SDMXGenericDataExample_2.0.xml", package = "rsdmx") sdmx <- readSDMX(file, isURL = FALSE) namespaces <- getNamespaces(sdmx) expect_is(namespaces, "data.frame") expect_equal(c("id","uri"), colnames(namespaces)) expect_equal(12L, nrow(namespaces)) }) test_that("findNamespace",{ file <- system.file("extdata", "SDMXGenericDataExample_2.0.xml", package = "rsdmx") sdmx <- readSDMX(file, isURL = FALSE) namespaces <- getNamespaces(sdmx) namespace <- findNamespace(namespaces, "generic") expect_is(namespace, "character") expect_equal(1L, length(namespace)) expect_equal("http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic", as.character(namespace)) }) rsdmx/tests/testthat/test_DataFlows.R0000644000176200001440000000234612654150565017475 0ustar liggesusers# test_DataFlows.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX DataFlows methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXDataFlows") test_that("DataFlows - 2.1",{ file <- system.file("extdata", "SDMXDataFlows_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) flow <- SDMXDataFlows(xmlObj) expect_is(flow, "SDMXDataFlows") expect_equal(length(flow@dataflows), 5L) flow.df <- as.data.frame(flow) expect_is(flow.df, "data.frame") expect_equal(nrow(flow.df), 5L) expect_equal(colnames(flow.df), c("id","agencyID", "Name.fr", "Name.en", "Name.es", "version", "uri", "urn", "isExternalReference", "isFinal", "validFrom", "validTo", "dsdRef")) expect_equal(flow.df[1,"id"], "DS-001") expect_equal(flow.df[1, "agencyID"], "MYORG") expect_equal(flow.df[1, "Name.en"], "Dataset 1") expect_equal(flow.df[1, "version"], "1.0") expect_equal(flow.df[1, "urn"], "urn:sdmx:org.sdmx.infomodel.datastructure.Dataflow=MYORG:DS-001(1.0)") expect_equal(flow.df[1, "dsdRef"], "DSD_DS-001") }) rsdmx/tests/testthat/test_CompactData.R0000644000176200001440000000133712654150565017770 0ustar liggesusers# test_CompactData.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX CompactData methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXCompactData") test_that("CompactData 2.0",{ file <- system.file("extdata", "SDMXCompactDataExample_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXCompactData(xmlObj) expect_is(ds, "SDMXCompactData") df <- as.data.frame(ds) expect_is(df, "data.frame") #test absence data expect_true(is.na(df[nrow(df),]$YEA)) expect_true(is.na(df[nrow(df),]$OBS_VALUE)) expect_true(is.na(df[nrow(df)-1,]$YEA)) expect_true(is.na(df[nrow(df)-1,]$OBS_VALUE)) })rsdmx/tests/testthat/test_Footer.R0000644000176200001440000000273412654150565017050 0ustar liggesusers# test_Footer.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Footer methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXFooter") test_that("SDMXFooter - 2.0",{ file <- system.file("extdata", "SDMXMessageExample_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) obj = SDMXFooter(xmlObj) expect_is(obj, "SDMXFooter") expect_equal(length(obj@messages),0) }) test_that("SDMXFooter - 2.1",{ file <- system.file("extdata", "SDMXMessageExample_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) obj = SDMXFooter(xmlObj) expect_is(obj, "SDMXFooter") obj.messages = obj@messages expect_equal(length(obj@messages),2) obj1 = obj.messages[[1]] expect_is(obj1, "SDMXFooterMessage") expect_equal(obj1@code, "413") expect_equal(obj1@severity, "Information") obj1.messages = obj1@messages expect_equal(length(obj1.messages),3) expect_equal(obj1.messages[[1]], "info message 1") expect_equal(obj1.messages[[2]], "info message 2") expect_equal(obj1.messages[[3]], "info message 3") obj2 = obj.messages[[2]] expect_is(obj2, "SDMXFooterMessage") expect_equal(obj2@code, "413") expect_equal(obj2@severity, "Warning") obj2.messages = obj2@messages expect_equal(length(obj2.messages),2) expect_equal(obj2.messages[[1]], "warning message 1") expect_equal(obj2.messages[[2]], "warning message 2") })rsdmx/tests/testthat/test_Main_Helpers.R0000644000176200001440000001635112654150565020160 0ustar liggesusers# test_Main_Helpers.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Main methods # using helpers to build the SDMX request #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXHelpers") #international data providers #ECB #--- #-> dataflow test_that("ECB - dataflow",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ECB", resource = "dataflow") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataFlows") } }) #-> datastructure test_that("ECB - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ECB", resource = "datastructure", resourceId = "ECB_DD1") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("ECB - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ECB", resource = "data", flowRef = "DD", key = "M.SE.BSI_STF.RO.4F_N", key.mode = "SDMX", start = 2010, end = 2010) if(!is.null(sdmx)){ expect_is(sdmx, "SDMXGenericData") } }) #ESTAT (EUROSTAT) #--------------- #-> dataflow test_that("ESTAT - dataflow",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ESTAT", resource = "dataflow") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataFlows") } }) #-> datastructure test_that("ESTAT - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ESTAT", resource = "datastructure", resourceId = "DSD_nama_gdp_c") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("ESTAT - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ESTAT", resource = "data", flowRef = "cdh_e_fos", key = list(NULL, NULL, "PC", "FOS1", "BE"), start = 2005, end = 2010) if(!is.null(sdmx)){ expect_is(sdmx, "SDMXGenericData") } }) #OECD #---- #-> dataflow test_that("OECD - dataflow",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "OECD", resource = "dataflow") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataFlows") } }) #-> datastructure test_that("OECD - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "OECD", resource = "datastructure", resourceId = "TABLE1") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("OECD - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG", key = list("TOT", NULL, NULL), start = 2011, end = 2011) if(!is.null(sdmx)){ expect_is(sdmx, "SDMXMessageGroup") } }) #FAO (UN-FAO) #------------ #-> datastructure test_that("FAO - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "FAO", resource = "datastructure", resourceId = "FAOSTAT") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("FAO - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "FAO", resource = "data", flowRef = "CROP_PRODUCTION", key = list(NULL, "156", "5312", NULL, NULL), start = "2010", end = "2014") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXGenericData") } }) #ILO (UN-ILO) #------------ #-> datastructure test_that("ILO - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ILO", resource = "datastructure", resourceId = "YI_ALB_EAP_TEAP_SEX_AGE_NB") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("ILO - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ILO", resource = "data", flowRef = "DF_CPI_FRA_CPI_TCPI_COI_RT", key = "ALL", key.mode = "SDMX", start = "2010-01-01", end = "2014-12-31") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXGenericData") } }) #UIS (UNESCO) #------------ #-> datastructure test_that("UIS - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "UIS", resource = "datastructure", resourceId = "all") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("UIS - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "UIS", resource = "data", flowRef = "EDULIT_DS", key = list("OFST_1_CP", NULL), start = "2000", end = "2015") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXGenericData") } }) #national data providers #ABS (Australia) #------------- #-> datastructure test_that("ABS - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ABS", resource = "datastructure", resourceId = "ALC") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("ABS - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "ABS", resource = "data", flowRef = "ALC", key = "1.1+2.1+2+3+5+4.6+10+11+12+15+14.A", key.mode = "SDMX", start = "2000", end = "2015") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXMessageGroup") } }) #NBB (Belgium) #------------- #-> datastructure test_that("NBB - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "NBB", resource = "datastructure", resourceId = "QNA") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("NBB - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "NBB", resource = "data", flowRef = "QNA", key = "all", key.mode = "SDMX", start = "2000", end = "2015") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXMessageGroup") } }) #INSEE (France) #------------- #-> dataflow test_that("INSEE - dataflow",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "INSEE", resource = "dataflow") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataFlows") } }) #-> datastructure test_that("INSEE - datastructure",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "INSEE", resource = "datastructure", resourceId = "IPI-2010-A21") if(!is.null(sdmx)){ expect_is(sdmx, "SDMXDataStructureDefinition") } }) #-> data test_that("INSEE - data",{ testthat::skip_on_travis() testthat::skip_on_cran() sdmx <- readSDMX(agencyId = "INSEE", resource = "data", flowRef = "IPI-2010-A21", key = "all", key.mode = "SDMX", start = 2010, end = 2015) if(!is.null(sdmx)){ expect_is(sdmx, "SDMXStructureSpecificData") } }) rsdmx/tests/testthat/test_GenericData.R0000644000176200001440000000525112654150565017755 0ustar liggesusers# test_GenericData.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX GenericData methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXGenericData") test_that("GenericData 2.0",{ file <- system.file("extdata", "SDMXGenericDataExample_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXGenericData(xmlObj) expect_is(ds, "SDMXGenericData") df <- as.data.frame(ds) expect_is(df, "data.frame") expect_equal(c(paste(rep("C",5),1:5,sep=""), "UNITS", "UNIT_MULTIPLIER", "obsTime", "obsValue"), names(df)) #test absence data expect_true(is.na(df[nrow(df),]$obsValue)) expect_true(is.na(df[nrow(df),]$obsTime)) }) test_that("GenericData - 2.0 - Eurostat",{ file <- system.file("extdata", "Example_Eurostat_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXGenericData(xmlObj) expect_is(ds, "SDMXGenericData") df <- as.data.frame(ds) expect_is(df, "data.frame") # test df content expect_equal(df, structure(list(UNIT = c("PC", "PC"), REASON = c("ECO", "ECO"), ENTERPR = c("OTH", "YHE"), NACE_R2 = c("B-E", "M"), GEO = c("PL", "PL"), FREQ = c("A", "A"), obsTime = rep("2009",2), obsValue = c(16.8, 18)), .Names = c("UNIT", "REASON", "ENTERPR", "NACE_R2", "GEO", "FREQ", "obsTime", "obsValue"), class = "data.frame", row.names = 1:2)) }) test_that("GenericData - 2.1",{ file <- system.file("extdata", "SDMXGenericDataExample_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXGenericData(xmlObj) expect_is(ds, "SDMXGenericData") df <- as.data.frame(ds) expect_is(df, "data.frame") # test df content expect_true(all(df == structure(list(UNIT = rep("PC",4), Y_GRAD = c(rep("TOTAL",2),rep("Y_GE1990",2)), FOS07 = rep("FOS1",4), GEO = rep("BE",4), FREQ = rep("A",4), obsTime = rep(c("2009","2006"),2), obsValue = c(NA, NA,43.75,NA), OBS_STATUS = rep("na",4)), .Names = c("UNIT", "Y_GRAD","FOS07", "GE0", "FREQ", "obsTime", "obsValue"), class = "data.frame", row.names = 1:4), na.rm = TRUE)) }) rsdmx/tests/testthat/test_ServiceProvider.R0000644000176200001440000000501212654150565020715 0ustar liggesusers# test_ServiceProvider.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Service Provider #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXServiceProvider") test_that("SDMXServiceProvider - constructor",{ requestBuilder <- SDMXRequestBuilder( regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", handler = function(baseUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant){ return(paste(baseUrl, agencyId, resource, flowRef, key, start, end, sep="/")) }, compliant = TRUE) provider <- SDMXServiceProvider( agencyId = "MYORG", name = "My Organization", builder = requestBuilder ) expect_is(provider, "SDMXServiceProvider") expect_equal(provider@agencyId, "MYORG") expect_equal(provider@name, "My Organization") expect_equal(provider@scale, "international") expect_true(is.na(provider@country)) expect_is(provider@builder, "SDMXRequestBuilder") }) test_that("SDMXServiceProvider - methods",{ providers <- getSDMXServiceProviders() expect_is(providers, "SDMXServiceProviders") expect_equal(length(providers@providers), 9L) expect_equal(sapply(providers@providers, function(x){slot(x,"agencyId")}), c("ECB", "ESTAT", "OECD", "FAO", "ILO", "UIS", "ABS", "NBB", "INSEE")) expect_is(as.data.frame(providers), "data.frame") #add a provider requestBuilder <- SDMXRequestBuilder( regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", handler = function(baseUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant){ return(paste(baseUrl, agencyId, resource, flowRef, key, start, end, sep="/")) }, compliant = TRUE) provider <- SDMXServiceProvider( agencyId = "MYORG", name = "My Organization", builder = requestBuilder ) addSDMXServiceProvider(provider) providers <- getSDMXServiceProviders() expect_equal(length(providers@providers), 10L) expect_equal(sapply(providers@providers, function(x){slot(x,"agencyId")}), c("ECB", "ESTAT", "OECD", "FAO", "ILO", "UIS", "ABS", "NBB", "INSEE", "MYORG")) #find a provider oecd <- findSDMXServiceProvider("OECD") expect_is(oecd, "SDMXServiceProvider") expect_equal(oecd@agencyId, "OECD") }) rsdmx/tests/testthat/test_Codelists.R0000644000176200001440000000165012654150565017537 0ustar liggesusers# test_Codelists.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Codelists methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXCodelists") test_that("Codelists - 2.0",{ file <- system.file("extdata", "SDMXCodelists_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) codelists <- SDMXCodelists(xmlObj) expect_is(codelists, "SDMXCodelists") expect_equal(length(codelists@codelists), 1L) df <- as.data.frame(codelists) expect_is(df, "data.frame") }) test_that("Codelists - 2.1",{ file <- system.file("extdata", "SDMXCodelists_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) codelists <- SDMXCodelists(xmlObj) expect_is(codelists, "SDMXCodelists") expect_equal(length(codelists@codelists), 1L) df <- as.data.frame(codelists) expect_is(df, "data.frame") })rsdmx/tests/testthat/test_Main.R0000644000176200001440000000470412654150565016475 0ustar liggesusers# test_Main.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Main methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMX") #SDMX datasets #------------ file <- system.file("extdata", "SDMXGenericDataExample_2.0.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) test_that("readSDMX - 2.0",{ expect_is(sdmxObj, "SDMXGenericData") }) #tests for 2.1 file2 <- system.file("extdata", "SDMXGenericDataExample_2.1.xml", package = "rsdmx") sdmxObj2 <- readSDMX(file2, isURL = FALSE) test_that("readSDMX - 2.1",{ expect_is(sdmxObj2, "SDMXGenericData") }) #SDMXConcepts #----------- test_that("readSDMX - SDMXConcepts - 2.0",{ file <- system.file("extdata", "SDMXConcepts_Example_2.0.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) expect_is(sdmxObj, "SDMXConcepts") }) test_that("readSDMX - SDMXConcepts (conceptScheme) - 2.0",{ file <- system.file("extdata", "SDMXConceptSchemes_Example_2.0.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) expect_is(sdmxObj, "SDMXConcepts") }) test_that("readSDMX - SDMXConcepts (conceptScheme) - 2.1",{ file <- system.file("extdata", "SDMXConceptSchemes_Example_2.1.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) expect_is(sdmxObj, "SDMXConcepts") }) #SDMXCodelists #------------- test_that("readSDMX - SDMXCodelists - 2.0",{ file <- system.file("extdata", "SDMXCodelists_Example_2.0.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) expect_is(sdmxObj, "SDMXCodelists") }) test_that("readSDMX - SDMXCodelists - 2.0",{ file <- system.file("extdata", "SDMXCodelists_Example_2.1.xml", package = "rsdmx") sdmxObj <- readSDMX(file, isURL = FALSE) expect_is(sdmxObj, "SDMXCodelists") }) #SDMXDataStructureDefinition (DSD) #-------------------------------- test_that("readSDMX - SDMXDataStructureDefinition (DSD) - 2.0",{ file <- system.file("extdata", "SDMXDataStructureDefinition_Example_2.0.xml", package = "rsdmx") dsd <- readSDMX(file, isURL = FALSE) expect_is(dsd, "SDMXDataStructureDefinition") expect_is(dsd@concepts, "SDMXConcepts") expect_is(dsd@codelists, "SDMXCodelists") expect_is(dsd@datastructures, "SDMXDataStructures") }) rsdmx/tests/testthat/test_Concepts.R0000644000176200001440000000275112654150565017367 0ustar liggesusers# test_Concepts.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Concepts methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXConcepts") test_that("Concepts 2.0 - with Concepts (backward compatibility with 1.0)",{ file <- system.file("extdata", "SDMXConcepts_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) concepts <- SDMXConcepts(xmlObj) expect_is(concepts, "SDMXConcepts") df <- as.data.frame(concepts) expect_is(df, "data.frame") expect_equal(colnames(df), c("id", "version","en")) expect_equal(nrow(df), 15L) }) test_that("Concepts - 2.0 - with ConceptSchemes",{ file <- system.file("extdata", "SDMXConceptSchemes_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) concepts <- SDMXConcepts(xmlObj) expect_is(concepts, "SDMXConcepts") df <- as.data.frame(concepts) expect_is(df, "data.frame") expect_equal(colnames(df), c("id", "urn","en")) expect_equal(nrow(df), 15L) }) test_that("Concepts - 2.1 - with ConceptSchemes",{ file <- system.file("extdata", "SDMXConceptSchemes_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) concepts <- SDMXConcepts(xmlObj) expect_is(concepts, "SDMXConcepts") df <- as.data.frame(concepts) expect_is(df, "data.frame") expect_equal(colnames(df), c("id", "urn","en")) expect_equal(nrow(df), 15L) }) rsdmx/tests/testthat/test_Schema.R0000644000176200001440000000213612654150565017006 0ustar liggesusers# test_Schema.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Schema methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXSchema") #read test data file1 <- system.file("extdata", "SDMXMessageExample_2.0.xml", package = "rsdmx") file2 <- system.file("extdata", "SDMXMessageExample_2.1.xml", package = "rsdmx") xmlObj1 <- xmlParse(file1) xmlObj2 <- xmlParse(file2) test_that("version.SDMXSchema - 2.0",{ schema1 = version.SDMXSchema(xmlObj1) expect_equal(schema1, "2.0") }) test_that("version.SDMXSchema - 2.1",{ schema2 = version.SDMXSchema(xmlObj2) expect_equal(schema2, "2.1") }) test_that("SDMXSchema - 2.0",{ obj1 = SDMXSchema(xmlObj1) expect_is(obj1, "SDMXSchema") }) test_that("SDMXSchema - 2.1",{ obj2 = SDMXSchema(xmlObj2) expect_is(obj2, "SDMXSchema") }) test_that("getVersion - 2.0",{ obj1 = SDMXSchema(xmlObj1) expect_equal(obj1@version, "2.0") }) test_that("getVersion - 2.1",{ obj2 = SDMXSchema(xmlObj2) expect_equal(obj2@version, "2.1") }) rsdmx/tests/testthat/test_RequestBuilder.R0000644000176200001440000000445512654150565020553 0ustar liggesusers# test_RequestBuilder.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX Service request builder #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXRequestBuilder") test_that("SDMXRequestBuilder",{ request <- SDMXRequestBuilder( regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", handler = function(regUrl, repoUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant){ return(paste(repoUrl, agencyId, resource, flowRef, key, start, end, sep="/")) }, compliant = TRUE) expect_is(request, "SDMXRequestBuilder") expect_equal(request@regUrl, "http://www.myorg.org/registry") expect_equal(request@repoUrl, "http://www.myorg.org/repository") expect_is(request@handler, "function") expect_equal(request@compliant, TRUE) webRequest <- request@handler(regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", agencyId = "MYORG", resource = "data", flowRef = "FLOW", resourceId = NULL, key = "KEY", start = 2000, end = 2010, compliant = TRUE) expect_equal(webRequest, "http://www.myorg.org/repository/MYORG/data/FLOW/KEY/2000/2010") }) test_that("SDMXRESTRequestBuilder",{ request <- SDMXRESTRequestBuilder(regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", compliant = TRUE) expect_is(request, "SDMXRESTRequestBuilder") expect_equal(request@regUrl, "http://www.myorg.org/registry") expect_equal(request@repoUrl, "http://www.myorg.org/repository") expect_is(request@handler, "function") expect_equal(request@compliant, TRUE) webRequest <- request@handler(regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", agencyId = "MYORG", resource = "data", flowRef = "FLOW", resourceId = NULL, key = "KEY", start = 2000, end = 2010, compliant = TRUE) expect_equal(webRequest, "http://www.myorg.org/repository/data/FLOW/KEY/all?startPeriod=2000&endPeriod=2010") }) rsdmx/tests/testthat/test_CrossSectionalData.R0000644000176200001440000000110212654150565021323 0ustar liggesusers# test_CrossSectionalData.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX CrossSectionalData methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXCrossSectionalData") test_that("CrossSectionalData 1.0",{ file <- system.file("extdata", "SDMXCrossSectionalDataExample_1.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXCrossSectionalData(xmlObj) expect_is(ds, "SDMXCrossSectionalData") df <- as.data.frame(ds) expect_is(df, "data.frame") })rsdmx/tests/testthat/test_StructureSpecificData.R0000644000176200001440000000122312654150565022042 0ustar liggesusers# test_StructureSpecificData.R # Author: Emmanuel Blondel # # Description: Unit tests for SDMX StructureSpecificData methods #======================= require(rsdmx, quietly = TRUE) require(testthat) context("SDMXStructureSpecificData") test_that("StructureSpecificData 2.1",{ file <- system.file("extdata", "SDMXStructureSpecificDataExample_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) ds <- SDMXStructureSpecificData(xmlObj) expect_is(ds, "SDMXStructureSpecificData") df <- as.data.frame(ds) expect_is(df, "data.frame") expect_false(is.null(df)) expect_true(nrow(df) > 0) })rsdmx/tests/test-all.R0000644000176200001440000000004612654150565014432 0ustar liggesuserslibrary(testthat) test_check("rsdmx")rsdmx/NAMESPACE0000644000176200001440000000424712654150565012646 0ustar liggesusersimport("methods") import("XML") import("RCurl") importFrom("plyr", "rbind.fill") importFrom("utils", "packageVersion") exportClasses( SDMX, SDMXSchema, SDMXHeader, SDMXFooterMessage, SDMXFooter, SDMXType, SDMXStructureType, SDMXGenericData, SDMXCompactData, SDMXUtilityData, SDMXStructureSpecificData, SDMXCrossSectionalData, SDMXMessageGroup, SDMXConcept, SDMXConceptScheme, SDMXConcepts, SDMXCode, SDMXCodelist, SDMXCodelists, SDMXDimension, SDMXTimeDimension, SDMXPrimaryMeasure, SDMXAttribute, SDMXComponents, SDMXDataStructure, SDMXDataStructures, SDMXDataStructureDefinition, SDMXDataFlow, SDMXDataFlows, SDMXRequestBuilder, SDMXRESTRequestBuilder, SDMXServiceProvider, SDMXServiceProviders ) export( SDMX, SDMXSchema, SDMXHeader, SDMXFooterMessage, SDMXFooter, SDMXType, SDMXStructureType, SDMXGenericData, SDMXCompactData, SDMXUtilityData, SDMXStructureSpecificData, SDMXCrossSectionalData, SDMXMessageGroup, SDMXConcept, SDMXConceptScheme, SDMXConcepts, SDMXCode, SDMXCodelist, SDMXCodelists, SDMXDimension, SDMXTimeDimension, SDMXPrimaryMeasure, SDMXAttribute, SDMXComponents, SDMXDataStructure, SDMXDataStructures, SDMXDataStructureDefinition, SDMXDataFlow, SDMXDataFlows, SDMXRequestBuilder, SDMXRESTRequestBuilder, SDMXServiceProvider, SDMXServiceProviders, findNamespace, isSoapRequestEnvelope, getSoapRequestResult, addSDMXServiceProvider, findSDMXServiceProvider, setSDMXServiceProviders, getSDMXServiceProviders, readSDMX ) exportMethods( getStructureType, getNamespaces ) S3method(as.data.frame, SDMXGenericData) S3method(as.data.frame, SDMXCompactData) S3method(as.data.frame, SDMXUtilityData) S3method(as.data.frame, SDMXStructureSpecificData) S3method(as.data.frame, SDMXCrossSectionalData) S3method(as.data.frame, SDMXMessageGroup) S3method(as.data.frame, SDMXConcepts) S3method(as.data.frame, SDMXCodelists) S3method(as.data.frame, SDMXDataStructures) S3method(as.data.frame, SDMXDataFlows) S3method(as.data.frame, SDMXServiceProviders)rsdmx/R/0000755000176200001440000000000012654150565011621 5ustar liggesusersrsdmx/R/Class-SDMXMessageGroup.R0000644000176200001440000000125012654150565016102 0ustar liggesusers#' @name SDMXMessageGroup #' @docType class #' @aliases SDMXMessageGroup-class #' #' @title Class "SDMXMessageGroup" #' @description A basic class to handle a SDMX-ML MessageGroup data set #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXMessageGroup", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXDataStructureDefinition-methods.R0000644000176200001440000000120212654150565020677 0ustar liggesusers#' @name SDMXDataStructureDefinition #' @rdname SDMXDataStructureDefinition #' @aliases SDMXDataStructureDefinition,SDMXDataStructureDefinition-method #' #' @usage #' SDMXDataStructureDefinition(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDataStructureDefinition" #' #' @seealso \link{readSDMX} #' SDMXDataStructureDefinition <- function(xmlObj){ new("SDMXDataStructureDefinition", SDMX(xmlObj), concepts = SDMXConcepts(xmlObj), codelists = SDMXCodelists(xmlObj), datastructures = SDMXDataStructures(xmlObj) ) }rsdmx/R/Class-SDMX.R0000644000176200001440000000311112654150565013556 0ustar liggesusers#' @name SDMX #' @rdname SDMX #' @docType class #' @aliases SDMX-class #' #' @title Class "SDMX" #' @description An abstract class from which SDMX classes are derived #' #' @slot xmlObj Object of class "XMLInternalDocument" derived from XML package #' @slot schema Object of class "SDMXSchema", handles the version of SDMX-ML format #' @slot header Object of class "SDMXHeader", handles the SDMX-ML document header #' @slot footer Object of class "SDMXFooter", handles the SDMX-ML document footer #' #' @section Warning: #' This class is not useful in itself, but all SDMX classes in this package derive #' from it. #' #' @note #' Currently, the approach drafted in \link{rsdmx} package was to rely on XML #' package, read the xml object and store it as part of the SDMX R object. Another #' approach being investigated is to use XML handlers throughthe Simple API for XML #' (SAX) that could avoid to load the full XML tree in the SDMX R object (xmlObj). #' Indeed, SDMX data could be huge and causes issues of memory if the complete XML #' tree is loaded in the R user session. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMX", representation( xmlObj = "XMLInternalDocument", schema = "SDMXSchema", header = "SDMXHeader", footer = "SDMXFooter" ), prototype = list( xmlObj = NULL, schema = new("SDMXSchema"), header = new("SDMXHeader"), footer = new("SDMXFooter") ), validity = function(object){ return(TRUE); } ) rsdmx/R/Class-SDMXStructureType.R0000644000176200001440000000225312654150565016347 0ustar liggesusers#' @name SDMXStructureType #' @docType class #' @aliases SDMXStructureType-class #' #' @title Class "SDMXStructureType" #' @description A basic class to handle the type of a SDMX-ML Structure document #' #' @section Warning: #' This class is not useful in itself, but it will be used by \link{readSDMX} to #' deal with SDMX-ML Structure documents. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXStructureType", contains = "SDMXType", representation(subtype = "character"), prototype = list(), validity = function(object){ type <- getStructureType(object); valid <- switch(type, "DataflowsType" = TRUE, "ConceptsType" = TRUE, "CodelistsType" = TRUE, "DataStructuresType" = TRUE, "DataStructureDefinitionsType" = TRUE, FALSE ); if(valid == FALSE) warning(paste("Unknown SDMXStructureType '", type, "'", sep="")); return(valid); } ) rsdmx/R/SDMXPrimaryMeasure-methods.R0000644000176200001440000000737412654150565017061 0ustar liggesusers#' @name SDMXPrimaryMeasure #' @rdname SDMXPrimaryMeasure #' @aliases SDMXPrimaryMeasure,SDMXPrimaryMeasure-method #' #' @usage #' SDMXPrimaryMeasure(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXPrimaryMeasure" #' #' @seealso \link{readSDMX} #' SDMXPrimaryMeasure <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #manage SDMX 2.1 conceptIdentity and codelist LocalRepresentation conceptRefXML <- NULL if(VERSION.21){ conceptIdentityXML <- getNodeSet(xmlDoc(xmlObj), "//str:ConceptIdentity", namespaces = c(str = as.character(strNs))) if(length(conceptIdentityXML) > 0) conceptRefXML <- xmlChildren(conceptIdentityXML[[1]])[[1]] } codelistRefXML <- NULL if(VERSION.21){ enumXML <- getNodeSet(xmlDoc(xmlObj), "//str:Enumeration", namespaces = c(str = as.character(strNs))) if(length(enumXML) > 0) codelistRefXML <- xmlChildren(enumXML[[1]])[[1]] } #attributes #========= conceptRef <- NULL conceptVersion <- NULL conceptAgency <- NULL conceptSchemeRef <- NULL conceptSchemeAgency <- NULL codelist <- NULL codelistVersion <- NULL codelistAgency <- NULL if(VERSION.21){ #concepts if(!is.null(conceptRefXML)){ conceptRef = xmlGetAttr(conceptRefXML, "id") conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") conceptAgency = xmlGetAttr(conceptRefXML, "agencyID") #TODO conceptSchemeRef? #TODO conceptSchemeAgency } #codelists if(!is.null(codelistRefXML)){ codelist <- xmlGetAttr(codelistRefXML, "id") codelistVersion <- xmlGetAttr(codelistRefXML, "version") codelistAgency <- xmlGetAttr(codelistRefXML, "agencyID") } }else{ #concepts conceptRef = xmlGetAttr(xmlObj, "conceptRef") conceptVersion = xmlGetAttr(xmlObj, "conceptVersion") conceptAgency = xmlGetAttr(xmlObj, "conceptAgency") conceptSchemeRef = xmlGetAttr(xmlObj, "conceptSchemeRef") conceptSchemeAgency = xmlGetAttr(xmlObj, "conceptSchemeAgency") #codelists codelist = xmlGetAttr(xmlObj, "codelist") codelistVersion = xmlGetAttr(xmlObj, "codelistVersion") codelistAgency = xmlGetAttr(xmlObj, "codelistAgency") } if(is.null(conceptRef)) conceptRef <- as.character(NA) if(is.null(conceptVersion)) conceptVersion <- as.character(NA) if(is.null(conceptAgency)) conceptAgency <- as.character(NA) if(is.null(conceptSchemeRef)) conceptSchemeRef <- as.character(NA) if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA) if(is.null(codelist)) codelist <- as.character(NA) if(is.null(codelistVersion)) codelistVersion <- as.character(NA) if(is.null(codelistAgency)) codelistAgency <- as.character(NA) #elements #======== #TextFormat TODO #instantiate the object obj<- new("SDMXPrimaryMeasure", #attributes conceptRef = conceptRef, conceptVersion = conceptVersion, conceptAgency = conceptAgency, conceptSchemeRef = conceptSchemeRef, conceptSchemeAgency = conceptSchemeAgency, codelist = codelist, codelistVersion = codelistVersion, codelistAgency = codelistAgency #elements, #TextFormat = TextFormat ) } rsdmx/R/rsdmx.R0000644000176200001440000000151112654150565013077 0ustar liggesusers#' @name rsdmx #' @aliases rsdmx-package #' @aliases rsdmx #' @docType package #' #' @title Tools for Reading SDMX Data and Metadata #' @description #' RSDMX is a package to parse/read SDMX documents in R. It provides: #' - a set of classes and methods to read data and metadata documents exchanged #' through theStatistical Data and Metadata Exchange (SDMX) framework. The package #' currently focuses on the SDMX XML standard format (SDMX-ML). #' - an web-service interface to well-known SDMX data providers #' #' @details #' \tabular{ll}{ #' Package: \tab rsdmx\cr #' Type: \tab Package\cr #' Version #' : \tab 0.5-1\cr #' Date: \tab 2016-01-19\cr #' License: \tab GPL(>=2.0)\cr #' LazyLoad: \tab yes\cr #' } #' #'@author Emmanuel Blondel \email{emmanuel.blondel1@@gmail.com} #' NULLrsdmx/R/Class-SDMXPrimaryMeasure.R0000644000176200001440000000451712654150565016457 0ustar liggesusers#' @name SDMXPrimaryMeasure #' @docType class #' @aliases SDMXPrimaryMeasure-class #' #' @title Class "SDMXPrimaryMeasure #' @description A basic class to handle a SDMX PrimaryMeasure #' #' @slot conceptRef Object of class "character" giving the dimension conceptRef (required) #' @slot conceptVersion Object of class "character" giving the dimension concept version #' @slot conceptAgency Object of class "character" giving the dimension concept agency #' @slot conceptSchemeRef Object of class "character" giving the dimension conceptScheme ref #' @slot conceptSchemeAgency Object of class "character" giving the dimension conceptScheme agency #' @slot codelist Object of class "character" giving the codelist ref name #' @slot codelistVersion Object of class "character" giving the codelist ref version #' @slot codelistAgency Object of class "character" giving the codelist ref agency #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXPrimaryMeasure", representation( #attributes conceptRef = "character", #required conceptVersion = "character", #optional conceptAgency = "character", #optional conceptSchemeRef = "character", #optional conceptSchemeAgency = "character", #optional codelist = "character", #optional codelistVersion = "character", #optional codelistAgency = "character" #optional #elements #TextFormat = "SDMXTextFormat" #optional ), prototype = list( #attributes conceptRef = "CONCEPT", conceptVersion = "1.0", conceptAgency = "ORG", conceptSchemeRef = "CONCEPT_SCHEME", conceptSchemeAgency = "ORG", codelist = "CODELIST", codelistVersion = "1.0", codelistAgency = "ORG" #elements #TextFormat = new("SDMXTextFormat") ), validity = function(object){ #eventual validation rules if(is.na(object@conceptRef)) return(FALSE) return(TRUE); } ) rsdmx/R/SDMXServiceProviders-methods.R0000644000176200001440000000205512654150565017401 0ustar liggesusers#' @name SDMXServiceProviders #' @rdname SDMXServiceProviders #' @aliases SDMXServiceProviders,SDMXServiceProviders-method #' #' @usage #'SDMXServiceProviders(providers) #' #' @param providers an object of class "list" (of \link{SDMXServiceProvider}) #' configured by default and/or at runtime in \pkg{rsdmx} #' @return an object of class "SDMXServiceProviders" #' SDMXServiceProviders <- function(providers) { new("SDMXServiceProviders", providers = providers); } as.data.frame.SDMXServiceProviders <- function(x, ...){ out <- as.data.frame(do.call("rbind", lapply(slot(x, "providers"), function(provider){ c(slot(provider,"agencyId"), slot(provider, "name"), slot(provider, "scale"), slot(provider, "country")) })), stringsAsFactors = FALSE) colnames(out) <- c("agencyId", "name", "scale", "country") return(out) } setAs("SDMXGenericData", "data.frame", function(from) {as.data.frame.SDMXServiceProviders(from)});rsdmx/R/Class-SDMXCodelists.R0000644000176200001440000000141612654150565015436 0ustar liggesusers#' @name SDMXCodelists #' @docType class #' @aliases SDMXCodelists-class #' #' @title Class "SDMXCodelists" #' @description A basic class to handle SDMX Codelists #' #' @slot codelists Object of class "list" giving the list of "SDMXCodelist" #' #' @section Warning: #' This class is not useful in itself, but \link{SDMXDataStructureDefinition} objects #' will encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXCodelists", contains = "SDMX", representation( codelists = "list" ), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } )rsdmx/R/SDMXType-methods.R0000644000176200001440000000170212654150565015022 0ustar liggesusers#' @name SDMXType #' @rdname SDMXType #' @aliases SDMXType,SDMXType-method #' #' @usage #' SDMXType(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXType" #' #' @note #' At now, the following types have been implemented and successfully tested: #' - \code{StructureType}, #' - \code{GenericDataType}, #' - \code{CompactDataType}, #' - \code{StructureSpecificDataType}, #' - \code{CrossSectionalDataType}, #' - \code{UtilityDataType}, #' - \code{MessageGroupType} #' #' @seealso \link{readSDMX} #' SDMXType <- function(xmlObj){ new("SDMXType", type = type.SDMXType(xmlObj)); } type.SDMXType <- function(xmlObj){ type <- xmlName(xmlRoot(xmlObj)) if(attr(regexpr(":", type, ignore.case = T),"match.length") > 0){ type <-strsplit(xmlName(xmlRoot(xmlObj), full=T), ":")[[1]][2] } res <- paste(type, "Type", sep=""); return(res) } rsdmx/R/Class-SDMXConcept.R0000644000176200001440000000600112654150565015073 0ustar liggesusers#' @name SDMXConcept #' @docType class #' @aliases SDMXConcept-class #' #' @title Class "SDMXConcept" #' @description A basic class to handle a SDMX Concept #' #' @slot id Object of class "character" giving the ID of the concept (required) #' @slot agencyID Object of class "character" giving the AgencyID #' @slot version Object of class "character" giving the concept version #' @slot uri Object of class "character" giving the concept uri #' @slot urn Object of class "character" giving the concept urn #' @slot isExternalReference Object of class "logical" indicating if the concept is an external reference #' @slot coreRepresentation Object of class "character" giving the core representation #' @slot coreRepresentationAgency Object of class "character" giving the core representation agency #' @slot parent Object of class "character" giving the concept parent #' @slot parentAgency Object of class "character" giving the parentAgency #' @slot Name Object of class "list" giving the concept name (by language) - required #' @slot Description Object of class "list" giving the concept description (by language) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXConcept", representation( #attributes id = "character", #required agencyID = "character", #optional version = "character", #optional uri = "character", #optional urn = "character", #optional isExternalReference = "logical", #optional coreRepresentation = "character", #optional coreRepresentationAgency = "character", #optional parent = "character", #optional parentAgency = "character", #optional #elements Name = "list", #at least one Description = "list" #optional ), prototype = list( #attributes id = "CONCEPT_ID", agencyID = "AGENCY_ID", version = "1.0", uri = as.character(NA), urn = as.character(NA), isExternalReference = FALSE, coreRepresentation = as.character(NA), coreRepresentationAgency = as.character(NA), parent = as.character(NA), parentAgency = as.character(NA), #elements Name = list( en = "concept name", fr = "nom du concept" ), Description = list( en = "concept description", fr = "description du concept" ) ), validity = function(object){ #validation rules if(is.na(object@id)) return(FALSE) if(length(object@Name) == 0) return(FALSE) return(TRUE); } )rsdmx/R/SDMX-methods.R0000644000176200001440000001152712654150565014166 0ustar liggesusers#' @name SDMX #' @rdname SDMX #' @aliases SDMX,SDMX-method #' #' @usage #' SDMX(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMX" #' #' @seealso \link{readSDMX} SDMX <- function(xmlObj){ schema <- SDMXSchema(xmlObj); header <- SDMXHeader(xmlObj); footer <- SDMXFooter(xmlObj); new("SDMX", xmlObj = xmlObj, schema = schema, header = header, footer = footer); } #functions namespaces.SDMX <- function(xmlObj){ nsFromXML <- xmlNamespaceDefinitions(xmlObj, recursive = TRUE, simplify = FALSE) nsDefs.df <- do.call("rbind", lapply(nsFromXML, function(x){ c(x$id, x$uri) })) row.names(nsDefs.df) <- 1:nrow(nsDefs.df) nsDefs.df <-as.data.frame(nsDefs.df, stringAsFactors = FALSE) if(nrow(nsDefs.df) > 0){ colnames(nsDefs.df) <- c("id","uri") nsDefs.df$id <- as.character(nsDefs.df$id) nsDefs.df$uri <- as.character(nsDefs.df$uri) } nsDefs.df <- unique(nsDefs.df) nsDefs.df <- nsDefs.df[!duplicated(nsDefs.df$uri),] return(nsDefs.df) } #' @name getNamespaces #' @docType methods #' @aliases getNamespaces,SDMX-method #' @title getNamespaces #' @description Access the namespaces of the SDMX-ML object #' @usage getNamespaces(obj) #' #' @param obj An object deriving from class "SDMX" #' @return an object of class \code{data.frame} giving the id and uri for each #' of the namespaces handled in the SDMX-ML document. #' #' @seealso \link{SDMX-class} #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} if (!isGeneric("getNamespaces")) setGeneric("getNamespaces", function(obj) standardGeneric("getNamespaces")); #' @describeIn getNamespaces setMethod(f = "getNamespaces", signature = "SDMX", function(obj){ return(namespaces.SDMX(obj@xmlObj)); }) #others non-S4 methods #==================== #' @name findNamespace #' @aliases findNamespace #' @title findNamespace #' @description function used to find a specific namespace within the available #' namespaces of an SDMX-ML object #' #' @usage #' findNamespace(namespaces, messageType) #' #' @param namespaces object of class \code{data.frame} giving the id and uri of #' namespaces available in a SDMX-ML object, typically obtained #' with \link{getNamespaces} #' @param messageType object of class \code{character} representing a message type #' @return an object of class "character" giving the namespace uri if found in the #' available namespaces #' #' @section Warning: #' \code{findNamespace} is a function used internally as utility function in #' SDMX-ML object parsers. #' #' @seealso \link{SDMX-class} \link{getNamespaces} #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} findNamespace <- function(namespaces, messageType){ regexp <- paste(messageType, "$", sep = "") ns <- c(ns = namespaces$uri[grep(regexp, namespaces$uri, ignore.case = TRUE)]) return(ns) } #' @name isSoapRequestEnvelope #' @aliases isSoapRequestEnvelope #' @title isSoapRequestEnvelope #' @description function used to detect if the XML document corresponds to a SOAP #' request response #' @usage #' isSoapRequestEnvelope(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "logical" #' #' @section Warning: #' \code{isSoapRequestEnvelope} is a function used internally by \link{readSDMX} #' #' @seealso \link{SDMX-class} \link{readSDMX} #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' isSoapRequestEnvelope <- function(xmlObj){ namespaces <- namespaces.SDMX(xmlObj) ns <- c(ns = namespaces$uri[grep("soap", namespaces$uri)]) return(length(ns) > 0) } #' @name getSoapRequestResult #' @aliases getSoapRequestResult #' @title getSoapRequestResult #' @description function used to extract the SDMX-ML message from a SOAP request #' response #' @usage #' getSoapRequestResult(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "XMLInternalDocument derived from XML package #' #' @section Warning: #' \code{getSoapRequestResult} is a function used internally by \link{readSDMX} #' #' @seealso \link{SDMX-class} \link{readSDMX} #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} getSoapRequestResult <- function(xmlObj){ body <- xmlChildren(xmlRoot(xmlObj)) response <- xmlChildren(body[[1]]); rm(body); result <- xmlChildren(response[[1]]); rm(response); sdmxDoc <- xmlDoc(xmlChildren(result[[1]])[[1]]); rm(result); return(sdmxDoc) } rsdmx/R/Class-SDMXSchema.R0000644000176200001440000000175012654150565014706 0ustar liggesusers#' @name SDMXSchema #' @docType class #' @aliases SDMXSchema-class #' @title Class "SDMXSchema" #' @description A basic class to handle the version of the SDMX-ML Schema #' #' @slot version Object of class "character" giving the SDMX-ML schema version #' #' @section Warning: #' this class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXSchema", representation( version = "character" ), prototype = list(version = "2.0"), validity = function(object){ VERSION <- object@version; valid <- switch(VERSION, "1.0" = TRUE, "2.0" = TRUE, "2.1" = TRUE, FALSE ); if(valid == FALSE) warning(paste("SDMXSchema version ", VERSION," not supported by RSDMX", sep="")); return(valid); } ) rsdmx/R/SDMXMessageGroup-methods.R0000644000176200001440000000433212654150565016504 0ustar liggesusers#' @name SDMXMessageGroup #' @rdname SDMXMessageGroup #' @aliases SDMXMessageGroup,SDMXMessageGroup-method #' #' @usage #' SDMXMessageGroup(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXMessageGroup" #' #' @seealso \link{readSDMX} #' SDMXMessageGroup <- function(xmlObj){ new("SDMXMessageGroup", SDMX(xmlObj) ) } #methods #======= class.SDMXMessageGroup <- function(xmlObj){ #namespace nsDefs.df <- namespaces.SDMX(xmlObj) #in case no ns found, try to find specific namespace ns.df <- nsDefs.df[ regexpr("http://www.sdmx.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == -1 & regexpr("http://www.w3.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == -1,] ns <- ns.df$uri if(length(ns) > 1) ns <- ns[1L] authorityNs <- nsDefs.df[nsDefs.df$uri == ns,] if(nrow(authorityNs) == 0){ hasAuthorityNS <- FALSE }else{ hasAuthorityNS <- TRUE } #business logic to inherit wrapped object class wrappedClass <- NULL seriesKeyXML <- NULL if(hasAuthorityNS){ seriesKeyXML <- getNodeSet(xmlObj, "//ns:SeriesKey", c(ns = authorityNs$uri)) }else{ if(nrow(nsDefs.df) > 0){ seriesKeyXML <- getNodeSet(xmlObj, "//ns:SeriesKey", c(ns = nsDefs.df[1,"uri"])) }else{ stop("Unsupported XML parser for empty target XML namespace") } } if(!is.null(seriesKeyXML)){ if(length(seriesKeyXML) > 0){ wrappedClass <- "SDMXGenericData" }else{ wrappedClass <- "SDMXCompactData" } } return(wrappedClass) } as.data.frame.SDMXMessageGroup <- function(x, ...){ #TODO support for other included message types #(at now limited to SDMXGenericData for making it work with OECD) xmlObj <- slot(x, "xmlObj") sdmx.df <- switch(class.SDMXMessageGroup(xmlObj), "SDMXGenericData" = as.data.frame.SDMXGenericData(x), "SDMXCompactData" = as.data.frame.SDMXCompactData(x), NULL ) return(sdmx.df) } setAs("SDMXMessageGroup", "data.frame", function(from) as.data.frame.SDMXMessageGroup(from)); rsdmx/R/Class-SDMXStructureSpecificData.R0000644000176200001440000000132312654150565017742 0ustar liggesusers#' @name SDMXStructureSpecificData #' @docType class #' @aliases SDMXStructureSpecificData-class #' #' @title Class "SDMXStructureSpecificData" #' @description A basic class to handle a SDMX-ML StructureSpecificData data set #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXStructureSpecificData", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXConcept-methods.R0000644000176200001440000000637312654150565015505 0ustar liggesusers#' @name SDMXConcept #' @rdname SDMXConcept #' @aliases SDMXConcept,SDMXConcept-method #' #' @usage #' SDMXConcept(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXConcept" #' #' @seealso \link{readSDMX} #' SDMXConcept <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") refNs <- strNs if(VERSION.21){ comNs <- findNamespace(namespaces, "common") refNs <- comNs } #attributes #========= id = xmlGetAttr(xmlObj, "id") if(is.null(id)) id <- as.character(NA) agencyId = xmlGetAttr(xmlObj, "agencyID") if(is.null(agencyId)) agencyId <- as.character(NA) version = xmlGetAttr(xmlObj, "version") if(is.null(version)) version <- as.character(NA) uri = xmlGetAttr(xmlObj, "uri") if(is.null(uri)) uri <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) isExternalReference = xmlGetAttr(xmlObj, "isExternalReference") if(is.null(isExternalReference)){ isExternalReference <- NA }else{ isExternalReference <- as.logical(isExternalReference) } coreRepresentation = xmlGetAttr(xmlObj, "coreRepresentation") if(is.null(coreRepresentation)) coreRepresentation <- as.character(NA) coreRepresentationAgency = xmlGetAttr(xmlObj, "coreRepresentationAgency") if(is.null(coreRepresentationAgency)) coreRepresentationAgency <- as.character(NA) parent = xmlGetAttr(xmlObj, "parent") if(is.null(parent)) parent <- as.character(NA) parentAgency = xmlGetAttr(xmlObj, "parentAgency") if(is.null(parentAgency)) parentAgency <- as.character(NA) #elements #======== #name (multi-languages) conceptNamesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Name", namespaces = refNs) conceptNames <- NULL if(length(conceptNamesXML) > 0){ conceptNames <- new.env() sapply(conceptNamesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") conceptNames[[lang]] <- xmlValue(x) }) conceptNames <- as.list(conceptNames) } #description (multi-languages) conceptDesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Description", namespaces = refNs) conceptDescriptions <- list() if(length(conceptDesXML) > 0){ conceptDescriptions <- new.env() sapply(conceptDesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") conceptDescriptions[[lang]] <- xmlValue(x) }) conceptDescriptions <- as.list(conceptDescriptions) } #instantiate the object obj<- new("SDMXConcept", #attributes id = id, agencyID = agencyId, version = version, uri = uri, urn = urn, isExternalReference = isExternalReference, coreRepresentation = coreRepresentation, coreRepresentationAgency = coreRepresentationAgency, parent = parent, parentAgency = parentAgency, #elements Name = conceptNames, Description = conceptDescriptions ) } rsdmx/R/SDMXCompactData-methods.R0000644000176200001440000001010212654150565016253 0ustar liggesusers#' @name SDMXCompactData #' @rdname SDMXCompactData #' @aliases SDMXCompactData,SDMXCompactData-method #' #' @usage #' SDMXCompactData(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXCompactData" #' #' @seealso \link{readSDMX} #' SDMXCompactData <- function(xmlObj){ new("SDMXCompactData", SDMX(xmlObj) ) } #methods as.data.frame.SDMXAllCompactData <- function(x, nsExpr, ...) { xmlObj <- x@xmlObj; dataset <- NULL schema <- slot(x,"schema") sdmxVersion <- slot(schema,"version") VERSION.21 <- sdmxVersion == "2.1" #namespace hasAuthorityNS <- FALSE nsDefs.df <- getNamespaces(x) ns <- findNamespace(nsDefs.df, nsExpr) authorityNs <- nsDefs.df[ regexpr("http://www.sdmx.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == -1 & regexpr("http://www.w3.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == -1,] if(nrow(authorityNs) > 0){ hasAuthorityNS <- TRUE if(nrow(authorityNs) > 1){ warning("More than one target dataset namespace found!") authorityNs <- authorityNs[1L,] } } if(hasAuthorityNS){ seriesXML <- getNodeSet(xmlObj, "//ns:Series", namespaces = c(ns = authorityNs$uri)) if(length(seriesXML) == 0){ seriesXML <- getNodeSet(xmlObj, "//ns:Series", namespaces = ns) } }else{ if(length(ns) > 0){ seriesXML <- getNodeSet(xmlObj, "//ns:Series", namespaces = ns) }else{ if(nrow(nsDefs.df) > 0){ serieNs <- nsDefs.df[1,] seriesXML <- getNodeSet(xmlObj, "//nt:Series", c(nt = serieNs$uri)) }else{ stop("Unsupported CompactData parser for empty target XML namespace") } } } if(length(seriesXML) == 0){ seriesXML <- getNodeSet(xmlObj, "//Series") } seriesNb <- length(seriesXML) if(seriesNb == 0) return(NULL); #function to parse a Serie parseSerie <- function(x){ #obs attributes (which may include observations) obsValueXML <- xmlChildren(x) obsAttrs <- data.frame() if(length(obsValueXML) > 0){ obsAttrs <- do.call("rbind.fill", lapply(obsValueXML, function(t){ data.frame(as.list(xmlAttrs(t)), stringsAsFactors = FALSE) })) } #obs children (in case we have) obsValues <- try(xmlToDataFrame(obsValueXML, stringsAsFactors = FALSE), silent=TRUE) if(class(obsValues) == "try-error"){ obsValues <- NULL }else{ obsKeyNames <- names(lapply(obsValueXML, xmlChildren)[["Key"]]) obsValues[,obsKeyNames] <- obsValues[1,obsKeyNames] obsValues <- obsValues[-1,] invisible(lapply(obsKeyNames, function(t) obsValues[nchar(obsValues[,t],"w")==0,t] <<- NA)) } #key values keydf <- as.data.frame(t(as.data.frame(xmlAttrs(x), stringAsFactors = FALSE)), stringAsFactors = FALSE) if(nrow(obsAttrs) > 0){ keydf <- keydf[rep(row.names(keydf), nrow(obsAttrs)),] if(class(keydf) == "data.frame") row.names(keydf) <- 1:nrow(obsAttrs) } #single Serie as DataFrame if(nrow(obsAttrs) > 0){ obsContent <- obsAttrs if(!is.null(obsValues)){ obsContent <- cbind(obsAttrs, obsValues) } serie <- cbind(keydf, obsContent, row.names = 1:nrow(obsAttrs)) }else{ #manage absence data serie <- keydf } return(serie) } #converting SDMX series to a DataFrame R object dataset <- do.call("rbind.fill", lapply(seriesXML, function(x){serie <- parseSerie(x) })) if(any(as.character(dataset$obsValue) == "NaN", na.rm = TRUE)){ dataset[as.character(dataset$obsValue) == "NaN",]$obsValue <- NA } if(!is.null(dataset)) row.names(dataset) <- 1:nrow(dataset) # output return(dataset) } as.data.frame.SDMXCompactData <- function(x, ...){ return(as.data.frame.SDMXAllCompactData(x, "compact")); } setAs("SDMXCompactData", "data.frame", function(from) as.data.frame.SDMXCompactData(from)); rsdmx/R/Class-SDMXUtilityData.R0000644000176200001440000000124112654150565015736 0ustar liggesusers#' @name SDMXUtilityData #' @docType class #' @aliases SDMXUtilityData-class #' #' @title Class "SDMXUtilityData" #' @description A basic class to handle a SDMX-ML UtilityData data set #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXUtilityData", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/Class-SDMXDataStructureDefinition.R0000644000176200001440000000270412654150565020311 0ustar liggesusers#' @name SDMXDataStructureDefinition #' @docType class #' @aliases SDMXDataStructureDefinition-class #' #' @title Class "SDMXDataStructureDefinition" #' @description A basic class to handle a SDMX DataStructureDefinition (DSD) #' #' @slot concepts Object of class "SDMXConcepts" giving the list of concepts or #' conceptSchemes (see \link{SDMXConcepts}) #' @slot codelists Object of class "SDMXCodelists" giving the list of codelists #' (see \link{SDMXCodelists}) #' @slot datastructures Object of class "SDMXDataStructures" giving the list of #' datastructures /key families (see \link{SDMXDataStructures}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXDataStructureDefinition", contains = "SDMX", representation( concepts = "SDMXConcepts", codelists = "SDMXCodelists", datastructures = "SDMXDataStructures" ), prototype = list( concepts = new("SDMXConcepts"), codelists = new("SDMXCodelists"), datastructures = new("SDMXDataStructures") ), validity = function(object){ #eventual validation rules return(TRUE); } )rsdmx/R/SDMXComponents-methods.R0000644000176200001440000001012612654150565016226 0ustar liggesusers#' @name SDMXComponents #' @rdname SDMXComponents #' @aliases SDMXComponents,SDMXComponents-method #' #' @usage #' SDMXComponents(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXComponents" #' #' @seealso \link{readSDMX} #' SDMXComponents <- function(xmlObj){ new("SDMXComponents", Dimensions = dimensions.SDMXComponents(xmlObj), TimeDimension = timedimension.SDMXComponents(xmlObj), PrimaryMeasure = primarymeasure.SDMXComponents(xmlObj), Attributes = attributes.SDMXComponents(xmlObj) ) } #get list of SDMXDimension #========================= dimensions.SDMXComponents <- function(xmlObj){ dimensions <- NULL sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) strNs <- findNamespace(namespaces, "structure") dimensionsXML <- NULL if(VERSION.21){ dimensionsXML <- getNodeSet(xmlDoc(xmlObj), "//str:DimensionList/str:Dimension", namespaces = c(str = as.character(strNs))) }else{ dimensionsXML <- getNodeSet(xmlDoc(xmlObj), "//str:Dimension", namespaces = c(str = as.character(strNs))) } if(!is.null(dimensionsXML)){ dimensions <- lapply(dimensionsXML, function(x){ SDMXDimension(x)}) } return(dimensions) } #get SDMXTimeDimension #===================== timedimension.SDMXComponents <- function(xmlObj){ timedimension <- NULL sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) strNs <- findNamespace(namespaces, "structure") timeDimXML <- NULL if(VERSION.21){ timeDimXML <- getNodeSet(xmlDoc(xmlObj), "//str:DimensionList/str:TimeDimension", namespaces = c(str = as.character(strNs))) }else{ timeDimXML <- getNodeSet(xmlDoc(xmlObj), "//str:TimeDimension", namespaces = c(str = as.character(strNs))) } if(length(timeDimXML) > 0){ timeDimensionXML <- timeDimXML[[1]] timedimension <- SDMXTimeDimension(timeDimensionXML) } return(timedimension) } #get SDMXPrimaryMeasure #====================== primarymeasure.SDMXComponents <- function(xmlObj){ primarymeasure <- NULL sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) strNs <- findNamespace(namespaces, "structure") if(VERSION.21){ measureXML <- getNodeSet(xmlDoc(xmlObj), "//str:MeasureList/str:PrimaryMeasure", namespaces = c(str = as.character(strNs))) }else{ measureXML <- getNodeSet(xmlDoc(xmlObj), "//str:PrimaryMeasure", namespaces = c(str = as.character(strNs))) } if(length(measureXML) > 0){ measureXML <- measureXML[[1]] primarymeasure <- SDMXPrimaryMeasure(measureXML) } return(primarymeasure) } #get list of SDMXAttribute #========================= attributes.SDMXComponents <- function(xmlObj){ attributes <- NULL sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) strNs <- findNamespace(namespaces, "structure") if(VERSION.21){ attributesXML <- getNodeSet(xmlDoc(xmlObj), "//str:AttributeList/str:Attribute", namespaces = c(str = as.character(strNs))) }else{ attributesXML <- getNodeSet(xmlDoc(xmlObj), "//str:Attribute", namespaces = c(str = as.character(strNs))) } if(!is.null(attributesXML)){ attributes <- lapply(attributesXML, function(x){ SDMXDimension(x)}) } return(attributes) }rsdmx/R/Class-SDMXConcepts.R0000644000176200001440000000243112654150565015261 0ustar liggesusers#' @name SDMXConcepts #' @docType class #' @aliases SDMXConcepts-class #' #' @title Class "SDMXConcepts" #' @description A basic class to handle SDMX Concepts #' #' @slot concepts Object of class "list" giving the list of "SDMXConcept". This #' slot is available to ensure backward compatibility with SDMX 1.0 in SDMX #' 2.0 or 2.1 documents #' @slot conceptSchemes Object of class "list" giving the list of "SDMXConceptScheme", #' which will encapsulate the list of "SDMXConcept" (defined from SDMX 2.0) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXConcepts", contains = "SDMX", representation( concepts = "list", #required for backward compatibility with SDMX 1.0 conceptSchemes = "list" #SDMX > 1.0 ), prototype = list( concepts = list(), conceptSchemes = list() ), validity = function(object){ #eventual validation rules return(TRUE); } )rsdmx/R/SDMXTimeDimension-methods.R0000644000176200001440000001264612654150565016656 0ustar liggesusers#' @name SDMXTimeDimension #' @rdname SDMXTimeDimension #' @aliases SDMXTimeDimension,SDMXTimeDimension-method #' #' @usage #' SDMXTimeDimension(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXTimeDimension" #' #' @seealso \link{readSDMX} #' SDMXTimeDimension <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #manage SDMX 2.1 conceptIdentity conceptRefXML <- NULL if(VERSION.21){ conceptIdentityXML <- getNodeSet(xmlDoc(xmlObj), "//str:ConceptIdentity", namespaces = c(str = as.character(strNs))) if(length(conceptIdentityXML) > 0) conceptRefXML <- xmlChildren(conceptIdentityXML[[1]])[[1]] } codelistRefXML <- NULL if(VERSION.21){ enumXML <- getNodeSet(xmlDoc(xmlObj), "//str:Enumeration", namespaces = c(str = as.character(strNs))) if(length(enumXML) > 0) codelistRefXML <- xmlChildren(enumXML[[1]])[[1]] } #attributes #========= conceptRef <- NULL conceptVersion <- NULL conceptAgency <- NULL conceptSchemeRef <- NULL conceptSchemeAgency <- NULL codelist <- NULL codelistVersion <- NULL codelistAgency <- NULL crossSectionalAttachDataset <- NULL crossSectionalAttachGroup <- NULL crossSectionalAttachSection <- NULL crossSectionalAttachObservation <- NULL if(VERSION.21){ #concepts if(!is.null(conceptRefXML)){ conceptRef = xmlGetAttr(conceptRefXML, "id") conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") conceptAgency = xmlGetAttr(conceptRefXML, "agencyID") #TODO conceptSchemeRef? #TODO conceptSchemeAgency } #codelists if(!is.null(codelistRefXML)){ codelist <- xmlGetAttr(codelistRefXML, "id") codelistVersion <- xmlGetAttr(codelistRefXML, "version") codelistAgency <- xmlGetAttr(codelistRefXML, "agencyID") } #crossSectionalAttach #TODO crossSectionalAttachDataset? #TODO crossSectionalAttachGroup? #TODO crossSectionalAttachSection? #TODO crossSectionalAttachObservation? }else{ #concepts conceptRef = xmlGetAttr(xmlObj, "conceptRef") conceptVersion = xmlGetAttr(xmlObj, "conceptVersion") conceptAgency = xmlGetAttr(xmlObj, "conceptAgency") conceptSchemeRef = xmlGetAttr(xmlObj, "conceptSchemeRef") conceptSchemeAgency = xmlGetAttr(xmlObj, "conceptSchemeAgency") #codelists codelist = xmlGetAttr(xmlObj, "codelist") codelistVersion = xmlGetAttr(xmlObj, "codelistVersion") codelistAgency = xmlGetAttr(xmlObj, "codelistAgency") #crossSectionalAttach crossSectionalAttachDataset = xmlGetAttr(xmlObj, "crossSectionalAttachDataset") crossSectionalAttachGroup = xmlGetAttr(xmlObj, "crossSectionalAttachGroup") crossSectionalAttachSection = xmlGetAttr(xmlObj, "crossSectionalAttachSection") crossSectionalAttachObservation = xmlGetAttr(xmlObj,"crossSectionalAttachObservation") } if(is.null(conceptRef)) conceptRef <- as.character(NA) if(is.null(conceptVersion)) conceptVersion <- as.character(NA) if(is.null(conceptAgency)) conceptAgency <- as.character(NA) if(is.null(conceptSchemeRef)) conceptSchemeRef <- as.character(NA) if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA) if(is.null(codelist)) codelist <- as.character(NA) if(is.null(codelistVersion)) codelistVersion <- as.character(NA) if(is.null(codelistAgency)) codelistAgency <- as.character(NA) if(is.null(crossSectionalAttachDataset)){ crossSectionalAttachDataset <- NA }else{ crossSectionalAttachDataset <- as.logical(crossSectionalAttachDataset) } if(is.null(crossSectionalAttachGroup)){ crossSectionalAttachGroup <- NA }else{ crossSectionalAttachGroup <- as.logical(crossSectionalAttachGroup) } if(is.null(crossSectionalAttachSection)){ crossSectionalAttachSection <- NA }else{ crossSectionalAttachSection <- as.logical(crossSectionalAttachSection) } if(is.null(crossSectionalAttachObservation)){ crossSectionalAttachObservation <- NA }else{ crossSectionalAttachObservation <- as.logical(crossSectionalAttachObservation) } #elements #======== #TextFormat TODO #instantiate the object obj<- new("SDMXTimeDimension", #attributes conceptRef = conceptRef, conceptVersion = conceptVersion, conceptAgency = conceptAgency, conceptSchemeRef = conceptSchemeRef, conceptSchemeAgency = conceptSchemeAgency, codelist = codelist, codelistVersion = codelistVersion, codelistAgency = codelistAgency, crossSectionalAttachDataset = crossSectionalAttachDataset, crossSectionalAttachGroup = crossSectionalAttachGroup, crossSectionalAttachSection = crossSectionalAttachSection, crossSectionalAttachObservation = crossSectionalAttachObservation #elements, #TextFormat = TextFormat ) } rsdmx/R/Class-SDMXComponents.R0000644000176200001440000000245612654150565015637 0ustar liggesusers#' @name SDMXComponents #' @docType class #' @aliases SDMXComponents-class #' @title Class "SDMXComponents" #' @description A basic class to handle SDMX Components #' #' @slot Dimensions Object of class "list" giving the list of dimensions (see \link{SDMXDimension}) #' @slot TimeDimension Object of class "SDMXTimeDimension" #' @slot PrimaryMeasure Object of class "SDMXPrimaryMeasure" #' @slot Attributes Object of class "list" giving the list of attributes (see \link{SDMXAttribute}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (DataStructures, or #' DataStructureDefinitions) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXComponents", representation( Dimensions = "list", TimeDimension = "SDMXTimeDimension_OR_NULL", PrimaryMeasure = "SDMXPrimaryMeasure", Attributes = "list" #crossSectionalMeasures = "list", #Groups = "list ), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) setClassUnion("SDMXComponents_OR_NULL", c("SDMXComponents","NULL")) rsdmx/R/profile.R0000644000176200001440000000025012654150565013401 0ustar liggesusers.onLoad <- function (libname, pkgname) { # nocov start assign(".rsdmx.options", new.env(), envir= asNamespace(pkgname)) setSDMXServiceProviders() } # nocov end rsdmx/R/SDMXConceptScheme-methods.R0000644000176200001440000000762112654150565016627 0ustar liggesusers#' @name SDMXConceptScheme #' @rdname SDMXConceptScheme #' @aliases SDMXConceptScheme,SDMXConceptScheme-method #' #' @usage #' SDMXConceptScheme(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXConceptScheme" #' #' @seealso \link{readSDMX} #' SDMXConceptScheme <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #attributes #========= id = xmlGetAttr(xmlObj, "id") if(is.null(id)) id <- as.character(NA) agencyId = xmlGetAttr(xmlObj, "agencyID") if(is.null(agencyId)) agencyId <- as.character(NA) version = xmlGetAttr(xmlObj, "version") if(is.null(version)) version <- as.character(NA) uri = xmlGetAttr(xmlObj, "uri") if(is.null(uri)) uri <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) isExternalReference = xmlGetAttr(xmlObj, "isExternalReference") if(is.null(isExternalReference)){ isExternalReference <- NA }else{ isExternalReference <- as.logical(isExternalReference) } isFinal = xmlGetAttr(xmlObj, "isFinal") if(is.null(isFinal)){ isFinal <- NA }else{ isFinal <- as.logical(isFinal) } validFrom = xmlGetAttr(xmlObj,"validFrom") if(is.null(validFrom)) validFrom <- as.character(NA) validTo = xmlGetAttr(xmlObj, "validTo") if(is.null(validTo)) validTo <- as.character(NA) #elements #======== #name (multi-languages) conceptNamesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") conceptNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:ConceptScheme/com:Name", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ conceptNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:ConceptScheme/str:Name", namespaces = c(str = as.character(strNs))) } conceptNames <- NULL if(length(conceptNamesXML) > 0){ conceptNames <- new.env() sapply(conceptNamesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") conceptNames[[lang]] <- xmlValue(x) }) conceptNames <- as.list(conceptNames) } #description (multi-languages) conceptDesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:ConceptScheme/ns:Description", namespaces = strNs) conceptDescriptions <- list() if(length(conceptDesXML) > 0){ conceptDescriptions <- new.env() sapply(conceptDesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") conceptDescriptions[[lang]] <- xmlValue(x) }) conceptDescriptions <- as.list(conceptDescriptions) } #concepts conceptsXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Concept", namespaces = strNs) concepts <- list() if(length(conceptsXML) > 0){ concepts <- lapply(conceptsXML, function(x){ SDMXConcept(x)}) } #instantiate the object obj<- new("SDMXConceptScheme", #attributes id = id, agencyID = agencyId, version = version, uri = uri, urn = urn, isExternalReference = isExternalReference, isFinal = isFinal, validFrom = validFrom, validTo = validTo, #elements, Name = conceptNames, Description = conceptDescriptions, Concept = concepts ) } rsdmx/R/SDMXCode-methods.R0000644000176200001440000000401712654150565014755 0ustar liggesusers#' @name SDMXCode #' @rdname SDMXCode #' @aliases SDMXCode,SDMXCode-method #' #' @usage #' SDMXCode(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXCode" #' #' @seealso \link{readSDMX} #' SDMXCode <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") refNs <- strNs if(VERSION.21){ comNs <- findNamespace(namespaces, "common") refNs <- comNs } #attributes #========= id <- NULL if(VERSION.21){ id <- xmlGetAttr(xmlObj, "id") }else{ id <- xmlGetAttr(xmlObj, "value") } if(is.null(id)) id <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) parentCode = xmlGetAttr(xmlObj, "parentCode") if(is.null(parentCode)) parentCode <- as.character(NA) #elements #======== # Labels - name /description (multi-languages) codeLabelsXML <- NULL if(VERSION.21){ codeLabelsXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Name", namespaces = refNs) }else{ codeLabelsXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Description", namespaces = refNs) } codeLabels <- list() if(length(codeLabelsXML) > 0){ codeLabels <- new.env() sapply(codeLabelsXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") if(is.null(lang)) lang <- "default" codeLabels[[lang]] <- xmlValue(x) }) codeLabels <- as.list(codeLabels) } #instantiate the object obj<- new("SDMXCode", #attributes id = id, #equivalent to "value" in SDMX 2.0 urn = urn, parentCode = parentCode, #elements label = codeLabels ) } rsdmx/R/SDMXDataStructures-methods.R0000644000176200001440000000740012654150565017057 0ustar liggesusers#' @name SDMXDataStructures #' @rdname SDMXDataStructures #' @aliases SDMXDataStructures,SDMXDataStructures-method #' #' @usage #' SDMXDataStructures(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDataStructures" #' #' @seealso \link{readSDMX} #' SDMXDataStructures <- function(xmlObj){ new("SDMXDataStructures", SDMX(xmlObj), datastructures = datastructures.SDMXDataStructures(xmlObj) ) } #get list of SDMXDataStructure #============================= datastructures.SDMXDataStructures <- function(xmlObj){ datastructures <- NULL sdmxVersion <- version.SDMXSchema(xmlObj) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlObj) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") dsXML <- NULL if(VERSION.21){ dsXML <- getNodeSet(xmlObj, "//mes:Structures/str:DataStructures/str:DataStructure", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) }else{ dsXML <- getNodeSet(xmlObj, "//mes:KeyFamilies/str:KeyFamily", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) } if(!is.null(dsXML)){ datastructures <- lapply(dsXML, function(x){ SDMXDataStructure(x)}) } return(datastructures) } #methods as.data.frame.SDMXDataStructures <- function(x, ...){ out <- do.call("rbind.fill", lapply(x@datastructures, function(ds){ names <- slot(ds, "Name") dsf.names <- as.data.frame(names, stringsAsFactors = FALSE) colnames(dsf.names) <- paste0("Name.", colnames(dsf.names)) desc <- slot(ds, "Description") dsf.desc <- NULL if(length(desc) > 0){ dsf.desc <- as.data.frame(desc, stringsAsFactors = FALSE) colnames(dsf.desc) <- paste0("Description.", colnames(dsf.desc)) } dsf <- data.frame( id = slot(ds, "id"), agencyID = slot(ds, "agencyID"), dsf.names, stringsAsFactors = FALSE) if(!is.null(dsf.desc)){ dsf <- cbind(dsf, dsf.desc, stringsASFactors = FALSE) } dsf <- cbind(dsf, version = slot(ds, "version"), uri = slot(ds, "uri"), urn = slot(ds, "urn"), isExternalReference = slot(ds, "isExternalReference"), isFinal = slot(ds, "isFinal"), validFrom = slot(ds, "validFrom"), validTo = slot(ds, "validTo"), stringsAsFactors = FALSE ) return(dsf) }) ) return(out) } setAs("SDMXDataStructures", "data.frame", function(from) as.data.frame.SDMXDataStructures(from));rsdmx/R/SDMXCodelist-methods.R0000644000176200001440000001073012654150565015650 0ustar liggesusers#' @name SDMXCodelist #' @rdname SDMXCodelist #' @aliases SDMXCodelist,SDMXCodelist-method #' #' @usage #' SDMXCodelist(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXCodelist" #' #' @seealso \link{readSDMX} #' SDMXCodelist <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #attributes #========= id = xmlGetAttr(xmlObj, "id") if(is.null(id)) id <- as.character(NA) agencyId = xmlGetAttr(xmlObj, "agencyID") if(is.null(agencyId)) agencyId <- as.character(NA) version = xmlGetAttr(xmlObj, "version") if(is.null(version)) version <- as.character(NA) uri = xmlGetAttr(xmlObj, "uri") if(is.null(uri)) uri <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) isExternalReference = xmlGetAttr(xmlObj, "isExternalReference") if(is.null(isExternalReference)){ isExternalReference <- NA }else{ isExternalReference <- as.logical(isExternalReference) } isFinal = xmlGetAttr(xmlObj, "isFinal") if(is.null(isFinal)){ isFinal <- NA }else{ isFinal <- as.logical(isFinal) } validFrom = xmlGetAttr(xmlObj,"validFrom") if(is.null(validFrom)) validFrom <- as.character(NA) validTo = xmlGetAttr(xmlObj, "validTo") if(is.null(validTo)) validTo <- as.character(NA) #elements #======== #name (multi-languages) codelistNamesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") codelistNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:Codelist/com:Name", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ codelistNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:CodeList/str:Name", namespaces = c(str = as.character(strNs))) } codelistNames <- NULL if(length(codelistNamesXML) > 0){ codelistNames <- new.env() sapply(codelistNamesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") codelistNames[[lang]] <- xmlValue(x) }) codelistNames <- as.list(codelistNames) } #description (multi-languages) codelistDesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") codelistDesXML <- getNodeSet(xmlDoc(xmlObj), "//str:Codelist/com:Description", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ codelistDesXML <- getNodeSet(xmlDoc(xmlObj), "//str:CodeList/str:Description", namespaces = c(str = as.character(strNs))) } codelistDescriptions <- list() if(length(codelistDesXML) > 0){ codelistDescriptions <- new.env() sapply(codelistDesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") codelistDescriptions[[lang]] <- xmlValue(x) }) codelistDescriptions <- as.list(codelistDescriptions) } #concepts codesXML <- NULL if(VERSION.21){ codesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:Codelist/ns:Code", namespaces = strNs) }else{ codesXML <- getNodeSet(xmlDoc(xmlObj), "//ns:CodeList/ns:Code", namespaces = strNs) } codes <- list() if(length(codesXML) > 0){ codes <- lapply(codesXML, function(x){ SDMXCode(x)}) } #instantiate the object obj<- new("SDMXCodelist", #attributes id = id, agencyID = agencyId, version = version, uri = uri, urn = urn, isExternalReference = isExternalReference, isFinal = isFinal, validFrom = validFrom, validTo = validTo, #elements, Name = codelistNames, Description = codelistDescriptions, Code = codes ) } rsdmx/R/Class-SDMXFooterMessage.R0000644000176200001440000000346012654150565016251 0ustar liggesusers#' @name SDMXFooterMessage #' @docType class #' @aliases SDMXFooterMessage-class #' @title Class "SDMXFooterMessage" #' @description A basic class to handle a footer message of a SDMX-ML document #' #' @slot code Object of class "character" giving the status code #' @slot severity Object of class "character" giving the severity of the message #' @slot messages Object of class "list" giving the list of messages #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document #' #' @note #' This class is especially useful for SDMX 2.1 compliant documents. Footer #' messages are not supported in SDMX 2.0 standard format. #' #' According to the SDMX 2.1 standard, the message severity takes one of the #' following values: "Error", "Warning",Information". Given the possible typos #' handled by data providers, rsdmx adopts a permissive strategy and does not #' validate the object according to such controlled terms. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXFooterMessage", representation( code = "character", severity = "character", messages = "list" ), prototype = list( code = "413", severity = "Information", messages = list("msg1", "msg2") ), validity = function(object){ # deactivated standard compliance (convenience because of data providers' typos) #if(!is.na(object@severity)){ # severityTypes <- c("Error", "Warning", "Information") # if(!(object@severity %in% severityTypes)) return(FALSE); #} return(TRUE); } )rsdmx/R/SDMXGenericData-methods.R0000644000176200001440000001730412654150565016254 0ustar liggesusers#' @name SDMXGenericData #' @rdname SDMXGenericData #' @aliases SDMXGenericData,SDMXGenericData-method #' #' @usage #' SDMXGenericData(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXGenericData" #' #' @seealso \link{readSDMX} #' SDMXGenericData <- function(xmlObj){ new("SDMXGenericData", SDMX(xmlObj) ) } #methods as.data.frame.SDMXGenericData <- function(x, ...){ xmlObj <- x@xmlObj; dataset <- NULL schema <- slot(x,"schema") sdmxVersion <- slot(schema,"version") VERSION.21 <- sdmxVersion == "2.1" #namespace nsDefs.df <- getNamespaces(x) ns <- findNamespace(nsDefs.df, "generic") #series seriesXML <- getNodeSet(xmlObj, "//ns:Series", namespaces = ns) if(length(seriesXML) == 0){ seriesXML <- getNodeSet(xmlObj, "//Series") } seriesNb <- length(seriesXML) if(seriesNb == 0) return(NULL); conceptId <- "concept" if(VERSION.21) conceptId <- "id" #serie keys keysXML <- getNodeSet(xmlDoc(getNodeSet(xmlObj, "//ns:SeriesKey", namespaces = ns)[[1]]), "//ns:Value", namespaces = ns) keysNames <- unique(sapply(keysXML, function(x) xmlGetAttr(x, conceptId))) #serie attributes serieAttrsNames <- NULL serieAttrsXML <- getNodeSet(xmlObj, "//ns:Series/ns:Attributes/ns:Value", namespaces = ns) if(length(serieAttrsXML) > 0){ serieAttrsNames <- unique(sapply(serieAttrsXML, function(x){ xmlGetAttr(x, conceptId) })) } #serie observation attributes obsAttrsNames <- NULL obsAttrsXML <- getNodeSet(xmlObj, "//ns:Obs/ns:Attributes/ns:Value", namespaces = ns) if(length(obsAttrsXML) > 0){ obsAttrsNames <- unique(sapply(obsAttrsXML,function(x){ xmlGetAttr(x, conceptId) })) } #output structure serieNames <- c(keysNames, "Time", "ObsValue") if(!is.null(obsAttrsNames)) serieNames <- c(serieNames, obsAttrsNames) if(!is.null(serieAttrsNames)) serieNames <- c(serieNames, serieAttrsNames) #obs parser function parseObs <- function(obs){ obsXML <- xmlDoc(obs) #time timeElement <- "Time" if(VERSION.21) timeElement <- "ObsDimension" obsTimeXML <- getNodeSet(obsXML, paste("//ns:",timeElement,sep=""), namespaces=ns)[[1]] obsTime <- NA if(!VERSION.21){ obsTime <- xmlValue(obsTimeXML) } else { obsTime <- xmlGetAttr(obsTimeXML,"value") } obsTime <- as.data.frame(obsTime) #value obsValue <- NA obsValuesXML <- getNodeSet(obsXML, "//ns:ObsValue", namespaces = ns) if(length(obsValuesXML) > 0){ obsValueXML <- obsValuesXML[[1]] obsValue <- as.numeric(xmlGetAttr(obsValueXML, "value")) } obsValue <- as.data.frame(obsValue) #attributes obsAttrs.df <- NULL if(!is.null(obsAttrsNames)){ obsAttrsXML <- getNodeSet(obsXML, "//ns:Attributes/ns:Value", namespaces = ns) if(length(obsAttrsXML) > 0){ obsAttrsValues <- sapply(obsAttrsXML, function(x){ as.character(xmlGetAttr(x, "value")) }) obsAttrsNames <- sapply(obsAttrsXML, function(x){ as.character(xmlGetAttr(x, conceptId)) }) obsAttrs.df <- structure(obsAttrsValues, .Names = obsAttrsNames) obsAttrs.df <- as.data.frame(lapply(obsAttrs.df, as.character), stringsAsFactors=FALSE) if(any(obsAttrs.df == "NA")){ obsAttrs.df[obsAttrs.df == "NA"] <- NA } if(!is.na(obsAttrs.df) && any(obsAttrs.df == "NULL")){ obsAttrs.df[obsAttrs.df == "NULL"] <- NA } } } #output obsR <- cbind(obsTime, obsValue) if(!is.null(obsAttrs.df)) obsR <- cbind(obsR, obsAttrs.df) return(obsR) } #function to parse a Serie parseSerie <- function(x){ # Single serie XMLInternalNode converted into a XMLInternalDocument serieXML <- xmlDoc(x) #parseobs obssXML <- getNodeSet(serieXML, "//ns:Series/ns:Obs", namespaces = ns) #apply obsParser obsdf <- NULL if(length(obssXML) > 0){ obsdf <- do.call("rbind.fill",lapply(obssXML, function(x) parseObs(x))) } #Key values #SeriesKey (concept attributes/values) are duplicated according to the #number of Time observations keyValuesXML <- getNodeSet(serieXML, "//ns:SeriesKey/ns:Value", namespaces = ns) keyValues <- sapply(keyValuesXML, function(x){ as.character(xmlGetAttr(x, "value")) }) keyNames <- sapply(keyValuesXML, function(x){ as.character(xmlGetAttr(x, conceptId)) }) keydf <- structure(keyValues, .Names = keyNames) keydf <- as.data.frame(lapply(keydf, as.character), stringsAsFactors=FALSE) if(!is.null(obsdf)){ keydf <- keydf[rep(row.names(keydf), nrow(obsdf)),] if(class(keydf) == "data.frame"){ row.names(keydf) <- 1:nrow(obsdf) colnames(keydf) <- keyNames } } #serie attributes attrs.df <- NULL serieAttrsXML <- getNodeSet(serieXML, "//ns:Series/ns:Attributes/ns:Value", namespaces = ns) if(!is.null(serieAttrsXML)){ if(length(serieAttrsXML) > 0){ attrsValues <- sapply(serieAttrsXML, function(x){ as.character(xmlGetAttr(x, "value")) }) attrsNames <- sapply(serieAttrsXML, function(x){ as.character(xmlGetAttr(x, conceptId)) }) attrs.df <- structure(attrsValues, .Names = attrsNames) attrs.df <- as.data.frame(lapply(attrs.df, as.character), stringsAsFactors=FALSE) if(!is.null(obsdf)){ attrs.df <- attrs.df[rep(row.names(attrs.df), nrow(obsdf)),] if(is(attrs.df, "data.frame")){ row.names(attrs.df) <- 1:nrow(obsdf) colnames(attrs.df) <- attrsNames } } } } #single Serie as DataFrame serie <- keydf if(!is.null(attrs.df)) serie <- cbind(serie, attrs.df) if(!is.null(obsdf)) serie <- cbind(serie, obsdf) #convert factor columns if("obsTime" %in% colnames(serie)){ serie[,"obsTime"] <- as.character(serie[,"obsTime"]) } if(!is.null(obsAttrsNames) & !is.null(obsdf)){ for(i in 1:length(colnames(obsdf))){ serie[,colnames(obsdf)[i]] <- as.character(serie[,colnames(obsdf)[i]]) } } return(serie) } #converting SDMX series to a DataFrame R object dataset <- do.call("rbind.fill", lapply(seriesXML, function(x){ serie <- parseSerie(x) })) dataset$obsValue <- as.numeric(dataset$obsValue) if(any(as.character(dataset$obsValue) == "NaN", na.rm = TRUE)){ dataset[as.character(dataset$obsValue) == "NaN",]$obsValue <- NA } if(!is.null(dataset)) row.names(dataset) <- 1:nrow(dataset) # output return(dataset) } setAs("SDMXGenericData", "data.frame", function(from) as.data.frame.SDMXGenericData(from)); rsdmx/R/SDMXStructureType-methods.R0000644000176200001440000000525012654150565016745 0ustar liggesusers#' @name SDMXStructureType #' @rdname SDMXStructureType #' @aliases SDMXStructureType,SDMXStructureType-method #' #' @usage #' SDMXStructureType(xmlObj, resource) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @param resource object of class "character" giving the REST resource to be #' queried (required to distinguish between dataflows and datastructures in #' SDMX 2.0) #' @return an object of class "SDMXStructureType" #' #' @seealso \link{readSDMX} #' SDMXStructureType <- function(xmlObj, resource){ new("SDMXStructureType", SDMXType(xmlObj), subtype = type.SDMXStructureType(xmlObj, resource)); } type.SDMXStructureType <- function(xmlObj, resource){ sdmxVersion <- version.SDMXSchema(xmlObj) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlObj) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") if(VERSION.21){ flowXML <- getNodeSet(xmlObj, "//ns:DataFlows", namespaces = strNs) dsXML <- getNodeSet(xmlObj, "//ns:DataStructures", namespaces = strNs) ccXML <- getNodeSet(xmlObj, "//ns:Concepts", namespaces = strNs) clXML <- getNodeSet(xmlObj, "//ns:Codelists", namespaces = strNs) if(all(c(length(dsXML)>0,length(ccXML)>0,length(clXML)>0))){ return("DataStructureDefinitionsType") }else{ #others structuresXML <- getNodeSet(xmlObj, "//ns:Structures", namespaces = messageNs) strType <- paste(xmlName(xmlChildren(structuresXML[[1]])[[1]]), "Type", sep="") return(strType) } }else{ #TODO flowXML dsXML <- getNodeSet(xmlObj, "//ns:KeyFamilies", namespaces = messageNs) ccXML <- getNodeSet(xmlObj, "//ns:Concepts", namespaces = messageNs) clXML <- getNodeSet(xmlObj, "//ns:CodeLists", namespaces = messageNs) if(all(c(length(dsXML)>0, length(ccXML)>0, length(clXML)>0))){ #DSD return("DataStructureDefinitionsType") }else{ #others if(length(ccXML)>0) return("ConceptsType") if(length(clXML)>0) return("CodelistsType") if(length(dsXML)>0){ strType <- switch(resource, "dataflow" = "DataflowsType", "datastructure" = "DataStructuresType", NULL = "DataStructuresType") return(strType) } } } return(NULL) } #generics if (!isGeneric("getStructureType")) setGeneric("getStructureType", function(obj) standardGeneric("getStructureType")); #methods setMethod(f = "getStructureType", signature = "SDMXStructureType", function(obj){ return(obj@subtype) }) rsdmx/R/SDMXDataFlows-methods.R0000644000176200001440000000743512654150565015776 0ustar liggesusers#' @name SDMXDataFlows #' @rdname SDMXDataFlows #' @aliases SDMXDataFlows,SDMXDataFlows-method #' #' @usage #' SDMXDataFlows(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDataFlows" #' #' @seealso \link{readSDMX} #' SDMXDataFlows <- function(xmlObj){ new("SDMXDataFlows", SDMX(xmlObj), dataflows = dataflows.SDMXDataFlows(xmlObj) ) } #get list of SDMXDataFlow #============================= dataflows.SDMXDataFlows <- function(xmlObj){ dataflows <- NULL sdmxVersion <- version.SDMXSchema(xmlObj) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlObj) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") dfXML <- NULL if(VERSION.21){ dfXML <- getNodeSet(xmlObj, "//mes:Structures/str:Dataflows/str:Dataflow", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) }else{ dfXML <- getNodeSet(xmlObj, "//mes:KeyFamilies/str:KeyFamily", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) } if(!is.null(dfXML)){ dataflows <- lapply(dfXML, function(x){ SDMXDataFlow(x)}) } return(dataflows) } #methods as.data.frame.SDMXDataFlows <- function(x, ...){ out <- do.call("rbind.fill", lapply(x@dataflows, function(dataflow){ names <- slot(dataflow, "Name") dataflow.names <- as.data.frame(names, stringsAsFactors = FALSE) colnames(dataflow.names) <- paste0("Name.", colnames(dataflow.names)) desc <- slot(dataflow, "Description") dataflow.desc <- NULL if(length(desc) > 0){ dataflow.desc <- as.data.frame(desc, stringsAsFactors = FALSE) colnames(datflow.desc) <- paste0("Description.", colnames(dataflow.desc)) } df <- data.frame( id = slot(dataflow, "id"), agencyID = slot(dataflow, "agencyID"), dataflow.names, stringsAsFactors = FALSE) if(!is.null(dataflow.desc)){ df <- cbind(df, dataflow.desc, stringsAsFactors = FALSE) } df <- cbind(df, version = slot(dataflow, "version"), uri = slot(dataflow, "uri"), urn = slot(dataflow, "urn"), isExternalReference = slot(dataflow, "isExternalReference"), isFinal = slot(dataflow, "isFinal"), validFrom = slot(dataflow, "validFrom"), validTo = slot(dataflow, "validTo"), dsdRef = slot(dataflow, "dsdRef"), stringsAsFactors = FALSE ) return(df) }) ) return(out) } setAs("SDMXDataFlows", "data.frame", function(from) as.data.frame.SDMXDataFlows(from));rsdmx/R/Class-SDMXFooter.R0000644000176200001440000000237212654150565014745 0ustar liggesusers#' @name SDMXFooter #' @docType class #' @aliases SDMXFooter-class #' @title Class "SDMXFooter" #' @description A basic class to handle the footer of a SDMX-ML document #' #' @slot messages Object of class "SDMXFooterMessage" giving the list of messages #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @note #' This class is especially useful for SDMX 2.1 compliant documents. Footer #' messages are not supported in SDMX 2.0standard format. In this case, the footer #' will return an empty message list(). #' #' According to the SDMX 2.1 standard, the message severity takes one of the #' following values: "Error", "Warning","Information". Given the possible typos #' handled by data providers, rsdmx adopts a permissive strategy and does not #' validate the object according to such controlled terms. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXFooter", representation( messages = "list" ), prototype = list( messages = list() ), validity = function(object){ return(TRUE); } )rsdmx/R/Class-SDMXCompactData.R0000644000176200001440000000076612654150565015674 0ustar liggesusers#' @name SDMXCompactData #' @docType class #' @aliases SDMXCompactData-class #' #' @title Class "SDMXCompactData" #' @description A basic class to handle a SDMX-ML compact data set #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXCompactData", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXFooterMessage-methods.R0000644000176200001440000000170412654150565016646 0ustar liggesusers#' @name SDMXFooterMessage #' @rdname SDMXFooterMessage #' @aliases SDMXFooterMessage,SDMXFooterMessage-method #' #' @usage #' SDMXFooterMessage(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXFooterMessage" #' #' @seealso \link{SDMXFooter} \link{readSDMX} SDMXFooterMessage <- function(xmlObj){ #code code <- xmlGetAttr(xmlObj,"code") if(is.null(code)) code <- as.character(NA) #severity severity <- xmlGetAttr(xmlObj, "severity") if(is.null(severity)) severity <- as.character(NA) #messages messages <- list() messagesXML <- xmlChildren(xmlObj) if(length(messagesXML) > 0){ messages <- unname(lapply(messagesXML, xmlValue)) } #SDMXFooterMessage object obj <- new("SDMXFooterMessage", code = code, severity = severity, messages = messages); return(obj); } rsdmx/R/SDMXFooter-methods.R0000644000176200001440000000150412654150565015337 0ustar liggesusers#' @name SDMXFooter #' @rdname SDMXFooter #' @aliases SDMXFooter,SDMXFooter-method #' #' @usage #' SDMXFooter(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXFooter" #' #' @seealso \link{readSDMX} SDMXFooter <- function(xmlObj){ messageList = list() #check presence of footer nsDefs.df <- namespaces.SDMX(xmlObj) ns <- findNamespace(nsDefs.df, "footer") if(length(ns) > 0){ messageListXML <- getNodeSet(xmlObj, "//footer:Message", namespaces = c(footer = as.character(ns))) messageList <- lapply(messageListXML, SDMXFooterMessage) } #SDMXFooter object obj <- new("SDMXFooter", messages = messageList); return(obj); } rsdmx/R/Class-SDMXDataStructure.R0000644000176200001440000000606612654150565016305 0ustar liggesusers#' @name SDMXDataStructure #' @docType class #' @aliases SDMXDataStructure-class #' #' @title Class "SDMXDataStructure" #' @description A basic class to handle a SDMX DataStructure (or KeyFamily) #' #' @slot id Object of class "character" giving the ID (required) #' @slot agencyID Object of class "character" giving the AgencyID #' @slot version Object of class "character" giving the version #' @slot uri Object of class "character" giving the uri #' @slot urn Object of class "character" giving the urn #' @slot isExternalReference Object of class "logical" indicating if the datastructure / keyfamily is an external reference #' @slot isFinal Object of class "logical" indicating if the datastructure / keyfamily is final #' @slot validFrom Object of class "character" indicating the start validity period #' @slot validTo Object of class "character" indicating the end validity period #' @slot Name Object of class "list" giving the codelist (by language) - required #' @slot Description Object of class "list" giving the codelist description (by language) #' @slot Components Object of class "SDMXComponents" (see \link{SDMXComponents}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXDataStructure", representation( #attributes id = "character", #required agencyID = "character", #optional version = "character", #optional uri = "character", #optional urn = "character", #optional isExternalReference = "logical", #optional isFinal = "logical", #optional validFrom = "character", #optional validTo = "character", #optional #elements Name = "list", #at least one Description = "list", #optional Components = "SDMXComponents_OR_NULL" #optional ), prototype = list( #attributes id = "KEYFAMILY_ID", agencyID = "AGENCY_ID", version = "1.0", uri = as.character(NA), urn = as.character(NA), isExternalReference = FALSE, isFinal = FALSE, validFrom = as.character(NA), validTo = as.character(NA), #elements Name = list( en = "datastructure/keyfamily name", fr = "nom du datastrucure/keyfamily" ), Description = list( en = "datastructure/keyfamily description", fr = "description du datastructure/keyfamily" ), Components = new("SDMXComponents") ), validity = function(object){ #eventual validation rules if(is.na(object@id)) return(FALSE) if(length(object@Name) == 0) return(FALSE) return(TRUE); } )rsdmx/R/Class-SDMXRequestBuilder.R0000644000176200001440000000276012654150565016447 0ustar liggesusers#' @name SDMXRequestBuilder #' @docType class #' @aliases SDMXRequestBuilder-class #' #' @title Class "SDMXRequestBuilder" #' @description A basic class to handle a SDMX service request builder #' #' @slot regUrl an object of class "character" giving the base Url of the SDMX service registry #' @slot repoUrl an object of class "character" giving the base Url of the SDMX service repository #' @slot handler an object of class "function" that will be in charge of build a web request. #' @slot compliant an object of class "logical" indicating if the request builder is somehow compliant with a service specification #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXRequestBuilder", representation( regUrl = "character", repoUrl = "character", handler = "function", compliant = "logical" ), prototype = list( regUrl = "http://www.myorg.org/sdmx/registry", repoUrl = "http://www.myorg.org/sdmx/repository", handler = function(regUrl, repUrl, agencyId){ paste(regUrl, agencyId,sep="/") }, compliant = TRUE ), validity = function(object){ return(TRUE); } ) rsdmx/R/readSDMX.R0000644000176200001440000002612112654150565013355 0ustar liggesusers#' @name readSDMX #' @aliases readSDMX #' @title readSDMX #' @description \code{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) #' #' @param file path to SDMX-ML document that needs to be parsed #' @param 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 \code{readSDMX} is used with helpers (based on the #' embedded list of \code{SDMXServiceProvider}) #' @param provider an object of class "SDMXServiceProvider". If specified, #' \code{file} and \code{isURL} arguments will be ignored. #' @param agencyId an object of class "character" representing a provider id. #' It has to be match a default provider as listed in\code{getSDMXServiceProviders()} #' @param 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. #' @param resourceId an object of class "character" giving a SDMX service resource #' Id, e.g. the id of a data structure #' @param version an object of class "character" giving a SDMX resource version, #' e.g. the version of a dataflow. #' @param flowRef an object of class "character" giving the SDMX flow ref id. Recognized #' if valid provider or provide id has been specified as argument. #' @param 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 \code{key.mode} is equal to \code{"R"} (default value), filter has to be an object #' of class "list" representing the filters to apply to the dataset, otherwise the filter #' will be a string. #' @param key.mode an object of class "character" indicating if the \code{key} has to be provided #' as an R object, ie a object of class "list" representing the filter(s) to apply. Default #' value is \code{"R"}. Alternative value is \code{"SDMX"} #' @param 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. #' @param 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. #' #' @return an object of class "SDMX" #' #' @examples #' # SDMX datasets #' #-------------- #' \dontrun{ #' # 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**) #' } #' #' \donttest{ #' # 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 #' #------------------------------- #' \donttest{ #' # 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 #' #--------------- #' \donttest{ #' # 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) #' #----------------------------------- #' \donttest{ #' # 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**) #' } #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' readSDMX <- function(file = NULL, isURL = TRUE, provider = NULL, agencyId = NULL, resource = NULL, resourceId = NULL, version = NULL, flowRef = NULL, key = NULL, key.mode = "R", start = NULL, end = NULL) { if(!(key.mode %in% c("R", "SDMX"))){ stop("Invalid value for key.mode argument. Accepted values are 'R', 'SDMX' ") } #check from arguments if request has to be performed buildRequest <- FALSE if(!is.null(provider)){ if(class(provider) != "SDMXServiceProvider"){ stop("Provider should be an instance of 'SDMXServiceProvider'") } buildRequest <- TRUE } if(!is.null(agencyId)){ provider <- findSDMXServiceProvider(agencyId) if(is.null(provider)){ stop("No provider with identifier ", agencyId) } buildRequest <- TRUE } #proceed with the request build if(buildRequest){ if(key.mode == "R" && !missing(key) && !is.null(key)){ key <- paste(sapply(key, paste, collapse = "+"), collapse=".") } if(is.null(resource)) stop("SDMX service resource cannot be null") file <- provider@builder@handler( regUrl = provider@builder@regUrl, repoUrl = provider@builder@repoUrl, agencyId = provider@agencyId, resource = resource, resourceId = resourceId, version = version, flowRef = flowRef, key = key, start = start, end = end, compliant = provider@builder@compliant) message(file) } #call readSDMX original if(is.null(file)) stop("Empty file argument") if(buildRequest) isURL = TRUE #load data status <- 0 if(isURL == FALSE){ if(!file.exists(file)) stop("File ", file, "not found\n") xmlObj <- xmlTreeParse(file, useInternalNodes = TRUE) status <- 1 }else{ rsdmxAgent <- paste("rsdmx/",as.character(packageVersion("rsdmx")),sep="") content <- getURL(file, httpheader = list('User-Agent' = rsdmxAgent), ssl.verifypeer = FALSE, .encoding = "UTF-8") status <- tryCatch({ if(attr(regexpr("", content), "match.length") == -1){ #check the presence of a BOM BOM <- "\ufeff" if(attr(regexpr(BOM, content), "match.length") != - 1){ content <- gsub(BOM, "", content) } xmlObj <- xmlTreeParse(content, useInternalNodes = TRUE) status <- 1 }else{ stop("The SDMX web-request failed. Please retry") } },error = function(err){ print(err) status <<- 0 return(status) }) } #internal function for SDMX Structure-based document getSDMXStructureObject <- function(xmlObj, resource){ strTypeObj <- SDMXStructureType(xmlObj, resource) strType <- getStructureType(strTypeObj) strObj <- switch(strType, "DataflowsType" = SDMXDataFlows(xmlObj), "ConceptsType" = SDMXConcepts(xmlObj), "CodelistsType" = SDMXCodelists(xmlObj), "DataStructuresType" = SDMXDataStructures(xmlObj), "DataStructureDefinitionsType" = SDMXDataStructureDefinition(xmlObj), NULL ) return(strObj) } #encapsulate in S4 object obj <- NULL if(status){ #convenience for SDMX documents embedded in SOAP XML responses if(isSoapRequestEnvelope(xmlObj)){ xmlObj <- getSoapRequestResult(xmlObj) } type <- SDMXType(xmlObj)@type obj <- switch(type, "StructureType" = getSDMXStructureObject(xmlObj, resource), "GenericDataType" = SDMXGenericData(xmlObj), "CompactDataType" = SDMXCompactData(xmlObj), "UtilityDataType" = SDMXUtilityData(xmlObj), "StructureSpecificDataType" = SDMXStructureSpecificData(xmlObj), "CrossSectionalDataType" = SDMXCrossSectionalData(xmlObj), "MessageGroupType" = SDMXMessageGroup(xmlObj), NULL ) if(is.null(obj)){ if(type == "StructureType"){ strTypeObj <- SDMXStructureType(xmlObj, resource) type <- getStructureType(strTypeObj) } stop(paste("Unsupported SDMX Type '",type,"'",sep="")) }else{ #handling footer messages footer <- slot(obj, "footer") footer.msg <- slot(footer, "messages") if(length(footer.msg) > 0){ invisible( lapply(footer.msg, function(x){ code <- slot(x,"code") severity <- slot(x,"severity") lapply(slot(x,"messages"), function(msg){ warning(paste(severity," (Code ",code,"): ",msg,sep=""), call. = FALSE) } ) }) ) } } } return(obj); } rsdmx/R/Class-SDMXCrossSectionalData.R0000644000176200001440000000103012654150565017222 0ustar liggesusers#' @name SDMXCrossSectionalData #' @docType class #' @aliases SDMXCrossSectionalData-class #' #' @title Class "SDMXCrossSectionalData" #' @description A basic class to handle a SDMX-ML cross sectional data set #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXCrossSectionalData", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXServiceProvider-methods.R0000644000176200001440000002423212654150565017217 0ustar liggesusers#' @name SDMXServiceProvider #' @rdname SDMXServiceProvider #' @aliases SDMXServiceProvider,SDMXServiceProvider-method #' #' @usage #' SDMXServiceProvider(agencyId, name, scale, country, builder) #' #' @param agencyId an object of class "character" giving the a provider identifier #' @param name an object of class "character" giving the name of the provider #' @param scale an object of class "character" giving the scale of the datasource, #' either "international" or "national". Default value is "international". #' @param country an object of class "character" giving the ISO 3-alpha code of #' the country (if scale is "national"). Default value is \code{NA} #' @param builder an object of class "SDMXRequestBuilder" that will performs the #' web request building for this specific provider #' @return an object of class "SDMXServiceProvider" #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' #' @examples #' #let's create a SDMXRESTRequestBuilder #' #(assuming that "My Organization" implements SDMX REST web-services) #' myBuilder <- SDMXRESTRequestBuilder(regUrl = "http://www.myorg.org/registry", #' repoUrl = "http://www.myorg.org/repository", #' compliant = TRUE) #' #' #create a SDMXServiceProvider #' provider <- SDMXServiceProvider(agencyId = "MYORG", name = "My Organization", #' builder = myBuilder) #' SDMXServiceProvider <- function(agencyId, name, scale = "international", country = as.character(NA), builder) { new("SDMXServiceProvider", agencyId = agencyId, name = name, scale = scale, country = country, builder = builder); } #other non-S4 methods #==================== #' @name setSDMXServiceProviders #' @aliases setSDMXServiceProviders #' @title setSDMXServiceProviders #' #' @description function used internally by \pkg{rsdmx}, when loading the package, #' to set the list of \link{SDMXServiceProvider} known by \pkg{rsdmx} #' (hence known by \link{readSDMX} to query data/metadata in an easier #' way). For internal use only (this function does not provide any #' value for the end user, but it is here documented for transparency, #' and to explain how the package works.) #' #' @usage #' setSDMXServiceProviders() #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' #' @seealso \link{getSDMXServiceProviders} \link{addSDMXServiceProvider} #' \link{findSDMXServiceProvider} \link{readSDMX} #' setSDMXServiceProviders <- function(){ # nocov start listOfProviders <- list( #international data providers #---------------------------- #ECB SDMXServiceProvider( agencyId = "ECB", name = "European Central Bank", builder = SDMXRESTRequestBuilder( regUrl = "https://sdw-wsrest.ecb.europa.eu/service", repoUrl = "https://sdw-wsrest.ecb.europa.eu/service", compliant = TRUE) ), #EUROSTAT SDMXServiceProvider( agencyId = "ESTAT", name = "Eurostat (Statistical office of the European Union)", builder = SDMXRESTRequestBuilder( regUrl = "http://ec.europa.eu/eurostat/SDMX/diss-web/rest", repoUrl = "http://ec.europa.eu/eurostat/SDMX/diss-web/rest", compliant = TRUE) ), #OECD SDMXServiceProvider( agencyId = "OECD", name = "Organisation for Economic Cooperation and Development ", builder = SDMXRESTRequestBuilder( regUrl = "http://stats.oecd.org/restsdmx/sdmx.ashx", repoUrl = "http://stats.oecd.org/restsdmx/sdmx.ashx", compliant = FALSE) ), #UN-FAO SDMXServiceProvider( agencyId = "FAO", name = "Food and Agriculture Organization of the United Nations", builder = SDMXRESTRequestBuilder( regUrl = "http://data.fao.org/sdmx/registry", repoUrl = "http://data.fao.org/sdmx/repository", compliant = TRUE, unsupportedResources = list("dataflow")) ), #UN-ILO SDMXServiceProvider( agencyId = "ILO", name = "International Labour Organization of the United Nations", builder = SDMXRESTRequestBuilder( regUrl = "http://www.ilo.org/ilostat/sdmx/ws/rest", repoUrl = "http://www.ilo.org/ilostat/sdmx/ws/rest", compliant = TRUE, skipAgencyId = TRUE, unsupportedResources = list("dataflow")) ), #UIS (UNESCO) SDMXServiceProvider( agencyId = "UIS", name = "UNESCO Institute of Statistics", builder = SDMXRESTRequestBuilder( regUrl = "http://data.uis.unesco.org/RestSDMX/sdmx.ashx", repoUrl = "http://data.uis.unesco.org/RestSDMX/sdmx.ashx", compliant = TRUE, unsupportedResources = list("dataflow")) ), #national data providers #----------------------- #ABS {Australia} SDMXServiceProvider( agencyId = "ABS", name = "Australian Bureau of Statistics", scale = "national", country = "AUS", builder = SDMXRESTRequestBuilder( regUrl = "http://stat.abs.gov.au/restsdmx/sdmx.ashx", repoUrl = "http://stat.abs.gov.au/restsdmx/sdmx.ashx", compliant = FALSE, forceAgencyId = TRUE, unsupportedResources = list("dataflow")) ), #NBB {Belgium} SDMXServiceProvider( agencyId = "NBB", name = "National Bank of Belgium", scale = "national", country = "BEL", builder = SDMXRESTRequestBuilder( regUrl = "http://stat.nbb.be/RestSDMX/sdmx.ashx", repoUrl = "http://stat.nbb.be/RestSDMX/sdmx.ashx", compliant = FALSE, unsupportedResources = list("dataflow")) ), #INSEE {France} SDMXServiceProvider( agencyId = "INSEE", name = "Institut national de la statistique et des \u00e9tudes \u00e9conomiques", scale = "national", country = "FRA", builder = SDMXRESTRequestBuilder( regUrl = "http://www.bdm.insee.fr/series/sdmx", repoUrl = "http://www.bdm.insee.fr/series/sdmx", compliant = TRUE) ) ) .rsdmx.options$providers <- new("SDMXServiceProviders", providers = listOfProviders) } # nocov end #' @name addSDMXServiceProvider #' @aliases addSDMXServiceProvider #' @title addSDMXServiceProvider #' @description function that allows configuring a new \link{SDMXServiceProvider} #' as part of the list of providers known by \pkg{rsdmx}, hence by #' \link{readSDMX} #' #' @usage #' addSDMXServiceProvider(provider) #' #' @param provider an object of class "SDMXServiceProvider" #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' #' @examples #' #create a provider #' myBuilder <- SDMXRESTRequestBuilder(regUrl = "http://www.myorg.org/registry", #' repoUrl = "http://www.myorg.org/repository", #' compliant = TRUE) #' myProvider <- SDMXServiceProvider( #' agencyId = "MYORG", name = "My Organization", #' builder = myBuilder #' ) #' #' #add it #' addSDMXServiceProvider(myProvider) #' #' #check out the list of existing provider (only list the agency Ids) #' sapply(slot(getSDMXServiceProviders(), "providers"), function(x){slot(x, "agencyId")}) #' #' @seealso \link{getSDMXServiceProviders} \link{findSDMXServiceProvider} #' \link{readSDMX} #' addSDMXServiceProvider <- function(provider){ .rsdmx.options$providers <- new("SDMXServiceProviders", providers = c(slot(.rsdmx.options$providers, "providers"), provider) ) } #' @name getSDMXServiceProviders #' @aliases getSDMXServiceProviders #' @title getSDMXServiceProviders #' @description function used to get the list of \link{SDMXServiceProvider} known #' by \pkg{rsdmx} (hence known by \link{readSDMX} to query data or #' metadata in an easier way). This function can be easily used to #' interrogate the list of known providers, and eventually consider #' adding one at runtime with \link{addSDMXServiceProvider} #' @usage #' getSDMXServiceProviders() #' #' @return an object of class "list" (of \link{SDMXServiceProvider}) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' #' @seealso \link{addSDMXServiceProvider} \link{findSDMXServiceProvider} #' \link{readSDMX} #' getSDMXServiceProviders <- function(){ out <- .rsdmx.options$providers return(out) } #' @name findSDMXServiceProvider #' @aliases findSDMXServiceProvider #' @title findSDMXServiceProvider #' #' @description function that allows searching by provider id in the list of #' known \link{SDMXServiceProvider}. This function can be used for #' interrogating the list of default providers known by \pkg{rsdmx}, #' and is used internally by \link{readSDMX} #' @usage #' findSDMXServiceProvider(agencyId) #' #' @param agencyId an object of class "character" representing a provider #' identifier #' @return an object of class "SDMXServiceProvider" (or NULL if no matching) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' #' @examples #' #find OECD provider #' oecd.provider <- findSDMXServiceProvider("OECD") #' #' @seealso \link{getSDMXServiceProviders} \link{addSDMXServiceProvider} #' \link{readSDMX} #' findSDMXServiceProvider <- function(agencyId){ res <- unlist(lapply(slot(getSDMXServiceProviders(),"providers"), function(x) {if(x@agencyId == agencyId){return(x)}})) if(!is.null(res) && length(res) > 0) res <- res[[1]] return(res) } rsdmx/R/Class-SDMXGenericData.R0000644000176200001440000000123712654150565015654 0ustar liggesusers#' @name SDMXGenericData #' @docType class #' @aliases SDMXGenericData-class #' #' @title Class "SDMXGenericData" #' @description A basic class to handle a SDMX-ML Generic data set #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXGenericData", contains = "SDMX", representation(), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXDataStructure-methods.R0000644000176200001440000001052512654150565016676 0ustar liggesusers#' @name SDMXDataStructure #' @rdname SDMXDataStructure #' @aliases SDMXDataStructure,SDMXDataStructure-method #' #' @usage #' SDMXDataStructure(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDataStructure" #' #' @seealso \link{readSDMX} #' SDMXDataStructure <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #attributes #========= id = xmlGetAttr(xmlObj, "id") if(is.null(id)) id <- as.character(NA) agencyId = xmlGetAttr(xmlObj, "agencyID") if(is.null(agencyId)) agencyId <- as.character(NA) version = xmlGetAttr(xmlObj, "version") if(is.null(version)) version <- as.character(NA) uri = xmlGetAttr(xmlObj, "uri") if(is.null(uri)) uri <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) isExternalReference = xmlGetAttr(xmlObj, "isExternalReference") if(is.null(isExternalReference)){ isExternalReference <- NA }else{ isExternalReference <- as.logical(isExternalReference) } isFinal = xmlGetAttr(xmlObj, "isFinal") if(is.null(isFinal)){ isFinal <- NA }else{ isFinal <- as.logical(isFinal) } validFrom = xmlGetAttr(xmlObj,"validFrom") if(is.null(validFrom)) validFrom <- as.character(NA) validTo = xmlGetAttr(xmlObj, "validTo") if(is.null(validTo)) validTo <- as.character(NA) #elements #======== #name (multi-languages) dsNamesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") dsNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:DataStructure/com:Name", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ dsNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:KeyFamily/str:Name", namespaces = c(str = as.character(strNs))) } dsNames <- NULL if(length(dsNamesXML) > 0){ dsNames <- new.env() sapply(dsNamesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") dsNames[[lang]] <- xmlValue(x) }) dsNames <- as.list(dsNames) } #description (multi-languages) dsDesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") dsDesXML <- getNodeSet(xmlDoc(xmlObj), "//str:DataStructure/com:Description", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ dsDesXML <- getNodeSet(xmlDoc(xmlObj), "//str:KeyFamily/str:Description", namespaces = c(str = as.character(strNs))) } dsDescriptions <- list() if(length(dsDesXML) > 0){ dsDescriptions <- new.env() sapply(dsDesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") dsDescriptions[[lang]] <- xmlValue(x) }) dsDescriptions <- as.list(dsDescriptions) } #Components compXML <- NULL if(VERSION.21){ compXML <- getNodeSet(xmlDoc(xmlObj), "//str:DataStructureComponents", namespaces = c(str = as.character(strNs))) }else{ compXML <- getNodeSet(xmlDoc(xmlObj), "//str:Components", namespaces = c(str = as.character(strNs))) } components <- NULL if(length(compXML) > 0) components <- SDMXComponents(xmlObj) #instantiate the object obj<- new("SDMXDataStructure", #attributes id = id, agencyID = agencyId, version = version, uri = uri, urn = urn, isExternalReference = isExternalReference, isFinal = isFinal, validFrom = validFrom, validTo = validTo, #elements, Name = dsNames, Description = dsDescriptions, Components = components ) } rsdmx/R/SDMXSchema-methods.R0000644000176200001440000000161412654150565015303 0ustar liggesusers#' @name SDMXSchema #' @rdname SDMXSchema #' @aliases SDMXSchema,SDMXSchema-method #' #' @usage #' SDMXSchema(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXSchema" #' #' @seealso \link{readSDMX} #' SDMXSchema <- function(xmlObj) { new("SDMXSchema", version = version.SDMXSchema(xmlObj)); } #default functions version.SDMXSchema <- function(xmlObj){ nsDefs.df <- namespaces.SDMX(xmlObj) ns.df <- nsDefs.df[ regexpr("http://www.sdmx.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == 1 & regexpr("http://www.w3.org", nsDefs.df$uri, "match.length", ignore.case = TRUE) == -1,] parsed <- strsplit(ns.df[1,]$uri,"/")[[1]]; schemaVersion <- gsub("_",".",substr(parsed[substr(parsed,0,1)=="v"],2,nchar(parsed,"w"))); return(schemaVersion); } rsdmx/R/SDMXUtilityData-methods.R0000644000176200001440000000120212654150565016331 0ustar liggesusers#' @name SDMXUtilityData #' @rdname SDMXUtilityData #' @aliases SDMXUtilityData,SDMXUtilityData-method #' #' @usage #' SDMXUtilityData(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXUtilityData" #' #' @seealso \link{readSDMX} #' SDMXUtilityData <- function(xmlObj){ new("SDMXUtilityData", SDMX(xmlObj) ) } #methods #======= as.data.frame.SDMXUtilityData <- function(x, ...){ return(as.data.frame.SDMXCompactData(x)) } setAs("SDMXUtilityData", "data.frame", function(from) as.data.frame.SDMXUtilityData(from)); rsdmx/R/SDMXStructureSpecificData-methods.R0000644000176200001440000000141212654150565020337 0ustar liggesusers#' @name SDMXStructureSpecificData #' @rdname SDMXStructureSpecificData #' @aliases SDMXStructureSpecificData,SDMXStructureSpecificData-method #' #' @usage #' SDMXStructureSpecificData(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXStructureSpecificData" #' #' @seealso \link{readSDMX} #' SDMXStructureSpecificData <- function(xmlObj){ new("SDMXStructureSpecificData", SDMX(xmlObj) ) } #methods #======= as.data.frame.SDMXStructureSpecificData <- function(x, ...){ return(as.data.frame.SDMXAllCompactData(x, "structurespecific")); } setAs("SDMXStructureSpecificData", "data.frame", function(from) as.data.frame.SDMXStructureSpecificData(from)); rsdmx/R/Class-SDMXConceptScheme.R0000644000176200001440000000601312654150565016223 0ustar liggesusers#' @name SDMXConceptScheme #' @docType class #' @aliases SDMXConceptScheme-class #' #' @title Class "SDMXConceptScheme" #' @description A basic class to handle a SDMX Concept scheme #' #' @slot id Object of class "character" giving the ID of the concept scheme (required) #' @slot agencyID Object of class "character" giving the AgencyID #' @slot version Object of class "character" giving the version #' @slot uri Object of class "character" giving the concept uri #' @slot urn Object of class "character" giving the concept urn #' @slot isExternalReference Object of class "logical" indicating if the concept scheme is an external reference #' @slot isFinal Object of class "logical" indicating if the concept scheme is final #' @slot validFrom Object of class "character" indicating the start validity period #' @slot validTo Object of class "character" indicating the end validity period #' @slot Name Object of class "list" giving the concept scheme name (by language) - required #' @slot Description Object of class "list" giving the concept scheme description (by language) #' @slot Concept Object of class "list" giving the list of "SDMXConcept" objects (see \link{SDMXConcept}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXConceptScheme", representation( #attributes id = "character", #required agencyID = "character", #optional version = "character", #optional uri = "character", #optional urn = "character", #optional isExternalReference = "logical", #optional isFinal = "logical", #optional validFrom = "character", #optional validTo = "character", #optional #elements Name = "list", #at least one Description = "list", #optional Concept = "list" #optional ), prototype = list( #attributes id = "CONCEPTSCHEME_ID", agencyID = "AGENCY_ID", version = "1.0", uri = as.character(NA), urn = as.character(NA), isExternalReference = FALSE, isFinal = FALSE, validFrom = as.character(NA), validTo = as.character(NA), #elements Name = list( en = "concept name", fr = "nom du concept" ), Description = list( en = "concept description", fr = "description du concept" ), Concept = list() ), validity = function(object){ #validation rules if(is.na(object@id)) return(FALSE) if(length(object@Name) == 0) return(FALSE) return(TRUE); } )rsdmx/R/Class-SDMXCodelist.R0000644000176200001440000000570512654150565015260 0ustar liggesusers#' @name SDMXCodelist #' @docType class #' @aliases SDMXCodelist-class #' #' @title Class "SDMXCodelist" #' @description A basic class to handle a SDMX Codelist #' #' @slot id Object of class "character" giving the ID of the codelist (required) #' @slot agencyID Object of class "character" giving the AgencyID #' @slot version Object of class "character" giving the version #' @slot uri Object of class "character" giving the codelist uri #' @slot urn Object of class "character" giving the codelist urn #' @slot isExternalReference Object of class "logical" indicating if the codelist is an external reference #' @slot isFinal Object of class "logical" indicating if the codelist is final #' @slot validFrom Object of class "character" indicating the start validity period #' @slot validTo Object of class "character" indicating the end validity period #' @slot Name Object of class "list" giving the codelist (by language) - required #' @slot Description Object of class "list" giving the codelist description (by language) #' @slot Code Object of class "list" giving the list of "SDMXCode" objects included in the codelist (see \link{SDMXCode}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Codelists, or DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXCodelist", representation( #attributes id = "character", #required agencyID = "character", #optional version = "character", #optional uri = "character", #optional urn = "character", #optional isExternalReference = "logical", #optional isFinal = "logical", #optional validFrom = "character", #optional validTo = "character", #optional #elements Name = "list", #at least one Description = "list", #optional Code = "list" #optional ), prototype = list( #attributes id = "CODELIST_ID", agencyID = "AGENCY_ID", version = "1.0", uri = as.character(NA), urn = as.character(NA), isExternalReference = FALSE, isFinal = FALSE, validFrom = as.character(NA), validTo = as.character(NA), #elements Name = list( en = "concept name", fr = "nom du concept" ), Description = list( en = "concept description", fr = "description du concept" ), Code = list() ), validity = function(object){ #eventual validation rules if(is.na(object@id)) return(FALSE) if(length(object@Name) == 0) return(FALSE) return(TRUE); } )rsdmx/R/Class-SDMXServiceProviders.R0000644000176200001440000000154412654150565017005 0ustar liggesusers#' @name SDMXServiceProviders #' @docType class #' @aliases SDMXServiceProviders-class #' #' @title Class "SDMXServiceProviders" #' @description A class to wrap a list of SDMX service providers #' #' @slot providers an object of class "list" (of \link{SDMXServiceProvider}) #' configured by default and/or at runtime in \pkg{rsdmx} #' #' @section Warning: #' this class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXServiceProviders", representation( providers = "list" ), prototype = list( providers = list() ), validity = function(object){ return(TRUE); } ) rsdmx/R/Class-SDMXDataStructures.R0000644000176200001440000000162312654150565016462 0ustar liggesusers#' @name SDMXDataStructures #' @docType class #' @aliases SDMXDataStructures-class #' #' @title Class "SDMXDataStructures" #' @description A basic class to handle a SDMX DataStructures (or KeyFamilies) #' #' @slot datastructures Object of class "list" giving the list of DataStructures, #' (see \link{SDMXDataStructure}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXDataStructures", contains = "SDMX", representation( datastructures = "list" ), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/SDMXConcepts-methods.R0000644000176200001440000000742212654150565015664 0ustar liggesusers#' @name SDMXConcepts #' @rdname SDMXConcepts #' @aliases SDMXConcepts,SDMXConcepts-method #' #' @usage #' SDMXConcepts(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXConcepts" #' #' @seealso \link{readSDMX} #' SDMXConcepts <- function(xmlObj){ new("SDMXConcepts", SDMX(xmlObj), concepts = concepts.SDMXConcepts(xmlObj), conceptSchemes = conceptSchemes.SDMXConcepts(xmlObj) ) } #get list of SDMXConcept (backward compatibility with SDMX 1.0) #======================= concepts.SDMXConcepts <- function(xmlObj){ concepts <- NULL sdmxVersion <- version.SDMXSchema(xmlObj) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlObj) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") conceptsXML <- NULL if(VERSION.21){ conceptsXML <- getNodeSet(xmlObj, "//mes:Structures/str:Concepts/str:Concept", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) }else{ conceptsXML <- getNodeSet(xmlObj, "//mes:Concepts/str:Concept", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) } if(!is.null(conceptsXML)){ concepts <- lapply(conceptsXML, function(x){ SDMXConcept(x)}) } return(concepts) } #get list of SDMXConceptScheme (from SDMX 2.0) #============================= conceptSchemes.SDMXConcepts <- function(xmlObj){ conceptSchemes <- NULL namespaces <- namespaces.SDMX(xmlObj) strNs <- findNamespace(namespaces, "structure") conceptSchemesXML <- getNodeSet(xmlObj, "//ns:ConceptScheme", namespaces = strNs) conceptSchemes <- lapply(conceptSchemesXML, function(x){ SDMXConceptScheme(x)}) return(conceptSchemes) } #as.data.frame #============= as.data.frame.SDMXConcepts <- function(x, ..., conceptSchemeId = NULL, ignore.empty.slots = TRUE){ xmlObj <- x@xmlObj; concepts <- NULL conceptsList <- NULL if(length(x@concepts) > 0){ conceptsList <- x@concepts }else if(length(x@conceptSchemes) > 0){ if(is.null(conceptSchemeId) & length(x@conceptSchemes) > 0){ warning("Using first conceptScheme referenced in SDMXConcepts object: \n Specify 'conceptSchemeId' argument for a specific conceptScheme") conceptScheme <- x@conceptSchemes[[1]] }else{ conceptScheme <- NULL for(i in 1:length(x@conceptSchemes)){ cs <- x@conceptSchemes[[i]] if(cs@id == conceptSchemeId) conceptScheme <- cs } } conceptsList <- conceptScheme@Concept } if(!is.null(conceptsList)){ concepts <- do.call("rbind.fill", lapply(conceptsList, function(concept){ as.data.frame(sapply(slotNames(concept), function(x){ obj <- slot(concept,x) if(all(is.na(obj))){ obj <- switch(class(obj), "character" = NA, "logical" = NA, "list" = structure(as.list(rep(NA,2)), .Names = names(conceptsList[[1]]@Name)) ) } return(obj) })) }) ) } if(ignore.empty.slots){ concepts <- concepts[,colSums(is.na(concepts)) 1){ if(is.null(codelistId)){ warning("Using first codelist referenced in SDMXCodelists object: \n Specify 'codelistId' argument for a specific codelist") codelist <- x@codelists[[1]] }else{ selectedCodelist <- NULL for(i in 1:length(x@codelists)){ cl <- x@codelists[[i]] if(cl@id == codelistId){ selectedCodelist <- cl } } codelist <- selectedCodelist } }else{ codelist <- x@codelists[[1]] } codesList <- codelist@Code if(!is.null(codesList)){ codes <- do.call("rbind.fill", lapply(codesList, function(code){ as.data.frame(sapply(slotNames(code), function(x){ obj <- slot(code,x) return(obj) })) }) ) } if(ignore.empty.slots){ codes <- codes[,colSums(is.na(codes)) 0){ hasAuthorityNS <- TRUE if(nrow(authorityNs) > 1){ warning("More than one target dataset namespace found!") authorityNs <- authorityNs[1L,] } } #parse Groups if(hasAuthorityNS){ groupsXML <- getNodeSet(xmlObj, "//ns:Group", namespaces = c(ns = authorityNs$uri)) if(length(groupsXML) == 0){ groupsXML <- getNodeSet(xmlObj, "//ns:Group", namespaces = ns) } }else{ if(length(ns) > 0){ groupsXML <- getNodeSet(xmlObj, "//ns:Group", namespaces = ns) }else{ if(nrow(nsDefs.df) > 0){ groupNs <- nsDefs.df[1,] groupsXML <- getNodeSet(xmlObj, "//nt:Group", c(nt = groupNs$uri)) }else{ stop("Unsupported CrossSectionalData parser for empty target XML namespace") } } } if(length(groupsXML) == 0){ groupsXML <- getNodeSet(xmlObj, "//Group") } groupsNb <- length(groupsXML) if(groupsNb == 0) return(NULL); #function to parse a Section parseSection <- function(x){ sectionAttrs <- xmlAttrs(x) sectionAttrs <- as.data.frame(t(sectionAttrs), stringsAsFactors = FALSE) sectionChildren <- xmlChildren(x) secObs <- names(sectionChildren) secValues <- do.call("rbind.fill", lapply(sectionChildren, function(x) { attrs <- xmlAttrs(x) return(as.data.frame(t(attrs), stringsAsFactors = FALSE)) })) secContent <- data.frame(sectionAttrs, obs = secObs, secValues, stringsAsFactors = FALSE) return(secContent) } #function to parse a Group parseGroup <- function(x){ groupAttrs <- xmlAttrs(x) groupAttrs <- as.data.frame(t(groupAttrs), stringsAsFactors = FALSE) x <- xmlDoc(x) if(hasAuthorityNS){ secXML <- getNodeSet(x, "//ns:Section", namespaces = c(ns = authorityNs$uri)) if(length(secXML) == 0){ secXML <- getNodeSet(x, "//ns:Section", namespaces = ns) } }else{ if(length(ns) > 0){ secXML <- getNodeSet(x, "//ns:Section", namespaces = ns) }else{ if(nrow(nsDefs.df) > 0){ secNs <- nsDefs.df[1,] secXML <- getNodeSet(x, "//nt:Section", c(nt = secNs$uri)) }else{ stop("Unsupported CrossSectionalData parser for empty target XML namespace") } } } if(length(secXML) == 0){ secXML <- getNodeSet(xmlObj, "//Section") } secNb <- length(secXML) if(secNb == 0) return(NULL); #converting SDMX section to a DataFrame R object sections <- do.call("rbind.fill", lapply(secXML, parseSection)) group <- data.frame(groupAttrs, sections) return(group) } #converting SDMX groups to a DataFrame R object dataset <- do.call("rbind.fill", lapply(groupsXML, parseGroup)) if(any(as.character(dataset$obsValue) == "NaN", na.rm = TRUE)){ dataset[as.character(dataset$obsValue) == "NaN",]$obsValue <- NA } if(!is.null(dataset)) row.names(dataset) <- 1:nrow(dataset) # output return(dataset) } setAs("SDMXCrossSectionalData", "data.frame", function(from) as.data.frame.SDMXCrossSectionalData(from)); rsdmx/R/Class-SDMXServiceProvider.R0000644000176200001440000000255312654150565016623 0ustar liggesusers#' @name SDMXServiceProvider #' @docType class #' @aliases SDMXServiceProvider-class #' #' @title Class "SDMXServiceProvider" #' @description A basic class to handle a SDMX service provider #' #' @slot agencyId an object of class "character" giving the a provider identifier #' @slot name an object of class "character" giving the name of the provider #' @slot scale an object of class "character" giving the scale of the datasource, #' either "international" or "national" #' @slot country an object of class "character" giving the ISO 3-alpha code of #' the country (if scale is "national") #' @slot builder an object of class "SDMXRequestBuilder" that will performs the #' web request building #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXServiceProvider", representation( agencyId = "character", name = "character", scale = "character", country = "character", builder = "SDMXRequestBuilder" ), prototype = list( agencyId = "MYORG", name = "My Organization", scale = "international", country = as.character(NA), footer = new("SDMXRequestBuilder") ), validity = function(object){ return(TRUE); } ) rsdmx/R/SDMXAttribute-methods.R0000644000176200001440000001313112654150565016043 0ustar liggesusers#' @name SDMXAttribute #' @rdname SDMXAttribute #' @aliases SDMXAttribute,SDMXAttribute-method #' #' @usage #' SDMXAttribute(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXAttribute" #' #' @seealso \link{readSDMX} #' SDMXAttribute <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #attributes #========= conceptRef = xmlGetAttr(xmlObj, "conceptRef") if(is.null(conceptRef)) conceptRef <- as.character(NA) conceptVersion = xmlGetAttr(xmlObj, "conceptVersion") if(is.null(conceptVersion)) conceptVersion <- as.character(NA) conceptAgency = xmlGetAttr(xmlObj, "conceptAgency") if(is.null(conceptAgency)) conceptAgency <- as.character(NA) conceptSchemeRef = xmlGetAttr(xmlObj, "conceptSchemeRef") if(is.null(conceptSchemeRef)) conceptSchemeRef <- as.character(NA) conceptSchemeAgency = xmlGetAttr(xmlObj, "conceptSchemeAgency") if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA) codelist = xmlGetAttr(xmlObj, "codelist") if(is.null(codelist)) codelist <- as.character(NA) codelistVersion = xmlGetAttr(xmlObj, "codelistVersion") if(is.null(codelistVersion)) codelistVersion <- as.character(NA) codelistAgency = xmlGetAttr(xmlObj, "codelistAgency") if(is.null(codelistAgency)) codelistAgency <- as.character(NA) attachmentLevel = xmlGetAttr(xmlObj, "attachmentLevel") if(is.null(attachmentLevel)) attachmentLevel <- as.character(NA) assignmentStatus = xmlGetAttr(xmlObj, "assignmentStatus") if(is.null(assignmentStatus)) assignmentStatus <- as.character(NA) isTimeFormat = xmlGetAttr(xmlObj, "isTimeFormat") if(is.null(isTimeFormat)){ isTimeFormat <- FALSE }else{ isTimeFormat <- as.logical(isTimeFormat) } crossSectionalAttachDataset = xmlGetAttr(xmlObj, "crossSectionalAttachDataset") if(is.null(crossSectionalAttachDataset)){ crossSectionalAttachDataset <- NA }else{ crossSectionalAttachDataset <- as.logical(crossSectionalAttachDataset) } crossSectionalAttachGroup = xmlGetAttr(xmlObj, "crossSectionalAttachGroup") if(is.null(crossSectionalAttachGroup)){ crossSectionalAttachGroup <- NA }else{ crossSectionalAttachGroup <- as.logical(crossSectionalAttachGroup) } crossSectionalAttachSection = xmlGetAttr(xmlObj, "crossSectionalAttachSection") if(is.null(crossSectionalAttachSection)){ crossSectionalAttachSection <- NA }else{ crossSectionalAttachSection <- as.logical(crossSectionalAttachSection) } crossSectionalAttachObservation = xmlGetAttr(xmlObj, "crossSectionalAttachObservation") if(is.null(crossSectionalAttachObservation)){ crossSectionalAttachObservation <- NA }else{ crossSectionalAttachObservation <- as.logical(crossSectionalAttachObservation) } isEntityAttribute = xmlGetAttr(xmlObj, "isEntityAttribute") if(is.null(isEntityAttribute)){ isEntityAttribute <- FALSE }else{ isEntityAttribute <- as.logical(isEntityAttribute) } isNonObservationTimeAttribute = xmlGetAttr(xmlObj, "isNonObservationTimeAttribute") if(is.null(isNonObservationTimeAttribute)){ isNonObservationTimeAttribute <- FALSE }else{ isNonObservationTimeAttribute <- as.logical(isNonObservationTimeAttribute) } isCountAttribute = xmlGetAttr(xmlObj, "isCountAttribute") if(is.null(isCountAttribute)){ isCountAttribute <- FALSE }else{ isCountAttribute <- as.logical(isCountAttribute) } isFrequencyAttribute = xmlGetAttr(xmlObj, "isFrequencyAttribute") if(is.null(isFrequencyAttribute)){ isFrequencyAttribute <- FALSE }else{ isFrequencyAttribute <- as.logical(isFrequencyAttribute) } isIdentityAttribute = xmlGetAttr(xmlObj, "isIdentityAttribute") if(is.null(isIdentityAttribute)){ isIdentityAttribute <- FALSE }else{ isIdentityAttribute <- as.logical(isIdentityAttribute) } #elements #======== #TextFormat TODO #instantiate the object obj<- new("SDMXAttribute", #attributes conceptRef = conceptRef, conceptVersion = conceptVersion, conceptAgency = conceptAgency, conceptSchemeRef = conceptSchemeRef, conceptSchemeAgency = conceptSchemeAgency, codelist = codelist, codelistVersion = codelistVersion, codelistAgency = codelistAgency, attachmentLevel = attachmentLevel, assignmentStatus = assignmentStatus, isTimeFormat = isTimeFormat, crossSectionalAttachDataset = crossSectionalAttachDataset, crossSectionalAttachGroup = crossSectionalAttachGroup, crossSectionalAttachSection = crossSectionalAttachSection, crossSectionalAttachObservation = crossSectionalAttachObservation, isEntityAttribute = isEntityAttribute, isNonObservationTimeAttribute = isNonObservationTimeAttribute, isCountAttribute = isCountAttribute, isFrequencyAttribute = isFrequencyAttribute, isIdentityAttribute = isIdentityAttribute #elements, #TextFormat #AttachmentGroup #AttachmentMeasure ) } rsdmx/R/SDMXDataFlow-methods.R0000644000176200001440000001022612654150565015603 0ustar liggesusers#' @name SDMXDataFlow #' @rdname SDMXDataFlow #' @aliases SDMXDataFlow,SDMXDataFlow-method #' #' @usage #' SDMXDataFlow(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDataFlow" #' #' @seealso \link{readSDMX} #' SDMXDataFlow <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #attributes #========= id = xmlGetAttr(xmlObj, "id") if(is.null(id)) id <- as.character(NA) agencyId = xmlGetAttr(xmlObj, "agencyID") if(is.null(agencyId)) agencyId <- as.character(NA) version = xmlGetAttr(xmlObj, "version") if(is.null(version)) version <- as.character(NA) uri = xmlGetAttr(xmlObj, "uri") if(is.null(uri)) uri <- as.character(NA) urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) isExternalReference = xmlGetAttr(xmlObj, "isExternalReference") if(is.null(isExternalReference)){ isExternalReference <- NA }else{ isExternalReference <- as.logical(isExternalReference) } isFinal = xmlGetAttr(xmlObj, "isFinal") if(is.null(isFinal)){ isFinal <- NA }else{ isFinal <- as.logical(isFinal) } validFrom = xmlGetAttr(xmlObj,"validFrom") if(is.null(validFrom)) validFrom <- as.character(NA) validTo = xmlGetAttr(xmlObj, "validTo") if(is.null(validTo)) validTo <- as.character(NA) #elements #======== #name (multi-languages) flowNamesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") flowNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:Dataflow/com:Name", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ flowNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:KeyFamily/str:Name", namespaces = c(str = as.character(strNs))) } flowNames <- NULL if(length(flowNamesXML) > 0){ flowNames <- new.env() sapply(flowNamesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") flowNames[[lang]] <- xmlValue(x) }) flowNames <- as.list(flowNames) } #description (multi-languages) flowDesXML <- NULL if(VERSION.21){ comNs <- findNamespace(namespaces, "common") flowDesXML <- getNodeSet(xmlDoc(xmlObj), "//str:Dataflow/com:Description", namespaces = c(str = as.character(strNs), com = as.character(comNs))) }else{ flowNamesXML <- getNodeSet(xmlDoc(xmlObj), "//str:KeyFamily/str:Description", namespaces = c(str = as.character(strNs))) } flowDescriptions <- list() if(length(flowDesXML) > 0){ flowDescriptions <- new.env() sapply(flowDesXML, function(x){ lang <- xmlGetAttr(x,"xml:lang") flowDescriptions[[lang]] <- xmlValue(x) }) flowDescriptions <- as.list(flowDescriptions) } #dsd reference dsdRef <- as.character(NA) if(VERSION.21){ flowStr <- getNodeSet(xmlDoc(xmlObj), "//str:Dataflow/str:Structure") if(length(flowStr) > 0){ flowStr <- flowStr[[1]] dsdRef <- xmlGetAttr(xmlChildren(flowStr)[[1]], "id") } }else{ dsdRef <- id } #instantiate the object obj<- new("SDMXDataFlow", #attributes id = id, agencyID = agencyId, version = version, uri = uri, urn = urn, isExternalReference = isExternalReference, isFinal = isFinal, validFrom = validFrom, validTo = validTo, #elements, Name = flowNames, Description = flowDescriptions, dsdRef = dsdRef ) } rsdmx/R/SDMXHeader-methods.R0000644000176200001440000001204112654150565015267 0ustar liggesusers#' @name SDMXHeader #' @rdname SDMXHeader #' @aliases SDMXHeader,SDMXHeader-method #' #' @usage #' SDMXHeader(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXHeader" #' #' @seealso \link{readSDMX} #' SDMXHeader <- function(xmlObj){ sdmxVersion <- slot(SDMXSchema(xmlObj), "version") VERSION.10 <- sdmxVersion == "1.0" VERSION.20 <- sdmxVersion == "2.0" VERSION.21 <- sdmxVersion == "2.1" #header elements node <- xmlRoot(xmlObj)[[1]]; children <- xmlChildren(node) #header attributes #----------------- id <- xmlValue(children$ID); test <- FALSE if(!is.null(children$Test)) test <- as.logical(xmlValue(children$Test)); truncated <- FALSE if(!is.null(children$Truncated)) truncated <- as.logical(xmlValue(children$Truncated)); name <- xmlValue(children$Name); #sender sender <- list(id=NA,name=NA,contact=NULL) if(!is.null(children$Sender)){ sender$id <- xmlGetAttr(children$Sender,"id"); senderList <- xmlChildren(children$Sender) if(length(senderList) != 0){ #name sender$name <- new.env() senderNames <- senderList[names(senderList) == "Name"] sapply(senderNames, function(x) { if(xmlName(x) == "Name"){ lang <- xmlGetAttr(x,"xml:lang") if(is.null(lang)) lang <- xmlGetAttr(x,"lang") if(is.null(lang)) lang <- "en" sender$name[[lang]] <- xmlValue(x) } }) sender$name <- as.list(sender$name) #contact sender$contact <- NULL #TODO currently not implemented #timezone if(VERSION.21){ sender$timezone <- xmlValue(senderNames[["Timezone"]]) } } } #receiver receiver <- list(id=NA,name=NA,contact=NULL) if(!is.null(children$Receiver)){ receiver$id <- xmlGetAttr(children$Receiver,"id"); receiverList <- xmlChildren(children$Receiver) if(length(receiverList) != 0){ #name receiver$name <- new.env() receiverNames <- receiverList[names(receiverList) == "Name"] sapply(receiverNames, function(x) { if(xmlName(x) == "Name"){ lang <- xmlGetAttr(x,"xml:lang") if(is.null(lang)) lang <- xmlGetAttr(x,"lang") if(is.null(lang)) lang <- "en" receiver$name[[lang]] <- xmlValue(x) } }) receiver$name <- as.list(receiver$name) #contact sender$contact <- NULL #TODO currently not implemented #timezone if(VERSION.21){ sender$timezone <- xmlValue(senderNames[["Timezone"]]) } } } #source source <- xmlValue(children$Source); #Dates preparedFormat <- NULL; prepared <- xmlValue(children$Prepared); if(!is.na(prepared)){ if(nchar(prepared,"w") %in% c(4,10)){ if(nchar(prepared,"w") == 4) prepared <- ISOdate(as.integer(prepared),1,1) preparedFormat <- "%Y-%m-%d"; }else{ if(attr(regexpr("T", prepared),"match.length") != -1){ preparedFormat <- "%Y-%m-%dT%H:%M:%S"; }else{ preparedFormat <- "%Y-%m-%d %H:%M:%S"; } } prepared <- as.POSIXlt(strptime(prepared, format = preparedFormat)); }else{ prepared <- as.POSIXlt(NA) } extractedFormat <- NULL; extracted <- xmlValue(children$Extracted); if(!is.na(extracted)){ if(nchar(extracted,"w") %in% c(4,10)){ if(nchar(extracted,"w") == 4) extracted <- ISOdate(as.integer(extracted),1,1) extractedFormat <- "%Y-%m-%d"; }else{ if(attr(regexpr("T", extracted),"match.length") != -1){ extractedFormat <- "%Y-%m-%dT%H:%M:%S"; }else{ extractedFormat <- "%Y-%m-%d %H:%M:%S"; } } extracted <- as.POSIXlt(strptime(extracted, format = extractedFormat)); }else{ extracted <- as.POSIXlt(NA) } #Reporting Dates reportFormat <- NULL; reportBegin = xmlValue(children$ReportingBegin) if(!is.na(reportBegin)){ if(nchar(reportBegin,"w") %in% c(4,10)){ if(nchar(reportBegin,"w") == 4) reportBegin <- ISOdate(as.integer(reportBegin),1,1) reportFormat <- "%Y-%m-%d"; }else{ if(attr(regexpr("T", extracted),"match.length") != -1){ reportFormat <- "%Y-%m-%dT%H:%M:%S"; }else{ reportFormat <- "%Y-%m-%d %H:%M:%S"; } } reportBegin <- as.POSIXlt(strptime( reportBegin, format = reportFormat)); }else{ reportBegin <- as.POSIXlt(NA) } reportEnd = xmlValue(children$ReportingEnd) if(!is.na(reportEnd)){ if(nchar(reportEnd,"w") == 4){ reportEnd <- ISOdate(as.integer(reportEnd),12,31) } reportEnd <- as.POSIXlt(strptime( reportEnd, format = reportFormat)); }else{ reportEnd <- as.POSIXlt(NA) } #SDMXHeader object obj <- new("SDMXHeader", ID = id, Test = test, Truncated = truncated, Name = name, Sender = sender, Receiver = receiver, Prepared = prepared, Extracted = extracted, ReportingBegin = reportBegin, ReportingEnd = reportEnd, Source = source); return(obj); } rsdmx/R/SDMXDimension-methods.R0000644000176200001440000001704112654150565016031 0ustar liggesusers#' @name SDMXDimension #' @rdname SDMXDimension #' @aliases SDMXDimension,SDMXDimension-method #' #' @usage #' SDMXDimension(xmlObj) #' #' @param xmlObj object of class "XMLInternalDocument derived from XML package #' @return an object of class "SDMXDimension" #' #' @seealso \link{readSDMX} #' SDMXDimension <- function(xmlObj){ sdmxVersion <- version.SDMXSchema(xmlDoc(xmlObj)) VERSION.21 <- sdmxVersion == "2.1" namespaces <- namespaces.SDMX(xmlDoc(xmlObj)) messageNs <- findNamespace(namespaces, "message") strNs <- findNamespace(namespaces, "structure") #manage SDMX 2.1 conceptIdentity and codelist LocalRepresentation conceptRefXML <- NULL if(VERSION.21){ conceptIdentityXML <- getNodeSet(xmlDoc(xmlObj), "//str:ConceptIdentity", namespaces = c(str = as.character(strNs))) if(length(conceptIdentityXML) > 0) conceptRefXML <- xmlChildren(conceptIdentityXML[[1]])[[1]] } codelistRefXML <- NULL if(VERSION.21){ enumXML <- getNodeSet(xmlDoc(xmlObj), "//str:Enumeration", namespaces = c(str = as.character(strNs))) if(length(enumXML) > 0) codelistRefXML <- xmlChildren(enumXML[[1]])[[1]] } #attributes #========= conceptRef <- NULL conceptVersion <- NULL conceptAgency <- NULL conceptSchemeRef <- NULL conceptSchemeAgency <- NULL codelist <- NULL codelistVersion <- NULL codelistAgency <- NULL isMeasureDimension <- NULL isFrequencyDimension <- NULL isEntityDimension <- NULL isCountDimension <- NULL isNonObservationTimeDimension <- NULL isIdentityDimension <- NULL crossSectionalAttachDataset <- NULL crossSectionalAttachGroup <- NULL crossSectionalAttachSection <- NULL crossSectionalAttachObservation <- NULL if(VERSION.21){ #concepts if(!is.null(conceptRefXML)){ conceptRef = xmlGetAttr(conceptRefXML, "id") conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") conceptAgency = xmlGetAttr(conceptRefXML, "agencyID") #TODO conceptSchemeRef? #TODO conceptSchemeAgency } #codelists if(!is.null(codelistRefXML)){ codelist <- xmlGetAttr(codelistRefXML, "id") codelistVersion <- xmlGetAttr(codelistRefXML, "version") codelistAgency <- xmlGetAttr(codelistRefXML, "agencyID") } #dimension characteristics #TODO isMeasureDimension? #TODO isFrequencyDimension? #TODO isEntityDimension? #TODO isLogicalDimension? #TODO isNonObservationTimeDimension? #TODO isIdentityDimension? #crossSectionalAttach #TODO crossSectionalAttachDataset? #TODO crossSectionalAttachGroup? #TODO crossSectionalAttachSection? #TODO crossSectionalAttachObservation? }else{ #concepts conceptRef = xmlGetAttr(xmlObj, "conceptRef") conceptVersion = xmlGetAttr(xmlObj, "conceptVersion") conceptAgency = xmlGetAttr(xmlObj, "conceptAgency") conceptSchemeRef = xmlGetAttr(xmlObj, "conceptSchemeRef") conceptSchemeAgency = xmlGetAttr(xmlObj, "conceptSchemeAgency") #codelists codelist = xmlGetAttr(xmlObj, "codelist") codelistVersion = xmlGetAttr(xmlObj, "codelistVersion") codelistAgency = xmlGetAttr(xmlObj, "codelistAgency") #dimensions characteristics isMeasureDimension = xmlGetAttr(xmlObj, "isMeasureDimension") isFrequencyDimension = xmlGetAttr(xmlObj, "isFrequencyDimension") isEntityDimension = xmlGetAttr(xmlObj, "isEntityDimension") isCountDimension = xmlGetAttr(xmlObj, "isCountDimension") isNonObservationTimeDimension = xmlGetAttr(xmlObj,"isNonObservationTimeDimension") isIdentityDimension = xmlGetAttr(xmlObj, "isIdentityDimension") #crossSectionalAttach crossSectionalAttachDataset = xmlGetAttr(xmlObj, "crossSectionalAttachDataset") crossSectionalAttachGroup = xmlGetAttr(xmlObj, "crossSectionalAttachGroup") crossSectionalAttachSection = xmlGetAttr(xmlObj, "crossSectionalAttachSection") crossSectionalAttachObservation = xmlGetAttr(xmlObj,"crossSectionalAttachObservation") } if(is.null(conceptRef)) conceptRef <- as.character(NA) if(is.null(conceptVersion)) conceptVersion <- as.character(NA) if(is.null(conceptAgency)) conceptAgency <- as.character(NA) if(is.null(conceptSchemeRef)) conceptSchemeRef <- as.character(NA) if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA) if(is.null(codelist)) codelist <- as.character(NA) if(is.null(codelistVersion)) codelistVersion <- as.character(NA) if(is.null(codelistAgency)) codelistAgency <- as.character(NA) if(is.null(isMeasureDimension)){ isMeasureDimension <- FALSE }else{ isMeasureDimension <- as.logical(isMeasureDimension) } if(is.null(isFrequencyDimension)){ isFrequencyDimension <- FALSE }else{ isFrequencyDimension <- as.logical(isFrequencyDimension) } if(is.null(isEntityDimension)){ isEntityDimension <- FALSE }else{ isEntityDimension <- as.logical(isEntityDimension) } if(is.null(isCountDimension)){ isCountDimension <- FALSE }else{ isCountDimension <- as.logical(isCountDimension) } if(is.null(isNonObservationTimeDimension)){ isNonObservationTimeDimension <- FALSE }else{ isNonObservationTimeDimension <- as.logical(isNonObservationTimeDimension) } if(is.null(isIdentityDimension)){ isIdentityDimension <- FALSE }else{ isIdentityDimension <- as.logical(isIdentityDimension) } if(is.null(crossSectionalAttachDataset)){ crossSectionalAttachDataset <- NA }else{ crossSectionalAttachDataset <- as.logical(crossSectionalAttachDataset) } if(is.null(crossSectionalAttachGroup)){ crossSectionalAttachGroup <- NA }else{ crossSectionalAttachGroup <- as.logical(crossSectionalAttachGroup) } if(is.null(crossSectionalAttachSection)){ crossSectionalAttachSection <- NA }else{ crossSectionalAttachSection <- as.logical(crossSectionalAttachSection) } if(is.null(crossSectionalAttachObservation)){ crossSectionalAttachObservation <- NA }else{ crossSectionalAttachObservation <- as.logical(crossSectionalAttachObservation) } #elements #======== #TextFormat TODO #instantiate the object obj<- new("SDMXDimension", #attributes conceptRef = conceptRef, conceptVersion = conceptVersion, conceptAgency = conceptAgency, conceptSchemeRef = conceptSchemeRef, conceptSchemeAgency = conceptSchemeAgency, codelist = codelist, codelistVersion = codelistVersion, codelistAgency = codelistAgency, isMeasureDimension = isMeasureDimension, isFrequencyDimension = isFrequencyDimension, isEntityDimension = isEntityDimension, isCountDimension = isCountDimension, isNonObservationTimeDimension = isNonObservationTimeDimension, isIdentityDimension = isIdentityDimension, crossSectionalAttachDataset = crossSectionalAttachDataset, crossSectionalAttachGroup = crossSectionalAttachGroup, crossSectionalAttachSection = crossSectionalAttachSection, crossSectionalAttachObservation = crossSectionalAttachObservation #elements, #TextFormat = TextFormat ) } rsdmx/R/Class-SDMXAttribute.R0000644000176200001440000001176412654150565015457 0ustar liggesusers#' @name SDMXAttribute #' @docType class #' @aliases SDMXAttribute-class #' #' @title Class "SDMXAttribute" #' @description A basic class to handle a SDMX Attribute #' #' @slot conceptRef Object of class "character" giving the attribute conceptRef (required) #' @slot conceptVersion Object of class "character" giving the attribute concept version #' @slot conceptAgency Object of class "character" giving the attribute concept agency #' @slot conceptSchemeRef Object of class "character" giving the attribute conceptScheme ref #' @slot conceptSchemeAgency Object of class "character" giving the attribute conceptScheme agency #' @slot codelist Object of class "character" giving the codelist ref name #' @slot codelistVersion Object of class "character" giving the codelist ref version #' @slot codelistAgency Object of class "character" giving the codelist ref agency #' @slot attachmentLevel Object of class "character" giving the attachment level (e.g. DataSet) #' @slot assignmentStatus Object of class "character" giving the assignment status (e.g. Mandatory) #' @slot isTimeFormat Object of class "logical" #' @slot crossSectionalAttachDataset Object of class "logical" #' @slot crossSectionalAttachGroup Object of class "logical" #' @slot crossSectionalAttachSection Object of class "logical" #' @slot crossSectionalAttachObservation Object of class "logical" #' @slot isEntityAttribute Object of class "logical" indicating if the Attribute is an entity Attribute. Default value is FALSE #' @slot isNonObservationTimeAttribute Object of class "logical" indicating if the Attribute is a non-observation Attribute. Default value is FALSE #' @slot isCountAttribute Object of class "logical" indicating if the Attribute is a count Attribute. Default value is FALSE #' @slot isFrequencyAttribute Object of class "logical" indicating if the Attribute is a frequency Attribute. Default value is FALSE #' @slot isIdentityAttribute Object of class "logical" indicating if the Attribute is an identity Attribute. Default value is FALSE #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (DataStructures, or #' DataStructureDefinitions) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXAttribute", representation( #attributes conceptRef = "character", #required conceptVersion = "character", #optional conceptAgency = "character", #optional conceptSchemeRef = "character", #optional conceptSchemeAgency = "character", #optional codelist = "character", #optional codelistVersion = "character", #optional codelistAgency = "character", #optional attachmentLevel = "character", #required assignmentStatus = "character", #required isTimeFormat = "logical", #default to false crossSectionalAttachDataset = "logical", #optional crossSectionalAttachGroup = "logical", #optional crossSectionalAttachSection = "logical", #optional crossSectionalAttachObservation = "logical", #optional isEntityAttribute = "logical", #default to false isNonObservationTimeAttribute = "logical", #default to false isCountAttribute = "logical", #default to false isFrequencyAttribute = "logical", #default to false isIdentityAttribute = "logical" #default to false #elements #TextFormat = "SDMXTextFormat", #optional #AttachmentGroup = "list", #AttachmentMeasure = "list" ), prototype = list( #attributes conceptRef = "CONCEPT", conceptVersion = "1.0", conceptAgency = "ORG", conceptSchemeRef = "CONCEPT_SCHEME", conceptSchemeAgency = "ORG", codelist = "CODELIST", codelistVersion = "1.0", codelistAgency = "ORG", attachmentLevel = "DataSet", assignmentStatus = "Mandatory", isTimeFormat = FALSE, crossSectionalAttachDataset = NA, crossSectionalAttachGroup = NA, crossSectionalAttachSection = NA, crossSectionalAttachObservation = NA, isEntityAttribute = FALSE, isNonObservationTimeAttribute = FALSE, isCountAttribute = FALSE, isFrequencyAttribute = FALSE, isIdentityAttribute = FALSE #elements #TextFormat = ?, #AttachmentGroup = ?, #AttachmentMeasure = ? ), validity = function(object){ #eventual validation rules if(is.na(object@conceptRef)) return(FALSE) #if(is.na(object@attachmentLevel)) return(FALSE) #if(is.na(object@assignmentStatus)) return(FALSE) return(TRUE); } ) rsdmx/R/SDMXRESTRequestBuilder-methods.R0000644000176200001440000001346612654150565017550 0ustar liggesusers#' @name SDMXRESTRequestBuilder #' @rdname SDMXRESTRequestBuilder #' @aliases SDMXRESTRequestBuilder,SDMXRESTRequestBuilder-method #' #' @usage #' SDMXRESTRequestBuilder(regUrl, repoUrl, compliant, unsupportedResources, #' skipAgencyId, forceAgencyId) #' #' @param regUrl an object of class "character" giving the base Url of the SDMX #' service registry #' @param repoUrl an object of class "character" giving the base Url of the SDMX #' service repository #' @param compliant an object of class "logical" indicating if the web-service #' is compliant with the SDMX REST web-service specifications #' @param unsupportedResources an object of class "list" giving eventual unsupported #' REST resources. Default is an empty list object #' @param skipAgencyId an object of class "logical" indicating that agencyId #' should be skipped. Used to control lack of strong SDMX REST compliance #' from data providers. For now, it applies only for the "data" resource. #' @param forceAgencyId an object of class "logical" indicating if the agencyId #' as to be added at the end of the request. Default value is \code{FALSE}. #' For some providers, the \code{all} value for the \code{agencyId} is not #' allowed, in this case, the \code{agencyId} of the data provider has to #' be forced in the web-request #' #' @examples #' #how to create a SDMXRESTRequestBuilder #' requestBuilder <- SDMXRESTRequestBuilder( #' regUrl = "http://www.myorg/registry", #' repoUrl = "http://www.myorg/repository", #' compliant = TRUE) #' SDMXRESTRequestBuilder <- function(regUrl, repoUrl, compliant, unsupportedResources = list(), skipAgencyId = FALSE, forceAgencyId = FALSE){ #function to handle request serviceRequestHandler <- function(regUrl, repoUrl, agencyId, resource, resourceId, version = NULL, flowRef, key = NULL, start = NULL, end = NULL, compliant){ if(is.null(resource)) stop("Missing SDMX service resource") if(resource %in% unsupportedResources) stop("Unsupported SDMX service resource for this provider") restResource <- switch(resource, "dataflow" = ifelse(compliant, resource, "GetKeyFamily"), "datastructure" = ifelse(compliant, resource, "GetDataStructure"), "data" = ifelse(compliant, resource, "GetData") ) #wrap argument values obj <- list(regUrl = regUrl, repoUrl = repoUrl, agencyId = agencyId, resource = restResource, resourceId = resourceId, version = version, flowRef = flowRef, key = key, start = start, end = end) #REST resource handler resourceHandler <- switch(resource, #'dataflow' resource (path="dataflow/{agencyID}/{resourceID}/{version}") #----------------------------------------------------------------------- "dataflow" = function(xmlObj){ if(is.null(obj$resourceId)) obj$resourceId = "all" if(is.null(obj$version)) obj$version = "latest" #base dataflow request if(compliant){ req <- paste(obj$regUrl, obj$resource, obj$agencyId, obj$resourceId, obj$version, sep = "/") }else{ req <- paste(obj$regUrl, obj$resource, obj$resourceId, sep = "/") } return(req) }, #'datastructure' resource (path="datastructure/{agencyID}/{resourceID}/{version}) #-------------------------------------------------------------------------------- "datastructure" = function(obj){ if(is.null(obj$resourceId)) obj$resourceId = "all" if(is.null(obj$version)) obj$version = "latest" #base datastructure request if(compliant){ req <- paste(obj$regUrl, obj$resource, obj$agencyId, obj$resourceId, obj$version, sep = "/") if(forceAgencyId) req <- paste(req, obj$agencyId, sep = "/") req <- paste0(req, "?references=children") #TODO to see later to have arg for this }else{ req <- paste(obj$regUrl, obj$resource, obj$resourceId, sep = "/") if(forceAgencyId) req <- paste(req, obj$agencyId, sep = "/") } return(req) }, #'data' resource (path="data/{flowRef}/{key}/{providerRef}) #---------------------------------------------------------- "data" = function(obj){ if(is.null(obj$flowRef)){ stop("Missing flowRef value") } if(is.null(obj$key)) obj$key = "all" #base data request req <- paste(obj$repoUrl, obj$resource, obj$flowRef, obj$key, sep = "/") if(skipAgencyId){ req <- paste0(req, "/") }else{ req <- paste(req, ifelse(forceAgencyId, obj$agencyId, "all"), sep = "/") } #DataQuery #-> temporal extent (if any) addParams = FALSE if(!is.null(obj$start)){ req <- paste0(req, "?") addParams = TRUE req <- paste0(req, "startPeriod=", start) } if(!is.null(obj$end)){ if(!addParams){ req <- paste0(req, "?") }else{ req <- paste0(req, "&") } req <- paste0(req, "endPeriod=", end) } return(req) } ) #handle rest resource path req <- resourceHandler(obj) return(req) } new("SDMXRESTRequestBuilder", regUrl = regUrl, repoUrl = repoUrl, handler = serviceRequestHandler, compliant = compliant) } rsdmx/R/Class-SDMXTimeDimension.R0000644000176200001440000000631212654150565016251 0ustar liggesusers#' @name SDMXTimeDimension #' @docType class #' @aliases SDMXTimeDimension-class #' #' @title Class "SDMXTimeDimension" #' @description A basic class to handle a SDMX TimeDimension #' #' @slot conceptRef Object of class "character" giving the dimension conceptRef (required) #' @slot conceptVersion Object of class "character" giving the dimension concept version #' @slot conceptAgency Object of class "character" giving the dimension concept agency #' @slot conceptSchemeRef Object of class "character" giving the dimension conceptScheme ref #' @slot conceptSchemeAgency Object of class "character" giving the dimension conceptScheme agency #' @slot codelist Object of class "character" giving the codelist ref name #' @slot codelistVersion Object of class "character" giving the codelist ref version #' @slot codelistAgency Object of class "character" giving the codelist ref agency #' @slot crossSectionalAttachDataset Object of class "logical" #' @slot crossSectionalAttachGroup Object of class "logical" #' @slot crossSectionalAttachSection Object of class "logical" #' @slot crossSectionalAttachObservation Object of class "logical" #' #' @section Warning: #' This class is not useful in itself, but non-abstract classes willencapsulate #' it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXTimeDimension", representation( #attributes conceptRef = "character", #required conceptVersion = "character", #optional conceptAgency = "character", #optional conceptSchemeRef = "character", #optional conceptSchemeAgency = "character", #optional codelist = "character", #optional codelistVersion = "character", #optional codelistAgency = "character", #optional crossSectionalAttachDataset = "logical", #optional crossSectionalAttachGroup = "logical", #optional crossSectionalAttachSection = "logical", #optional crossSectionalAttachObservation = "logical" #optional #elements #TextFormat = "SDMXTextFormat" #optional ), prototype = list( #attributes conceptRef = "CONCEPT", conceptVersion = "1.0", conceptAgency = "ORG", conceptSchemeRef = "CONCEPT_SCHEME", conceptSchemeAgency = "ORG", codelist = "CODELIST", codelistVersion = "1.0", codelistAgency = "ORG", crossSectionalAttachDataset = NA, crossSectionalAttachGroup = NA, crossSectionalAttachSection = NA, crossSectionalAttachObservation = NA #elements #TextFormat = new("SDMXTextFormat") ), validity = function(object){ #eventual validation rules if(!is.null(object)){ if(is.na(object@conceptRef)) return(FALSE) } return(TRUE); } ) setClassUnion("SDMXTimeDimension_OR_NULL", c("SDMXTimeDimension","NULL")) rsdmx/R/Class-SDMXDimension.R0000644000176200001440000001064312654150565015434 0ustar liggesusers#' @name SDMXDimension #' @docType class #' @aliases SDMXDimension-class #' #' @title Class "SDMXDimension" #' @description A basic class to handle a SDMX Dimension #' #' @slot conceptRef Object of class "character" giving the dimension conceptRef (required) #' @slot conceptVersion Object of class "character" giving the dimension concept version #' @slot conceptAgency Object of class "character" giving the dimension concept agency #' @slot conceptSchemeRef Object of class "character" giving the dimension conceptScheme ref #' @slot conceptSchemeAgency Object of class "character" giving the dimension conceptScheme agency #' @slot codelist Object of class "character" giving the codelist ref name #' @slot codelistVersion Object of class "character" giving the codelist ref version #' @slot codelistAgency Object of class "character" giving the codelist ref agency #' @slot isMeasureDimension Object of class "logical" indicating if the dimension is a measure dimension. Default value is FALSE #' @slot isFrequencyDimension Object of class "logical" indicating if the dimension is a frequency dimension. Default value is FALSE #' @slot isEntityDimension Object of class "logical" indicating if the dimension is an entity dimension. Default value is FALSE #' @slot isCountDimension Object of class "logical" indicating if the dimension is a count dimension. Default value is FALSE #' @slot isNonObservationTimeDimension Object of class "logical" indicating if the dimension is a non-observation dimension. Default value is FALSE #' @slot isIdentityDimension Object of class "logical" indicating if the dimension is an identity dimension. Default value is FALSE #' @slot crossSectionalAttachDataset Object of class "logical" #' @slot crossSectionalAttachGroup Object of class "logical" #' @slot crossSectionalAttachSection Object of class "logical" #' @slot crossSectionalAttachObservation Object of class "logical" #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXDimension", representation( #attributes conceptRef = "character", #required conceptVersion = "character", #optional conceptAgency = "character", #optional conceptSchemeRef = "character", #optional conceptSchemeAgency = "character", #optional codelist = "character", #optional codelistVersion = "character", #optional codelistAgency = "character", #optional isMeasureDimension = "logical", #default to false isFrequencyDimension = "logical", #default to false isEntityDimension = "logical", #default to false isCountDimension = "logical", #default to false isNonObservationTimeDimension = "logical", #default to false isIdentityDimension = "logical", #default to false crossSectionalAttachDataset = "logical", #optional crossSectionalAttachGroup = "logical", #optional crossSectionalAttachSection = "logical", #optional crossSectionalAttachObservation = "logical" #optional #elements #TextFormat = "SDMXTextFormat" #optional ), prototype = list( #attributes conceptRef = "CONCEPT", conceptVersion = "1.0", conceptAgency = "ORG", conceptSchemeRef = "CONCEPT_SCHEME", conceptSchemeAgency = "ORG", codelist = "CODELIST", codelistVersion = "1.0", codelistAgency = "ORG", isMeasureDimension = FALSE, isFrequencyDimension = FALSE, isEntityDimension = FALSE, isCountDimension = FALSE, isNonObservationTimeDimension = FALSE, isIdentityDimension = FALSE, crossSectionalAttachDataset = NA, crossSectionalAttachGroup = NA, crossSectionalAttachSection = NA, crossSectionalAttachObservation = NA #elements #TextFormat = new("SDMXTextFormat") ), validity = function(object){ #eventual validation rules #if(is.na(object@conceptRef)) return(FALSE) return(TRUE); } ) rsdmx/R/Class-SDMXDataFlows.R0000644000176200001440000000156112654150565015372 0ustar liggesusers#' @name SDMXDataFlows #' @docType class #' @aliases SDMXDataFlows-class #' #' @title Class "SDMXDataFlows" #' @description A basic class to handle a SDMX DataFlows #' #' @slot dataflows Object of class "list" giving the list of DataFlows (datasets), #' (see \link{SDMXDataFlow}) #' #' @section Warning: #' This class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or #' DataStructureDefinition) #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXDataFlows", contains = "SDMX", representation( dataflows = "list" ), prototype = list(), validity = function(object){ #eventual validation rules return(TRUE); } ) rsdmx/R/Class-SDMXType.R0000644000176200001440000000236412654150565014431 0ustar liggesusers#' @name SDMXType #' @docType class #' @aliases SDMXType-class #' @title Class "SDMXType" #' #' @description A basic class to handle the type of a SDMX-ML document #' #' @slot type Object of class "character" giving the type of the SDMX-ML document #' #' @section Warning: #' this class is not useful in itself, but all SDMX non-abstract classes will #' encapsulate it as slot, when parsing an SDMX-ML document. #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' setClass("SDMXType", representation( type = "character" ), prototype = list(type = "SDMXGenericData"), validity = function(object){ type <- object@type; valid <- switch(type, "StructureType" = TRUE, "GenericDataType" = TRUE, "CompactDataType" = TRUE, "UtilityDataType" = TRUE, "StructureSpecificDataType" = TRUE, "CrossSectionalDataType" = TRUE, "MessageGroupType" = TRUE, FALSE ); if(valid == FALSE) warning(paste("Unknown SDMXType ", type, sep="")); return(valid); } )rsdmx/vignettes/0000755000176200001440000000000012654151640013423 5ustar liggesusersrsdmx/vignettes/quickstart.Rmd0000644000176200001440000001703412654150565016273 0ustar liggesusers # rsdmx quickstart guide The goal of this document is to get you up and running with rsdmx as quickly as possible. ``rsdmx`` provides a set of classes and methods to read data and metadata documents exchanged through the Statistical Data and Metadata Exchange (SDMX) framework. ## SDMX - a short introduction The SDMX framework provides two sets of standard specifications to facilitate the exchange of statistical data: * standard formats * web-service specifications SDMX allows to disseminate both **data** (a dataset) and **metadata** (the description of the dataset). For this, the SDMX standard provides various types of _documents_, also known as _messages_. Hence there will be: * **data** SDMX-ML _documents_. The two main _document_ types are the ``Generic`` and ``Compact`` ones. The latter aims to provide a more compact XML document. They are other data _document_ types derivating from the ones previously mentioned. * **metadata** SDMX-ML _documents_. The main metadata _document_ is known a ``Data Structure Definition`` (DSD). As its name indicates, it _describes_ the structure and organization of a dataset, and will generally include all the master/reference data used to characterize a dataset. The 2 main types of metadata are (1) the ``concepts``, which correspond to the _dimensions_ and/or _attributes_ of the dataset, and (2) the ``codelists`` which inventory the possible values to be used in the representation of _dimensions_ and _attributes_. For more information about the SDMX standards, you can visit the [SDMX website](http://sdmx.org/), or this [introduction by EUROSTAT](https://webgate.ec.europa.eu/fpfis/mwikis/sdmx/index.php/SDMX). ## How to deal with SDMX in R [rsdmx](http://cran.r-project.org/package=rsdmx) offers a low-level set of tools to read **data** and **metadata** in the SDMX-ML format. Its strategy is to make it very easy for the user. For this, a unique function named ``readSDMX`` has to be used, whatever it is a ``data`` or ``metadata`` document, or if it is ``local`` or ``remote`` datasource. What ``rsdmx`` does support: * a SDMX format abstraction library, with focus on the the main SDMX standard XML format (SDMX-ML), and the support of the three format standard versions (``1.0``, ``2.0``, ``2.1``) * an interface to SDMX web-services for a list of well-known data providers, such as OECD, EUROSTAT, ECB, UN FAO, UN ILO, etc (a list that should grow in a near future!). See it [in action](https://github.com/opensdmx/rsdmx/blob/master/vignettes/quickstart.Rmd#using-the-helper-approach)! Let's see then how to use ``rsdmx``! ## Install rsdmx ``rsdmx`` can be installed from CRAN or from its development repository hosted in Github. For the latter, you will need the ``devtools`` package and run: ```{r, eval=FALSE} devtools::install_github("opensdmx/rsdmx") ``` ## Load rsdmx To load rsdmx in R, do the following: ```{r} library(rsdmx) ``` ## Read dataset documents This section will introduce you on how to read SDMX *dataset* documents, either from _remote_ datasources, or from _local_ SDMX files. ### Read _remote_ datasets #### using the _raw_ approach (specifying the complete request URL) The following code snipet shows you how to read a dataset from a remote data source, taking as example the [OECD StatExtracts portal](http://stats.oecd.org): [http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011](http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011) ```{r} myUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011" dataset <- readSDMX(myUrl) stats <- as.data.frame(dataset) ``` You can try it out with other datasources, such as from the [**EUROSTAT portal**](http://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1): [http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011](http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011) The online rsdmx documentation also provides a list of data providers, either from international or national institutions, and [more request examples](https://github.com/opensdmx/rsdmx/wiki#read-remote-datasets). #### using the _helper_ approach Now, the service providers above mentioned are known by ``rsdmx`` which let users using ``readSDMX`` with the helper parameters. The list of service providers can be retrieved doing: ```{r} providers <- getSDMXServiceProviders(); as.data.frame(providers) ``` Note it is also possible to add an SDMX service provider at runtime. For registering a new SDMX service provider by default, please contact me! Let's see how it would look like for querying an ``OECD`` datasource: ```{r, message = FALSE} sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG", key = list("TOT", NULL, NULL), start = 2010, end = 2011) df <- as.data.frame(sdmx) head(df) ``` ### Read _local_ datasets This example shows you how to use ``rsdmx`` with _local_ SDMX files, previously downloaded from [EUROSTAT](http://ec.europa.eu/eurostat). ```{r} #bulk download from Eurostat tf <- tempfile(tmpdir = tdir <- tempdir()) #temp file and folder download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf) sdmx_files <- unzip(tf, exdir = tdir) #read local SDMX (set isURL = FALSE) sdmx <- readSDMX(sdmx_files[2], isURL = FALSE) stats <- as.data.frame(sdmx) ``` By default, ``readSDMX`` considers the data source is remote. To read a local file, add ``isURL = FALSE``. ## Read metadata documents This section will introduce you on how to read SDMX **metadata** documents, including ``concepts``, ``codelists`` and a complete ``data structure definition`` (DSD) ### Concepts Read concept schemes from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r, warning=FALSE} csUrl <- "http://data.fao.org/sdmx/registry/conceptscheme/FAO/ALL/LATEST/?detail=full&references=none&version=2.1" csobj <- readSDMX(csUrl) csdf <- as.data.frame(csobj) ``` ### Codelists Read codelists from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r} clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1" clobj <- readSDMX(clUrl) cldf <- as.data.frame(clobj) ``` ###Data Structure Definition (DSD) This example illustrates how to read a complete DSD using a [OECD StatExtracts portal](http://stats.oecd.org) data source. ```{r} dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1" dsd <- readSDMX(dsdUrl) ``` ``rsdmx`` is implemented in object-oriented way with ``S4`` classes and methods. The properties of ``S4`` objects are named ``slots`` and can be accessed with the ``slot`` method. The following code snippet allows to extract the list of ``codelists`` contained in the DSD document, and read one codelist as ``data.frame``. ```{r} #get codelists from DSD cls <- slot(dsd, "codelists") #get list of codelists codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id")) #get a codelist codelist <- as.data.frame(slot(dsd, "codelists"), codelistId = "CL_TABLE1_FLOWS") ``` In a similar way, the ``concepts`` of the dataset can be extracted from the DSD and read as ``data.frame``. ```{r} #get concepts from DSD concepts <- as.data.frame(slot(dsd, "concepts")) ``` rsdmx/README.md0000644000176200001440000003433212654150565012704 0ustar liggesusers**rsdmx** ======= [![Build Status](https://travis-ci.org/opensdmx/rsdmx.svg?branch=master)](https://travis-ci.org/opensdmx/rsdmx) [![codecov.io](http://codecov.io/github/opensdmx/rsdmx/coverage.svg?branch=master)](http://codecov.io/github/opensdmx/rsdmx?branch=master) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/rsdmx)](http://cran.r-project.org/package=rsdmx) [![Github_Status_Badge](https://img.shields.io/badge/Github-0.5--1-blue.svg)](https://github.com/opensdmx/rsdmx) ``rsdmx``: Tools for reading SDMX data and metadata documents in R ## Overview ``rsdmx`` is a package to parse/read SDMX data and metadata in R. It provides: * a set of classes and methods to read data and metadata documents exchanged through the Statistical Data and Metadata Exchange (SDMX) framework. The package currently focuses on the SDMX XML standard format (SDMX-ML). * an interface to SDMX web-services for a list of well-known data providers, such as EUROSTAT, OECD, and others [Learn more](https://github.com/opensdmx/rsdmx/wiki#package_overview). **Collating scattered SDMX data sources** In spite they are some R package initiatives relying on ``rsdmx`` that aim to provide a wrapper for a _single data source_ (e.g. OECD, EUROSTAT), it is strongly recommended to rely directly on ``rsdmx``. Indeed, one main objective of ``rsdmx`` is to **promote and facilitate collating scattered data** from a growing number of SDMX data providers, whatever the organization. It is already possible to query well-known datasources, using the embedded [helpers](https://github.com/opensdmx/rsdmx/blob/master/vignettes/quickstart.Rmd#using-the-helper-approach). Pull requests are welcome to support additional data providers by default in ``rsdmx``. **SDMX standards compliance** [![SDMX_Compliance_Badge_1.0](https://img.shields.io/badge/SDMX--ML-1.0-blue.svg)](https://github.com/opensdmx/rsdmx) [![SDMX_Compliance_Badge_2.0](https://img.shields.io/badge/SDMX--ML-2.0-blue.svg)](https://github.com/opensdmx/rsdmx) [![SDMX_Compliance_Badge_2.1](https://img.shields.io/badge/SDMX--ML-2.1-blue.svg)](https://github.com/opensdmx/rsdmx) **Status** At now, the package allows to read: * Datasets (``GenericData``, ``CompactData``, ``StructureSpecificData``, ``UtilityData`` and ``MessageGroup`` SDMX-ML types) * Concepts (``Concept``, ``ConceptScheme`` and ``Concepts`` SDMX-ML types) * Codelists (``Code``, ``Codelist`` and ``Codelists`` SDMX-ML types) * DataStructures / KeyFamilies - with all subtypes * Data Structure Definitions (DSDs) - with all subtypes **Fundings** ``rsdmx`` is looking for **[sponsors](https://github.com/opensdmx/rsdmx/wiki#package_development_funding)**. You have been using ``rsdmx`` and you wish to support its development? Please help us to make the package growing! **Citation**: We thank in advance people that use ``rsdmx`` for citing it in their work / publication(s). For this, please use the citation provided at this link [![DOI](https://zenodo.org/badge/5183/opensdmx/rsdmx.svg)](https://zenodo.org/badge/latestdoi/5183/opensdmx/rsdmx) **R CRAN rsdmx check results:** [http://cran.r-project.org/web/checks/check_results_rsdmx.html](http://cran.r-project.org/web/checks/check_results_rsdmx.html) Please note that following a new submission to CRAN, or eventually a modification of CRAN policies, the package might be temporarily archived, and removed from CRAN. In case you notice that the package is not back in few time, please contact me. **Mailing list:
** [https://groups.google.com/forum/#!forum/rsdmx](https://groups.google.com/forum/#!forum/rsdmx)
You can subscribe directly in the google group, or by email: [rsdmx+subscribe@googlegroups.com](rsdmx+subscribe@googlegroups.com) To send a post, use: [rsdmx@googlegroups.com](rsdmx@googlegroups.com) To unsubscribe, send an email to: [rsdmx+unsubscribe@googlegroups.com](rsdmx+unsubscribe@googlegroups.com) ## Quickstart [rsdmx](http://cran.r-project.org/package=rsdmx) offers a low-level set of tools to read **data** and **metadata** in SDMX format. Its strategy is to make it very easy for the user. For this, a unique function named ``readSDMX`` has to be used, whatever it is a ``data`` or ``metadata`` document, or if it is ``local`` or ``remote`` datasource. It is important to highlight that one of the major benefits of ``rsdmx`` is to focus first on the SDMX **format** specifications (acting as format abstraction library). This allows ``rsdmx`` reading SDMX data from _remote_ datasources, or from _local_ SDMX files. For accessing _remote_ datasources, it also means that ``rsdmx`` does not bound to SDMX **service** specifications, and can read a wider ranger of datasources. ### Install rsdmx ``rsdmx`` can be installed from CRAN ```{r, echo = FALSE} install.packages("rsdmx") ``` or from its development repository hosted in Github (using the ``devtools`` package): ```{r, echo = FALSE} devtools::install_github("opensdmx/rsdmx") ``` ### Load rsdmx To load rsdmx in R, do the following: ```{r, echo = FALSE} library(rsdmx) ``` ### readSDMX & helper functions #### readSDMX as low-level function The ``readSDMX`` function is then first designed at low-level so it can take as parameters a _url_ (``isURL=TRUE`` by default) or a _file_. So wherever is located the SDMX document, ``readSDMX`` will allow you to read it, as follows: ```{r, echo = FALSE} #read a remote file sdmx <- readSDMX(file = "someUrl") #read a local file sdmx <- readSDMX(file = "somelocalfile", isURL = FALSE) ``` In addition, in order to facilitate querying datasources, ``readSDMX`` also providers helpers to query well-known remote datasources. This allows not to specify the entire URL, but rather specify a simple provider ID, and the different parameters to build a SDMX query (e.g. for a dataset query: operation, key, filter, startPeriod and endPeriod). This is made possible as a list of SDMX service providers is embedded within ``rsdmx``, and such list provides all the information required for ``readSDMX`` to build the SDMX request (url) before accessing the datasource. #### get list of SDMX service providers The list of known SDMX service providers can be queried as follows: ```{r, echo = FALSE} providers <- getSDMXServiceProviders() as.data.frame(providers) ``` #### create/add a SDMX service provider It also also possible to create and add a new SDMX service providers in this list (so ``readSDMX`` can be aware of it). A provider can be created with the ``SDMXServiceProvider``, and is made of five parameters: an ``agencyId``, its ``name``, ``scale`` (international or national), a ``country`` ISO 3-alpha code (if national) and a request ``builder``. The request builder can be created with ``SDMXRequestBuilder`` which takes 3 arguments: the ``baseUrl`` of the service endpoint, a ``handler`` function which will allow to build the web request, and a ``compliant`` logical parameter (either the request builder is compliant with some web-service specifications), . ``rsdmx`` intends to provider specific request builder that embedds yet an handler function (not need to implement it), and is now attempting to provide a ``SDMXRESTRequestBuilder`` to build SDMX REST web-requests. All this is still under experiments. Let's see it with an example: First create a request builder for our provider: ```{r, echo = FALSE} myBuilder <- SDMXRequestBuilder( regUrl = "http://www.myorg.org/sdmx/registry", repoUrl = "http://www.myorg.org/sdmx/repository", handler = function(baseUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant){ paste(baseUrl, agencyId, resource, flowRef, key, start, end, sep="/") }, compliant = FALSE ) ``` As you can see, we built a handler that will be in charge of creating a web-request such as [http://www.myorg.org/sdmx/agencyId/resource/flowRef/key/start/end](http://www.myorg.org/sdmx/agencyId/resource/flowRef/key/start/end) We can create a provider with the above request builder, and add it to the list of known SDMX service providers: ```{r, echo = FALSE} #create the provider provider <- SDMXServiceProvider( agencyId = "MYORG", name = "My Organization", builder = myBuilder ) #add it to the list addSDMXServiceProvider(provider) #check provider has been added as.data.frame(getSDMXServiceProviders()) ``` #### find a SDMX service provider A another helper allows you to interrogate ``rsdmx`` if a specific provider is known, given an id: ```{r, echo = FALSE} oecd <- findSDMXServiceProvider("OECD") ``` #### readSDMX as helper function Now you know how to add a SDMX provider, you can consider using ``readSDMX`` without having to specifying a entire URL, but just by specifying the ``agencyId`` of the provider, and the different query parameters to reach your SDMX document: ```{r, echo = FALSE} sdmx <- readSDMX(agencyId = "MYORG", resource = "data", flowRef="MYSERIE", key = "all", key.mode = "SDMX", start = 2000, end = 2015) ``` The following sections will show you how to query SDMX documents, by using ``readSDMX`` in different ways: either for _local_ or _remote_ files, using ``readSDMX`` as low-level or with the helpers. ### Read dataset documents This section will introduce you on how to read SDMX *dataset* documents. #### Read _remote_ datasets The following code snipet shows you how to read a dataset from a remote data source, taking as example the [OECD StatExtracts portal](http://stats.oecd.org): [http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011](http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011) ```{r, echo = FALSE} myUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/MIG/TOT../OECD?startTime=2000&endTime=2011" dataset <- readSDMX(myUrl) stats <- as.data.frame(dataset) ``` You can try it out with other datasources, such as: * [**EUROSTAT portal**](http://ec.europa.eu/eurostat/web/sdmx-web-services/rest-sdmx-2.1): [http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011](http://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/cdh_e_fos/..PC.FOS1.BE/?startperiod=2005&endPeriod=2011) * [**European Central Bank (ECB)**](https://sdw-wsrest.ecb.europa.eu): [https://sdw-wsrest.ecb.europa.eu/service/data/DD/M.SE.BSI_STF.RO.4F_N](https://sdw-wsrest.ecb.europa.eu/service/data/DD/M.SE.BSI_STF.RO.4F_N) * [**UN International Labour Organization (ILO)**](http://www.ilo.org/ilostat/faces/home/statisticaldata/technical_page?_adf.ctrl-state=25zdozvi8_9&_afrLoop=1131342564621899): [http://www.ilo.org/ilostat/sdmx/ws/rest/data/ILO,DF_CPI_FRA_CPI_TCPI_COI_RT/ALL?startPeriod=2000-01-01&endPeriod=2014-12-31](http://www.ilo.org/ilostat/sdmx/ws/rest/data/ILO,DF_CPI_FRA_CPI_TCPI_COI_RT/ALL?startPeriod=2000-01-01&endPeriod=2014-12-31) The online rsdmx documentation also provides a list of data providers, either from international or national institutions. Now, the service providers above mentioned are known by ``rsdmx`` which let users using ``readSDMX`` with the helper parameters. Let's see how it would look like for querying an OECD datasource: ```{r, echo = FALSE} sdmx <- readSDMX(agencyId = "OECD", resource = "data", flowRef = "MIG", key = list("TOT", NULL, NULL), start = 2010, end = 2011) df <- as.data.frame(sdmx) head(df) ``` #### Read _local_ datasets This example shows you how to use ``rsdmx`` with _local_ SDMX files, previously downloaded from [EUROSTAT](http://ec.europa.eu/eurostat). ```{r, echo = FALSE} #bulk download from Eurostat tf <- tempfile(tmpdir = tdir <- tempdir()) #temp file and folder download.file("http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Frd_e_gerdsc.sdmx.zip", tf) sdmx_files <- unzip(tf, exdir = tdir) sdmx <- readSDMX(sdmx_files[2], isURL = FALSE) stats <- as.data.frame(sdmx) head(stats) ``` By default, ``readSDMX`` considers the data source is remote. To read a local file, add ``isURL = FALSE``. ### Read metadata documents This section will introduce you on how to read SDMX **metadata** documents, including ``concepts``, ``codelists`` and complete ``data structure definitions`` (DSD) #### Concepts Read concept schemes from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r, echo = FALSE} csUrl <- "http://data.fao.org/sdmx/registry/conceptscheme/FAO/ALL/LATEST/?detail=full&references=none&version=2.1" csobj <- readSDMX(csUrl) csdf <- as.data.frame(csobj) head(csdf) ``` #### Codelists Read codelists from [FAO data portal](http://data.fao.org/sdmx/index.html) ```{r, echo = FALSE} 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) ``` #### Data Structures (Key Families) This example illustrates how to read the complete list of data structures (or key families) from the [OECD StatExtracts portal](http://stats.oecd.org) ```{r, echo = FALSE} dsUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/ALL" ds <- readSDMX(dsUrl) dsdf <- as.data.frame(ds) head(dsdf) ``` #### Data Structure Definition (DSD) This example illustrates how to read a complete DSD using a [OECD StatExtracts portal](http://stats.oecd.org) data source. ```{r, echo = FALSE} dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1" dsd <- readSDMX(dsdUrl) ``` ``rsdmx`` is implemented in object-oriented way with ``S4`` classes and methods. The properties of ``S4`` objects are named ``slots`` and can be accessed with the ``slot`` method. The following code snippet allows to extract the list of ``codelists`` contained in the DSD document, and read one codelist as ``data.frame``. ```{r, echo = FALSE} #get codelists from DSD cls <- slot(dsd, "codelists") codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id")) #get list of codelists codelist <- as.data.frame(slot(dsd, "codelists"), codelistId = "CL_TABLE1_FLOWS") #get a codelist ``` In a similar way, the ``concepts`` of the dataset can be extracted from the DSD and read as ``data.frame``. ```{r, echo = FALSE} #get concepts from DSD concepts <- as.data.frame(slot(dsd, "concepts")) ``` rsdmx/build/0000755000176200001440000000000012654151640012512 5ustar liggesusersrsdmx/build/vignette.rds0000644000176200001440000000032312654151640015047 0ustar liggesusersb```b`fbb`b2 1# '+,L..I,* MA+*NɭP@QH/LIESŏdFFIn4@ j I-k^bnj1.y) 3GZY_Ӄ -3'foHf e2|s  =XQĒD"~e#rsdmx/DESCRIPTION0000644000176200001440000000560412654245164013133 0ustar liggesusersPackage: rsdmx Version: 0.5-1 Date: 2016-01-19 Title: Tools for Reading SDMX Data and Metadata Authors@R: c( person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com"), person("Matthieu", "Stigler", role = c("ctb"))) Maintainer: Emmanuel Blondel Depends: R (>= 2.15) Imports: methods, XML (>= 3.96-1.1), RCurl, plyr, utils Suggests: testthat, knitr Description: Set of classes and methods to read data and metadata documents exchanged through the Statistical Data and Metadata Exchange (SDMX) framework, currently focusing on the SDMX XML standard format (SDMX-ML). License: GPL (>= 2) VignetteBuilder: knitr URL: https://github.com/opensdmx/rsdmx, http://www.sdmx.org BugReports: https://github.com/opensdmx/rsdmx/issues LazyLoad: yes Encoding: UTF-8 Collate: Class-SDMXSchema.R Class-SDMXType.R Class-SDMXStructureType.R Class-SDMXHeader.R Class-SDMXFooterMessage.R Class-SDMXFooter.R Class-SDMX.R Class-SDMXGenericData.R Class-SDMXCompactData.R Class-SDMXUtilityData.R Class-SDMXStructureSpecificData.R Class-SDMXCrossSectionalData.R Class-SDMXMessageGroup.R Class-SDMXConcept.R Class-SDMXConceptScheme.R Class-SDMXConcepts.R Class-SDMXCode.R Class-SDMXCodelist.R Class-SDMXCodelists.R Class-SDMXDimension.R Class-SDMXTimeDimension.R Class-SDMXPrimaryMeasure.R Class-SDMXAttribute.R Class-SDMXComponents.R Class-SDMXDataStructure.R Class-SDMXDataStructures.R Class-SDMXDataStructureDefinition.R Class-SDMXDataFlow.R Class-SDMXDataFlows.R Class-SDMXRequestBuilder.R Class-SDMXRESTRequestBuilder.R Class-SDMXServiceProvider.R Class-SDMXServiceProviders.R SDMXSchema-methods.R SDMXType-methods.R SDMXStructureType-methods.R SDMXHeader-methods.R SDMXFooterMessage-methods.R SDMXFooter-methods.R SDMX-methods.R SDMXGenericData-methods.R SDMXCompactData-methods.R SDMXUtilityData-methods.R SDMXStructureSpecificData-methods.R SDMXCrossSectionalData-methods.R SDMXMessageGroup-methods.R SDMXConcept-methods.R SDMXConceptScheme-methods.R SDMXConcepts-methods.R SDMXCode-methods.R SDMXCodelist-methods.R SDMXCodelists-methods.R SDMXDimension-methods.R SDMXTimeDimension-methods.R SDMXPrimaryMeasure-methods.R SDMXAttribute-methods.R SDMXComponents-methods.R SDMXDataStructure-methods.R SDMXDataStructures-methods.R SDMXDataStructureDefinition-methods.R SDMXDataFlow-methods.R SDMXDataFlows-methods.R SDMXRequestBuilder-methods.R SDMXRESTRequestBuilder-methods.R SDMXServiceProvider-methods.R SDMXServiceProviders-methods.R readSDMX.R profile.R rsdmx.R NeedsCompilation: no Packaged: 2016-02-02 16:04:55 UTC; Emmanuel Author: Emmanuel Blondel [aut, cre], Matthieu Stigler [ctb] Repository: CRAN Date/Publication: 2016-02-03 01:31:48 rsdmx/man/0000755000176200001440000000000012654150565012173 5ustar liggesusersrsdmx/man/SDMXRequestBuilder.Rd0000644000176200001440000000517712654150565016127 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXRequestBuilder.R, R/SDMXRequestBuilder-methods.R \docType{class} \name{SDMXRequestBuilder} \alias{SDMXRequestBuilder} \alias{SDMXRequestBuilder,SDMXRequestBuilder-method} \alias{SDMXRequestBuilder-class} \title{Class "SDMXRequestBuilder"} \usage{ SDMXRequestBuilder(regUrl, repoUrl, handler, compliant) } \arguments{ \item{regUrl}{an object of class "character" giving the base Url of the SDMX service registry} \item{repoUrl}{an object of class "character" giving the base Url of the SDMX service repository} \item{handler}{an object of class "function" that will be in charge of build a web request.} \item{compliant}{an object of class "logical" indicating if the request builder is somehow compliant with a service specification} } \description{ A basic class to handle a SDMX service request builder } \details{ The \code{handler} function must have the following structure in term of arguments (baseUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant) and output (a string representing the web request to build). The rsdmx package will as much as possible try to handler generic handlers, e.g. an handler for SDMX REST web-services. For the latter example, a specific builder is provided and made part of the specific and still experimental \link{SDMXRESTRequestBuilder}. } \section{Slots}{ \describe{ \item{\code{regUrl}}{an object of class "character" giving the base Url of the SDMX service registry} \item{\code{repoUrl}}{an object of class "character" giving the base Url of the SDMX service repository} \item{\code{handler}}{an object of class "function" that will be in charge of build a web request.} \item{\code{compliant}}{an object of class "logical" indicating if the request builder is somehow compliant with a service specification} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \examples{ #an handler myHandler <- function(baseUrl, agencyId, resource, resourceId, version, flowRef, key, start, end, compliant){ req <- paste(baseUrl, agencyId, resource, flowRef, key, start, end, sep="/") return(req) } #how to create a SDMXRequestBuilder requestBuilder <- SDMXRequestBuilder( regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", handler = myHandler, compliant = FALSE) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } rsdmx/man/SDMXFooter.Rd0000644000176200001440000000257412654150565014424 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXFooter.R, R/SDMXFooter-methods.R \docType{class} \name{SDMXFooter} \alias{SDMXFooter} \alias{SDMXFooter,SDMXFooter-method} \alias{SDMXFooter-class} \title{Class "SDMXFooter"} \usage{ SDMXFooter(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXFooter" } \description{ A basic class to handle the footer of a SDMX-ML document } \section{Slots}{ \describe{ \item{\code{messages}}{Object of class "SDMXFooterMessage" giving the list of messages} }} \note{ This class is especially useful for SDMX 2.1 compliant documents. Footer messages are not supported in SDMX 2.0standard format. In this case, the footer will return an empty message list(). According to the SDMX 2.1 standard, the message severity takes one of the following values: "Error", "Warning","Information". Given the possible typos handled by data providers, rsdmx adopts a permissive strategy and does not validate the object according to such controlled terms. } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXConceptScheme.Rd0000644000176200001440000000375512654150564015707 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXConceptScheme.R, R/SDMXConceptScheme-methods.R \docType{class} \name{SDMXConceptScheme} \alias{SDMXConceptScheme} \alias{SDMXConceptScheme,SDMXConceptScheme-method} \alias{SDMXConceptScheme-class} \title{Class "SDMXConceptScheme"} \usage{ SDMXConceptScheme(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXConceptScheme" } \description{ A basic class to handle a SDMX Concept scheme } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID of the concept scheme (required)} \item{\code{agencyID}}{Object of class "character" giving the AgencyID} \item{\code{version}}{Object of class "character" giving the version} \item{\code{uri}}{Object of class "character" giving the concept uri} \item{\code{urn}}{Object of class "character" giving the concept urn} \item{\code{isExternalReference}}{Object of class "logical" indicating if the concept scheme is an external reference} \item{\code{isFinal}}{Object of class "logical" indicating if the concept scheme is final} \item{\code{validFrom}}{Object of class "character" indicating the start validity period} \item{\code{validTo}}{Object of class "character" indicating the end validity period} \item{\code{Name}}{Object of class "list" giving the concept scheme name (by language) - required} \item{\code{Description}}{Object of class "list" giving the concept scheme description (by language)} \item{\code{Concept}}{Object of class "list" giving the list of "SDMXConcept" objects (see \link{SDMXConcept})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXConcept.Rd0000644000176200001440000000357612654150564014563 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXConcept.R, R/SDMXConcept-methods.R \docType{class} \name{SDMXConcept} \alias{SDMXConcept} \alias{SDMXConcept,SDMXConcept-method} \alias{SDMXConcept-class} \title{Class "SDMXConcept"} \usage{ SDMXConcept(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXConcept" } \description{ A basic class to handle a SDMX Concept } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID of the concept (required)} \item{\code{agencyID}}{Object of class "character" giving the AgencyID} \item{\code{version}}{Object of class "character" giving the concept version} \item{\code{uri}}{Object of class "character" giving the concept uri} \item{\code{urn}}{Object of class "character" giving the concept urn} \item{\code{isExternalReference}}{Object of class "logical" indicating if the concept is an external reference} \item{\code{coreRepresentation}}{Object of class "character" giving the core representation} \item{\code{coreRepresentationAgency}}{Object of class "character" giving the core representation agency} \item{\code{parent}}{Object of class "character" giving the concept parent} \item{\code{parentAgency}}{Object of class "character" giving the parentAgency} \item{\code{Name}}{Object of class "list" giving the concept name (by language) - required} \item{\code{Description}}{Object of class "list" giving the concept description (by language)} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/setSDMXServiceProviders.Rd0000644000176200001440000000163012654150565017170 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMXServiceProvider-methods.R \name{setSDMXServiceProviders} \alias{setSDMXServiceProviders} \title{setSDMXServiceProviders} \usage{ setSDMXServiceProviders() } \description{ function used internally by \pkg{rsdmx}, when loading the package, to set the list of \link{SDMXServiceProvider} known by \pkg{rsdmx} (hence known by \link{readSDMX} to query data/metadata in an easier way). For internal use only (this function does not provide any value for the end user, but it is here documented for transparency, and to explain how the package works.) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{getSDMXServiceProviders} \link{addSDMXServiceProvider} \link{findSDMXServiceProvider} \link{readSDMX} } rsdmx/man/SDMXRESTRequestBuilder.Rd0000644000176200001440000000471212654150565016617 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXRESTRequestBuilder.R, R/SDMXRESTRequestBuilder-methods.R \docType{class} \name{SDMXRESTRequestBuilder} \alias{SDMXRESTRequestBuilder} \alias{SDMXRESTRequestBuilder,SDMXRESTRequestBuilder-method} \alias{SDMXRESTRequestBuilder-class} \title{Class "SDMXRESTRequestBuilder"} \usage{ SDMXRESTRequestBuilder(regUrl, repoUrl, compliant, unsupportedResources, skipAgencyId, forceAgencyId) } \arguments{ \item{regUrl}{an object of class "character" giving the base Url of the SDMX service registry} \item{repoUrl}{an object of class "character" giving the base Url of the SDMX service repository} \item{compliant}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications} \item{unsupportedResources}{an object of class "list" giving eventual unsupported REST resources. Default is an empty list object} \item{skipAgencyId}{an object of class "logical" indicating that agencyId should be skipped. Used to control lack of strong SDMX REST compliance from data providers. For now, it applies only for the "data" resource.} \item{forceAgencyId}{an object of class "logical" indicating if the agencyId as to be added at the end of the request. Default value is \code{FALSE}. For some providers, the \code{all} value for the \code{agencyId} is not allowed, in this case, the \code{agencyId} of the data provider has to be forced in the web-request} } \description{ A experimental class to handle a SDMX 2.1 service request builder } \section{Slots}{ \describe{ \item{\code{regUrl}}{an object of class "character" giving the base Url of the SDMX service registry} \item{\code{repoUrl}}{an object of class "character" giving the base Url of the SDMX service repository} \item{\code{compliant}}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \examples{ #how to create a SDMXRESTRequestBuilder requestBuilder <- SDMXRESTRequestBuilder( regUrl = "http://www.myorg/registry", repoUrl = "http://www.myorg/repository", compliant = TRUE) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } rsdmx/man/SDMXSchema.Rd0000644000176200001440000000161612654150565014362 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXSchema.R, R/SDMXSchema-methods.R \docType{class} \name{SDMXSchema} \alias{SDMXSchema} \alias{SDMXSchema,SDMXSchema-method} \alias{SDMXSchema-class} \title{Class "SDMXSchema"} \usage{ SDMXSchema(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXSchema" } \description{ A basic class to handle the version of the SDMX-ML Schema } \section{Slots}{ \describe{ \item{\code{version}}{Object of class "character" giving the SDMX-ML schema version} }} \section{Warning}{ this class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/findNamespace.Rd0000644000176200001440000000173112654150564015220 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMX-methods.R \name{findNamespace} \alias{findNamespace} \title{findNamespace} \usage{ findNamespace(namespaces, messageType) } \arguments{ \item{namespaces}{object of class \code{data.frame} giving the id and uri of namespaces available in a SDMX-ML object, typically obtained with \link{getNamespaces}} \item{messageType}{object of class \code{character} representing a message type} } \value{ an object of class "character" giving the namespace uri if found in the available namespaces } \description{ function used to find a specific namespace within the available namespaces of an SDMX-ML object } \section{Warning}{ \code{findNamespace} is a function used internally as utility function in SDMX-ML object parsers. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{SDMX-class} \link{getNamespaces} } rsdmx/man/getSoapRequestResult.Rd0000644000176200001440000000133712654150564016637 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMX-methods.R \name{getSoapRequestResult} \alias{getSoapRequestResult} \title{getSoapRequestResult} \usage{ getSoapRequestResult(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "XMLInternalDocument derived from XML package } \description{ function used to extract the SDMX-ML message from a SOAP request response } \section{Warning}{ \code{getSoapRequestResult} is a function used internally by \link{readSDMX} } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{SDMX-class} \link{readSDMX} } rsdmx/man/SDMX.Rd0000644000176200001440000000277512654150564013247 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMX.R, R/SDMX-methods.R \docType{class} \name{SDMX} \alias{SDMX} \alias{SDMX,SDMX-method} \alias{SDMX-class} \title{Class "SDMX"} \usage{ SDMX(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMX" } \description{ An abstract class from which SDMX classes are derived } \section{Slots}{ \describe{ \item{\code{xmlObj}}{Object of class "XMLInternalDocument" derived from XML package} \item{\code{schema}}{Object of class "SDMXSchema", handles the version of SDMX-ML format} \item{\code{header}}{Object of class "SDMXHeader", handles the SDMX-ML document header} \item{\code{footer}}{Object of class "SDMXFooter", handles the SDMX-ML document footer} }} \note{ Currently, the approach drafted in \link{rsdmx} package was to rely on XML package, read the xml object and store it as part of the SDMX R object. Another approach being investigated is to use XML handlers throughthe Simple API for XML (SAX) that could avoid to load the full XML tree in the SDMX R object (xmlObj). Indeed, SDMX data could be huge and causes issues of memory if the complete XML tree is loaded in the R user session. } \section{Warning}{ This class is not useful in itself, but all SDMX classes in this package derive from it. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXUtilityData.Rd0000644000176200001440000000150312654150565015412 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXUtilityData.R, R/SDMXUtilityData-methods.R \docType{class} \name{SDMXUtilityData} \alias{SDMXUtilityData} \alias{SDMXUtilityData,SDMXUtilityData-method} \alias{SDMXUtilityData-class} \title{Class "SDMXUtilityData"} \usage{ SDMXUtilityData(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXUtilityData" } \description{ A basic class to handle a SDMX-ML UtilityData data set } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXDataStructures.Rd0000644000176200001440000000206312654150564016133 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDataStructures.R, R/SDMXDataStructures-methods.R \docType{class} \name{SDMXDataStructures} \alias{SDMXDataStructures} \alias{SDMXDataStructures,SDMXDataStructures-method} \alias{SDMXDataStructures-class} \title{Class "SDMXDataStructures"} \usage{ SDMXDataStructures(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDataStructures" } \description{ A basic class to handle a SDMX DataStructures (or KeyFamilies) } \section{Slots}{ \describe{ \item{\code{datastructures}}{Object of class "list" giving the list of DataStructures, (see \link{SDMXDataStructure})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXCodelist.Rd0000644000176200001440000000364412654150564014732 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXCodelist.R, R/SDMXCodelist-methods.R \docType{class} \name{SDMXCodelist} \alias{SDMXCodelist} \alias{SDMXCodelist,SDMXCodelist-method} \alias{SDMXCodelist-class} \title{Class "SDMXCodelist"} \usage{ SDMXCodelist(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXCodelist" } \description{ A basic class to handle a SDMX Codelist } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID of the codelist (required)} \item{\code{agencyID}}{Object of class "character" giving the AgencyID} \item{\code{version}}{Object of class "character" giving the version} \item{\code{uri}}{Object of class "character" giving the codelist uri} \item{\code{urn}}{Object of class "character" giving the codelist urn} \item{\code{isExternalReference}}{Object of class "logical" indicating if the codelist is an external reference} \item{\code{isFinal}}{Object of class "logical" indicating if the codelist is final} \item{\code{validFrom}}{Object of class "character" indicating the start validity period} \item{\code{validTo}}{Object of class "character" indicating the end validity period} \item{\code{Name}}{Object of class "list" giving the codelist (by language) - required} \item{\code{Description}}{Object of class "list" giving the codelist description (by language)} \item{\code{Code}}{Object of class "list" giving the list of "SDMXCode" objects included in the codelist (see \link{SDMXCode})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Codelists, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXComponents.Rd0000644000176200001440000000233612654150564015306 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXComponents.R, R/SDMXComponents-methods.R \docType{class} \name{SDMXComponents} \alias{SDMXComponents} \alias{SDMXComponents,SDMXComponents-method} \alias{SDMXComponents-class} \title{Class "SDMXComponents"} \usage{ SDMXComponents(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXComponents" } \description{ A basic class to handle SDMX Components } \section{Slots}{ \describe{ \item{\code{Dimensions}}{Object of class "list" giving the list of dimensions (see \link{SDMXDimension})} \item{\code{TimeDimension}}{Object of class "SDMXTimeDimension"} \item{\code{PrimaryMeasure}}{Object of class "SDMXPrimaryMeasure"} \item{\code{Attributes}}{Object of class "list" giving the list of attributes (see \link{SDMXAttribute})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (DataStructures, or DataStructureDefinitions) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXConcepts.Rd0000644000176200001440000000230612654150564014734 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXConcepts.R, R/SDMXConcepts-methods.R \docType{class} \name{SDMXConcepts} \alias{SDMXConcepts} \alias{SDMXConcepts,SDMXConcepts-method} \alias{SDMXConcepts-class} \title{Class "SDMXConcepts"} \usage{ SDMXConcepts(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXConcepts" } \description{ A basic class to handle SDMX Concepts } \section{Slots}{ \describe{ \item{\code{concepts}}{Object of class "list" giving the list of "SDMXConcept". This slot is available to ensure backward compatibility with SDMX 1.0 in SDMX 2.0 or 2.1 documents} \item{\code{conceptSchemes}}{Object of class "list" giving the list of "SDMXConceptScheme", which will encapsulate the list of "SDMXConcept" (defined from SDMX 2.0)} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/readSDMX.Rd0000644000176200001440000001255212654150564014075 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/readSDMX.R \name{readSDMX} \alias{readSDMX} \title{readSDMX} \usage{ readSDMX(file, isURL, provider, agencyId, resource, resourceId, version, flowRef, key, key.mode, start, end) } \arguments{ \item{file}{path to SDMX-ML document that needs to be parsed} \item{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 \code{readSDMX} is used with helpers (based on the embedded list of \code{SDMXServiceProvider})} \item{provider}{an object of class "SDMXServiceProvider". If specified, \code{file} and \code{isURL} arguments will be ignored.} \item{agencyId}{an object of class "character" representing a provider id. It has to be match a default provider as listed in\code{getSDMXServiceProviders()}} \item{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.} \item{resourceId}{an object of class "character" giving a SDMX service resource Id, e.g. the id of a data structure} \item{version}{an object of class "character" giving a SDMX resource version, e.g. the version of a dataflow.} \item{flowRef}{an object of class "character" giving the SDMX flow ref id. Recognized if valid provider or provide id has been specified as argument.} \item{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 \code{key.mode} is equal to \code{"R"} (default value), filter has to be an object of class "list" representing the filters to apply to the dataset, otherwise the filter will be a string.} \item{key.mode}{an object of class "character" indicating if the \code{key} has to be provided as an R object, ie a object of class "list" representing the filter(s) to apply. Default value is \code{"R"}. Alternative value is \code{"SDMX"}} \item{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.} \item{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" } \description{ \code{readSDMX} is the main function to use to read SDMX data } \examples{ # SDMX datasets #-------------- \dontrun{ # 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**) } \donttest{ # 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 #------------------------------- \donttest{ # 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 #--------------- \donttest{ # 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) #----------------------------------- \donttest{ # 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**) } } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } rsdmx/man/isSoapRequestEnvelope.Rd0000644000176200001440000000131112654150564016762 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMX-methods.R \name{isSoapRequestEnvelope} \alias{isSoapRequestEnvelope} \title{isSoapRequestEnvelope} \usage{ isSoapRequestEnvelope(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "logical" } \description{ function used to detect if the XML document corresponds to a SOAP request response } \section{Warning}{ \code{isSoapRequestEnvelope} is a function used internally by \link{readSDMX} } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{SDMX-class} \link{readSDMX} } rsdmx/man/SDMXTimeDimension.Rd0000644000176200001440000000366312654150565015732 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXTimeDimension.R, R/SDMXTimeDimension-methods.R \docType{class} \name{SDMXTimeDimension} \alias{SDMXTimeDimension} \alias{SDMXTimeDimension,SDMXTimeDimension-method} \alias{SDMXTimeDimension-class} \title{Class "SDMXTimeDimension"} \usage{ SDMXTimeDimension(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXTimeDimension" } \description{ A basic class to handle a SDMX TimeDimension } \section{Slots}{ \describe{ \item{\code{conceptRef}}{Object of class "character" giving the dimension conceptRef (required)} \item{\code{conceptVersion}}{Object of class "character" giving the dimension concept version} \item{\code{conceptAgency}}{Object of class "character" giving the dimension concept agency} \item{\code{conceptSchemeRef}}{Object of class "character" giving the dimension conceptScheme ref} \item{\code{conceptSchemeAgency}}{Object of class "character" giving the dimension conceptScheme agency} \item{\code{codelist}}{Object of class "character" giving the codelist ref name} \item{\code{codelistVersion}}{Object of class "character" giving the codelist ref version} \item{\code{codelistAgency}}{Object of class "character" giving the codelist ref agency} \item{\code{crossSectionalAttachDataset}}{Object of class "logical"} \item{\code{crossSectionalAttachGroup}}{Object of class "logical"} \item{\code{crossSectionalAttachSection}}{Object of class "logical"} \item{\code{crossSectionalAttachObservation}}{Object of class "logical"} }} \section{Warning}{ This class is not useful in itself, but non-abstract classes willencapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/rsdmx.Rd0000644000176200001440000000153412654150564013621 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/rsdmx.R \docType{package} \name{rsdmx} \alias{rsdmx} \alias{rsdmx-package} \title{Tools for Reading SDMX Data and Metadata} \description{ RSDMX is a package to parse/read SDMX documents in R. It provides: - a set of classes and methods to read data and metadata documents exchanged through theStatistical Data and Metadata Exchange (SDMX) framework. The package currently focuses on the SDMX XML standard format (SDMX-ML). - an web-service interface to well-known SDMX data providers } \details{ \tabular{ll}{ Package: \tab rsdmx\cr Type: \tab Package\cr Version : \tab 0.5-1\cr Date: \tab 2016-01-19\cr License: \tab GPL(>=2.0)\cr LazyLoad: \tab yes\cr } } \author{ Emmanuel Blondel \email{emmanuel.blondel1@gmail.com} } rsdmx/man/SDMXFooterMessage.Rd0000644000176200001440000000306112654150565015721 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXFooterMessage.R, R/SDMXFooterMessage-methods.R \docType{class} \name{SDMXFooterMessage} \alias{SDMXFooterMessage} \alias{SDMXFooterMessage,SDMXFooterMessage-method} \alias{SDMXFooterMessage-class} \title{Class "SDMXFooterMessage"} \usage{ SDMXFooterMessage(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXFooterMessage" } \description{ A basic class to handle a footer message of a SDMX-ML document } \section{Slots}{ \describe{ \item{\code{code}}{Object of class "character" giving the status code} \item{\code{severity}}{Object of class "character" giving the severity of the message} \item{\code{messages}}{Object of class "list" giving the list of messages} }} \note{ This class is especially useful for SDMX 2.1 compliant documents. Footer messages are not supported in SDMX 2.0 standard format. According to the SDMX 2.1 standard, the message severity takes one of the following values: "Error", "Warning",Information". Given the possible typos handled by data providers, rsdmx adopts a permissive strategy and does not validate the object according to such controlled terms. } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{SDMXFooter} \link{readSDMX} } rsdmx/man/getSDMXServiceProviders.Rd0000644000176200001440000000157112654150564017157 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMXServiceProvider-methods.R \name{getSDMXServiceProviders} \alias{getSDMXServiceProviders} \title{getSDMXServiceProviders} \usage{ getSDMXServiceProviders() } \value{ an object of class "list" (of \link{SDMXServiceProvider}) } \description{ function used to get the list of \link{SDMXServiceProvider} known by \pkg{rsdmx} (hence known by \link{readSDMX} to query data or metadata in an easier way). This function can be easily used to interrogate the list of known providers, and eventually consider adding one at runtime with \link{addSDMXServiceProvider} } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{addSDMXServiceProvider} \link{findSDMXServiceProvider} \link{readSDMX} } rsdmx/man/getStructureType-methods.Rd0000644000176200001440000000114312654150564017463 0ustar liggesusers\name{getStructureType-methods} \docType{methods} \alias{getStructureType,SDMXStructureType-method} \alias{getStructureType} \title{getStructureType} \description{Access the subtype of SDMXStructureType object} \usage{ getStructureType(obj) } \arguments{ \item{obj}{An object deriving from class "SDMXStructureType"} } \section{Methods}{ \describe{ \item{obj}{An object deriving from class "SDMXStructureType"} }} \value{an object of class "character"} \author{Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com}} \keyword{methods} \seealso{\link{SDMXStructureType-class}} rsdmx/man/SDMXDataStructureDefinition.Rd0000644000176200001440000000263712654150564017770 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDataStructureDefinition.R, R/SDMXDataStructureDefinition-methods.R \docType{class} \name{SDMXDataStructureDefinition} \alias{SDMXDataStructureDefinition} \alias{SDMXDataStructureDefinition,SDMXDataStructureDefinition-method} \alias{SDMXDataStructureDefinition-class} \title{Class "SDMXDataStructureDefinition"} \usage{ SDMXDataStructureDefinition(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDataStructureDefinition" } \description{ A basic class to handle a SDMX DataStructureDefinition (DSD) } \section{Slots}{ \describe{ \item{\code{concepts}}{Object of class "SDMXConcepts" giving the list of concepts or conceptSchemes (see \link{SDMXConcepts})} \item{\code{codelists}}{Object of class "SDMXCodelists" giving the list of codelists (see \link{SDMXCodelists})} \item{\code{datastructures}}{Object of class "SDMXDataStructures" giving the list of datastructures /key families (see \link{SDMXDataStructures})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXCrossSectionalData.Rd0000644000176200001440000000135512654150564016706 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXCrossSectionalData.R, R/SDMXCrossSectionalData-methods.R \docType{class} \name{SDMXCrossSectionalData} \alias{SDMXCrossSectionalData} \alias{SDMXCrossSectionalData,SDMXCrossSectionalData-method} \alias{SDMXCrossSectionalData-class} \title{Class "SDMXCrossSectionalData"} \usage{ SDMXCrossSectionalData(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXCrossSectionalData" } \description{ A basic class to handle a SDMX-ML cross sectional data set } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXHeader.Rd0000644000176200001440000000432012654150565014345 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXHeader.R, R/SDMXHeader-methods.R \docType{class} \name{SDMXHeader} \alias{SDMXHeader} \alias{SDMXHeader,SDMXHeader-method} \alias{SDMXHeader-class} \title{Class "SDMXHeader"} \usage{ SDMXHeader(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXHeader" } \description{ A basic class to handle the header of a SDMX-ML document } \section{Slots}{ \describe{ \item{\code{ID}}{Object of class "character" giving the ID of the SDMX-ML document} \item{\code{Test}}{Object of class "logical" indicating if the SDMX-ML document is disseminated for test purpose} \item{\code{Truncated}}{Object of class "logical" indicating if the SDMX-ML document is truncated} \item{\code{Name}}{Object of class "character" giving the name of SDMX-ML document} \item{\code{Sender}}{Object of class "list" giving the id of the sender and eventually its in name, possibly in multi-languages} \item{\code{Receiver}}{Object of class "list" giving the id of the receiver and eventually its in name, possibly in multi-languages} \item{\code{Prepared}}{Object of class "POSIXlt" giving the preparation date of the SDMX-ML document} \item{\code{Extracted}}{Object of class "POSIXlt" giving the extraction date of the SDMX-ML document} \item{\code{ReportingBegin}}{Object of class "POSIXlt" giving the reporting begin date for the data retrieved in the SDMX-ML document} \item{\code{ReportingEnd}}{Object of class "POSIXlt" giving the reporting end date for the data retrieved in the SDMX-ML document} \item{\code{Source}}{Object of class "character" giving the source of the SDMX-ML document} }} \note{ Some SDMXHeader properties are not yet supported and thus not available as "slots". These are "KeyFamilyRef", "KeyFamilyAgency", "DataSetAgency", "DataSetID", "DataSetAction". } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXPrimaryMeasure.Rd0000644000176200001440000000317712654150565016133 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXPrimaryMeasure.R, R/SDMXPrimaryMeasure-methods.R \docType{class} \name{SDMXPrimaryMeasure} \alias{SDMXPrimaryMeasure} \alias{SDMXPrimaryMeasure,SDMXPrimaryMeasure-method} \alias{SDMXPrimaryMeasure-class} \title{Class "SDMXPrimaryMeasure} \usage{ SDMXPrimaryMeasure(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXPrimaryMeasure" } \description{ A basic class to handle a SDMX PrimaryMeasure } \section{Slots}{ \describe{ \item{\code{conceptRef}}{Object of class "character" giving the dimension conceptRef (required)} \item{\code{conceptVersion}}{Object of class "character" giving the dimension concept version} \item{\code{conceptAgency}}{Object of class "character" giving the dimension concept agency} \item{\code{conceptSchemeRef}}{Object of class "character" giving the dimension conceptScheme ref} \item{\code{conceptSchemeAgency}}{Object of class "character" giving the dimension conceptScheme agency} \item{\code{codelist}}{Object of class "character" giving the codelist ref name} \item{\code{codelistVersion}}{Object of class "character" giving the codelist ref version} \item{\code{codelistAgency}}{Object of class "character" giving the codelist ref agency} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXCompactData.Rd0000644000176200001440000000123712654150564015340 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXCompactData.R, R/SDMXCompactData-methods.R \docType{class} \name{SDMXCompactData} \alias{SDMXCompactData} \alias{SDMXCompactData,SDMXCompactData-method} \alias{SDMXCompactData-class} \title{Class "SDMXCompactData"} \usage{ SDMXCompactData(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXCompactData" } \description{ A basic class to handle a SDMX-ML compact data set } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXDataFlows.Rd0000644000176200001440000000174712654150564015052 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDataFlows.R, R/SDMXDataFlows-methods.R \docType{class} \name{SDMXDataFlows} \alias{SDMXDataFlows} \alias{SDMXDataFlows,SDMXDataFlows-method} \alias{SDMXDataFlows-class} \title{Class "SDMXDataFlows"} \usage{ SDMXDataFlows(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDataFlows" } \description{ A basic class to handle a SDMX DataFlows } \section{Slots}{ \describe{ \item{\code{dataflows}}{Object of class "list" giving the list of DataFlows (datasets), (see \link{SDMXDataFlow})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXDataStructure.Rd0000644000176200001440000000370112654150564015750 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDataStructure.R, R/SDMXDataStructure-methods.R \docType{class} \name{SDMXDataStructure} \alias{SDMXDataStructure} \alias{SDMXDataStructure,SDMXDataStructure-method} \alias{SDMXDataStructure-class} \title{Class "SDMXDataStructure"} \usage{ SDMXDataStructure(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDataStructure" } \description{ A basic class to handle a SDMX DataStructure (or KeyFamily) } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID (required)} \item{\code{agencyID}}{Object of class "character" giving the AgencyID} \item{\code{version}}{Object of class "character" giving the version} \item{\code{uri}}{Object of class "character" giving the uri} \item{\code{urn}}{Object of class "character" giving the urn} \item{\code{isExternalReference}}{Object of class "logical" indicating if the datastructure / keyfamily is an external reference} \item{\code{isFinal}}{Object of class "logical" indicating if the datastructure / keyfamily is final} \item{\code{validFrom}}{Object of class "character" indicating the start validity period} \item{\code{validTo}}{Object of class "character" indicating the end validity period} \item{\code{Name}}{Object of class "list" giving the codelist (by language) - required} \item{\code{Description}}{Object of class "list" giving the codelist description (by language)} \item{\code{Components}}{Object of class "SDMXComponents" (see \link{SDMXComponents})} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXMessageGroup.Rd0000644000176200001440000000151612654150565015562 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXMessageGroup.R, R/SDMXMessageGroup-methods.R \docType{class} \name{SDMXMessageGroup} \alias{SDMXMessageGroup} \alias{SDMXMessageGroup,SDMXMessageGroup-method} \alias{SDMXMessageGroup-class} \title{Class "SDMXMessageGroup"} \usage{ SDMXMessageGroup(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXMessageGroup" } \description{ A basic class to handle a SDMX-ML MessageGroup data set } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/getNamespaces.Rd0000644000176200001440000000134012654150564015236 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMX-methods.R \docType{methods} \name{getNamespaces} \alias{getNamespaces} \alias{getNamespaces,SDMX-method} \title{getNamespaces} \usage{ getNamespaces(obj) \S4method{getNamespaces}{SDMX}(obj) } \arguments{ \item{obj}{An object deriving from class "SDMX"} } \value{ an object of class \code{data.frame} giving the id and uri for each of the namespaces handled in the SDMX-ML document. } \description{ Access the namespaces of the SDMX-ML object } \section{Methods (by class)}{ \itemize{ \item \code{SDMX}: }} \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{SDMX-class} } rsdmx/man/findSDMXServiceProvider.Rd0000644000176200001440000000174512654150564017140 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMXServiceProvider-methods.R \name{findSDMXServiceProvider} \alias{findSDMXServiceProvider} \title{findSDMXServiceProvider} \usage{ findSDMXServiceProvider(agencyId) } \arguments{ \item{agencyId}{an object of class "character" representing a provider identifier} } \value{ an object of class "SDMXServiceProvider" (or NULL if no matching) } \description{ function that allows searching by provider id in the list of known \link{SDMXServiceProvider}. This function can be used for interrogating the list of default providers known by \pkg{rsdmx}, and is used internally by \link{readSDMX} } \examples{ #find OECD provider oecd.provider <- findSDMXServiceProvider("OECD") } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{getSDMXServiceProviders} \link{addSDMXServiceProvider} \link{readSDMX} } rsdmx/man/SDMXDimension.Rd0000644000176200001440000000534312654150564015107 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDimension.R, R/SDMXDimension-methods.R \docType{class} \name{SDMXDimension} \alias{SDMXDimension} \alias{SDMXDimension,SDMXDimension-method} \alias{SDMXDimension-class} \title{Class "SDMXDimension"} \usage{ SDMXDimension(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDimension" } \description{ A basic class to handle a SDMX Dimension } \section{Slots}{ \describe{ \item{\code{conceptRef}}{Object of class "character" giving the dimension conceptRef (required)} \item{\code{conceptVersion}}{Object of class "character" giving the dimension concept version} \item{\code{conceptAgency}}{Object of class "character" giving the dimension concept agency} \item{\code{conceptSchemeRef}}{Object of class "character" giving the dimension conceptScheme ref} \item{\code{conceptSchemeAgency}}{Object of class "character" giving the dimension conceptScheme agency} \item{\code{codelist}}{Object of class "character" giving the codelist ref name} \item{\code{codelistVersion}}{Object of class "character" giving the codelist ref version} \item{\code{codelistAgency}}{Object of class "character" giving the codelist ref agency} \item{\code{isMeasureDimension}}{Object of class "logical" indicating if the dimension is a measure dimension. Default value is FALSE} \item{\code{isFrequencyDimension}}{Object of class "logical" indicating if the dimension is a frequency dimension. Default value is FALSE} \item{\code{isEntityDimension}}{Object of class "logical" indicating if the dimension is an entity dimension. Default value is FALSE} \item{\code{isCountDimension}}{Object of class "logical" indicating if the dimension is a count dimension. Default value is FALSE} \item{\code{isNonObservationTimeDimension}}{Object of class "logical" indicating if the dimension is a non-observation dimension. Default value is FALSE} \item{\code{isIdentityDimension}}{Object of class "logical" indicating if the dimension is an identity dimension. Default value is FALSE} \item{\code{crossSectionalAttachDataset}}{Object of class "logical"} \item{\code{crossSectionalAttachGroup}}{Object of class "logical"} \item{\code{crossSectionalAttachSection}}{Object of class "logical"} \item{\code{crossSectionalAttachObservation}}{Object of class "logical"} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXGenericData.Rd0000644000176200001440000000147712654150565015335 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXGenericData.R, R/SDMXGenericData-methods.R \docType{class} \name{SDMXGenericData} \alias{SDMXGenericData} \alias{SDMXGenericData,SDMXGenericData-method} \alias{SDMXGenericData-class} \title{Class "SDMXGenericData"} \usage{ SDMXGenericData(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXGenericData" } \description{ A basic class to handle a SDMX-ML Generic data set } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/namespaces.SDMX.Rd0000644000176200001440000000132212654150564015350 0ustar liggesusers\name{namespaces.SDMX} \Rdversion{1.1} \alias{namespaces.SDMX} \title{namespaces.SDMX} \description{function used to get the namespaces handled by an SDMX-ML object} \usage{ namespaces.SDMX(xmlObj) } \arguments{ \item{xmlObj}{an object of class "XMLInternalDocument"} } \value{an object of class "data.frame" giving the namespace(s) id and uri} \author{Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com}} \section{Warning}{\code{namespaces.SDMX} is a function used internally to get the namespaces of the SDMX-ML object through \link{getNamespaces}. This last function is used an utility re-used in the different SDMX document parsers.} \seealso{\link{SDMXType-class} \link{getNamespaces}}rsdmx/man/SDMXCodelists.Rd0000644000176200001440000000164312654150564015112 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXCodelists.R, R/SDMXCodelists-methods.R \docType{class} \name{SDMXCodelists} \alias{SDMXCodelists} \alias{SDMXCodelists,SDMXCodelists-method} \alias{SDMXCodelists-class} \title{Class "SDMXCodelists"} \usage{ SDMXCodelists(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXCodelists" } \description{ A basic class to handle SDMX Codelists } \section{Slots}{ \describe{ \item{\code{codelists}}{Object of class "list" giving the list of "SDMXCodelist"} }} \section{Warning}{ This class is not useful in itself, but \link{SDMXDataStructureDefinition} objects will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXAttribute.Rd0000644000176200001440000000555712654150564015134 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXAttribute.R, R/SDMXAttribute-methods.R \docType{class} \name{SDMXAttribute} \alias{SDMXAttribute} \alias{SDMXAttribute,SDMXAttribute-method} \alias{SDMXAttribute-class} \title{Class "SDMXAttribute"} \usage{ SDMXAttribute(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXAttribute" } \description{ A basic class to handle a SDMX Attribute } \section{Slots}{ \describe{ \item{\code{conceptRef}}{Object of class "character" giving the attribute conceptRef (required)} \item{\code{conceptVersion}}{Object of class "character" giving the attribute concept version} \item{\code{conceptAgency}}{Object of class "character" giving the attribute concept agency} \item{\code{conceptSchemeRef}}{Object of class "character" giving the attribute conceptScheme ref} \item{\code{conceptSchemeAgency}}{Object of class "character" giving the attribute conceptScheme agency} \item{\code{codelist}}{Object of class "character" giving the codelist ref name} \item{\code{codelistVersion}}{Object of class "character" giving the codelist ref version} \item{\code{codelistAgency}}{Object of class "character" giving the codelist ref agency} \item{\code{attachmentLevel}}{Object of class "character" giving the attachment level (e.g. DataSet)} \item{\code{assignmentStatus}}{Object of class "character" giving the assignment status (e.g. Mandatory)} \item{\code{isTimeFormat}}{Object of class "logical"} \item{\code{crossSectionalAttachDataset}}{Object of class "logical"} \item{\code{crossSectionalAttachGroup}}{Object of class "logical"} \item{\code{crossSectionalAttachSection}}{Object of class "logical"} \item{\code{crossSectionalAttachObservation}}{Object of class "logical"} \item{\code{isEntityAttribute}}{Object of class "logical" indicating if the Attribute is an entity Attribute. Default value is FALSE} \item{\code{isNonObservationTimeAttribute}}{Object of class "logical" indicating if the Attribute is a non-observation Attribute. Default value is FALSE} \item{\code{isCountAttribute}}{Object of class "logical" indicating if the Attribute is a count Attribute. Default value is FALSE} \item{\code{isFrequencyAttribute}}{Object of class "logical" indicating if the Attribute is a frequency Attribute. Default value is FALSE} \item{\code{isIdentityAttribute}}{Object of class "logical" indicating if the Attribute is an identity Attribute. Default value is FALSE} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (DataStructures, or DataStructureDefinitions) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/addSDMXServiceProvider.Rd0000644000176200001440000000241212654150564016740 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/SDMXServiceProvider-methods.R \name{addSDMXServiceProvider} \alias{addSDMXServiceProvider} \title{addSDMXServiceProvider} \usage{ addSDMXServiceProvider(provider) } \arguments{ \item{provider}{an object of class "SDMXServiceProvider"} } \description{ function that allows configuring a new \link{SDMXServiceProvider} as part of the list of providers known by \pkg{rsdmx}, hence by \link{readSDMX} } \examples{ #create a provider myBuilder <- SDMXRESTRequestBuilder(regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", compliant = TRUE) myProvider <- SDMXServiceProvider( agencyId = "MYORG", name = "My Organization", builder = myBuilder ) #add it addSDMXServiceProvider(myProvider) #check out the list of existing provider (only list the agency Ids) sapply(slot(getSDMXServiceProviders(), "providers"), function(x){slot(x, "agencyId")}) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{getSDMXServiceProviders} \link{findSDMXServiceProvider} \link{readSDMX} } rsdmx/man/SDMXServiceProvider.Rd0000644000176200001440000000452512654150565016277 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXServiceProvider.R, R/SDMXServiceProvider-methods.R \docType{class} \name{SDMXServiceProvider} \alias{SDMXServiceProvider} \alias{SDMXServiceProvider,SDMXServiceProvider-method} \alias{SDMXServiceProvider-class} \title{Class "SDMXServiceProvider"} \usage{ SDMXServiceProvider(agencyId, name, scale, country, builder) } \arguments{ \item{agencyId}{an object of class "character" giving the a provider identifier} \item{name}{an object of class "character" giving the name of the provider} \item{scale}{an object of class "character" giving the scale of the datasource, either "international" or "national". Default value is "international".} \item{country}{an object of class "character" giving the ISO 3-alpha code of the country (if scale is "national"). Default value is \code{NA}} \item{builder}{an object of class "SDMXRequestBuilder" that will performs the web request building for this specific provider} } \value{ an object of class "SDMXServiceProvider" } \description{ A basic class to handle a SDMX service provider } \section{Slots}{ \describe{ \item{\code{agencyId}}{an object of class "character" giving the a provider identifier} \item{\code{name}}{an object of class "character" giving the name of the provider} \item{\code{scale}}{an object of class "character" giving the scale of the datasource, either "international" or "national"} \item{\code{country}}{an object of class "character" giving the ISO 3-alpha code of the country (if scale is "national")} \item{\code{builder}}{an object of class "SDMXRequestBuilder" that will performs the web request building} }} \examples{ #let's create a SDMXRESTRequestBuilder #(assuming that "My Organization" implements SDMX REST web-services) myBuilder <- SDMXRESTRequestBuilder(regUrl = "http://www.myorg.org/registry", repoUrl = "http://www.myorg.org/repository", compliant = TRUE) #create a SDMXServiceProvider provider <- SDMXServiceProvider(agencyId = "MYORG", name = "My Organization", builder = myBuilder) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } rsdmx/man/SDMXStructureType.Rd0000644000176200001440000000177712654150565016034 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXStructureType.R, R/SDMXStructureType-methods.R \docType{class} \name{SDMXStructureType} \alias{SDMXStructureType} \alias{SDMXStructureType,SDMXStructureType-method} \alias{SDMXStructureType-class} \title{Class "SDMXStructureType"} \usage{ SDMXStructureType(xmlObj, resource) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} \item{resource}{object of class "character" giving the REST resource to be queried (required to distinguish between dataflows and datastructures in SDMX 2.0)} } \value{ an object of class "SDMXStructureType" } \description{ A basic class to handle the type of a SDMX-ML Structure document } \section{Warning}{ This class is not useful in itself, but it will be used by \link{readSDMX} to deal with SDMX-ML Structure documents. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXCode.Rd0000644000176200001440000000242412654150564014031 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXCode.R, R/SDMXCode-methods.R \docType{class} \name{SDMXCode} \alias{SDMXCode} \alias{SDMXCode,SDMXCode-method} \alias{SDMXCode-class} \title{Class "SDMXCode"} \usage{ SDMXCode(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXCode" } \description{ A basic class to handle a SDMX Code } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID of the code (required). In SDMX 2.0 documents, this slot will handle the 'value' attribute} \item{\code{urn}}{Object of class "character" giving the code urn} \item{\code{parentCode}}{Object of class "character" giving the parent code} \item{\code{label}}{Object of class "list" giving the code label (by language). In SDMX 2.0, it takes the code 'Description' element vs. 'Name' element in SDMX 2.1} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Codelists, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXType.Rd0000644000176200001440000000224412654150565014101 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXType.R, R/SDMXType-methods.R \docType{class} \name{SDMXType} \alias{SDMXType} \alias{SDMXType,SDMXType-method} \alias{SDMXType-class} \title{Class "SDMXType"} \usage{ SDMXType(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXType" } \description{ A basic class to handle the type of a SDMX-ML document } \section{Slots}{ \describe{ \item{\code{type}}{Object of class "character" giving the type of the SDMX-ML document} }} \note{ At now, the following types have been implemented and successfully tested: - \code{StructureType}, - \code{GenericDataType}, - \code{CompactDataType}, - \code{StructureSpecificDataType}, - \code{CrossSectionalDataType}, - \code{UtilityDataType}, - \code{MessageGroupType} } \section{Warning}{ this class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXStructureSpecificData.Rd0000644000176200001440000000166112654150565017422 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXStructureSpecificData.R, R/SDMXStructureSpecificData-methods.R \docType{class} \name{SDMXStructureSpecificData} \alias{SDMXStructureSpecificData} \alias{SDMXStructureSpecificData,SDMXStructureSpecificData-method} \alias{SDMXStructureSpecificData-class} \title{Class "SDMXStructureSpecificData"} \usage{ SDMXStructureSpecificData(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXStructureSpecificData" } \description{ A basic class to handle a SDMX-ML StructureSpecificData data set } \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} } rsdmx/man/SDMXServiceProviders.Rd0000644000176200001440000000210012654150565016445 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXServiceProviders.R, R/SDMXServiceProviders-methods.R \docType{class} \name{SDMXServiceProviders} \alias{SDMXServiceProviders} \alias{SDMXServiceProviders,SDMXServiceProviders-method} \alias{SDMXServiceProviders-class} \title{Class "SDMXServiceProviders"} \usage{ SDMXServiceProviders(providers) } \arguments{ \item{providers}{an object of class "list" (of \link{SDMXServiceProvider}) configured by default and/or at runtime in \pkg{rsdmx}} } \value{ an object of class "SDMXServiceProviders" } \description{ A class to wrap a list of SDMX service providers } \section{Slots}{ \describe{ \item{\code{providers}}{an object of class "list" (of \link{SDMXServiceProvider}) configured by default and/or at runtime in \pkg{rsdmx}} }} \section{Warning}{ this class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document. } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } rsdmx/man/SDMXDataFlow.Rd0000644000176200001440000000355612654150564014667 0ustar liggesusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/Class-SDMXDataFlow.R, R/SDMXDataFlow-methods.R \docType{class} \name{SDMXDataFlow} \alias{SDMXDataFlow} \alias{SDMXDataFlow,SDMXDataFlow-method} \alias{SDMXDataFlow-class} \title{Class "SDMXDataFlow"} \usage{ SDMXDataFlow(xmlObj) } \arguments{ \item{xmlObj}{object of class "XMLInternalDocument derived from XML package} } \value{ an object of class "SDMXDataFlow" } \description{ A basic class to handle a SDMX DataFlow } \section{Slots}{ \describe{ \item{\code{id}}{Object of class "character" giving the ID (required)} \item{\code{agencyID}}{Object of class "character" giving the AgencyID} \item{\code{version}}{Object of class "character" giving the version} \item{\code{uri}}{Object of class "character" giving the uri} \item{\code{urn}}{Object of class "character" giving the urn} \item{\code{isExternalReference}}{Object of class "logical" indicating if the dataflow is an external reference} \item{\code{isFinal}}{Object of class "logical" indicating if the dataflow is final} \item{\code{validFrom}}{Object of class "character" indicating the start validity period} \item{\code{validTo}}{Object of class "character" indicating the end validity period} \item{\code{Name}}{Object of class "list" giving the dataflow (by available language) - required} \item{\code{Description}}{Object of class "list" giving the dataflow description (by available language)} \item{\code{dsdRef}}{Object of class "character" giving the reference datastructure Id} }} \section{Warning}{ This class is not useful in itself, but all SDMX non-abstract classes will encapsulate it as slot, when parsing an SDMX-ML document (Concepts, or DataStructureDefinition) } \author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} } \seealso{ \link{readSDMX} }