Skip to content

Commit

Permalink
fixes for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 10, 2023
1 parent d6ba047 commit 5139c2a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 56 deletions.
2 changes: 1 addition & 1 deletion R/SDMX-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespaces.SDMX <- function(xmlObj){

encodeSDMXOutput <- function(df){
for(col in colnames(df)){
if(class(df[,col]) == "character") Encoding(df[,col]) <- "UTF-8"
if(is(df[,col],"character")) Encoding(df[,col]) <- "UTF-8"
}
return(df)
}
Expand Down
8 changes: 4 additions & 4 deletions R/SDMXCompactData-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ as.data.frame.SDMXAllCompactData <- function(x, nsExpr, labels = FALSE, ...) {

if(length(seriesXML) == 0){
seriesXML <- try(getNodeSet(xmlObj, "//ns:Series", namespaces = ns), silent = TRUE)
if(class(seriesXML) == "try-error") seriesXML <- list()
if(is(seriesXML,"try-error")) seriesXML <- list()
}
}else{
if(length(ns) > 0){
seriesXML <- try(getNodeSet(xmlObj, "//ns:Series", namespaces = ns), silent = TRUE)
if(class(seriesXML) == "try-error") seriesXML <- list()
if(is(seriesXML,"try-error")) seriesXML <- list()
}else{
if(nrow(nsDefs.df) > 0){
serieNs <- nsDefs.df[1,]
Expand Down Expand Up @@ -102,7 +102,7 @@ as.data.frame.SDMXAllCompactData <- function(x, nsExpr, labels = FALSE, ...) {

#obs children (in case we have)
obsValues <- try(xmlToDataFrame(obsValueXML, stringsAsFactors = FALSE), silent=TRUE)
if(class(obsValues) == "try-error"){
if(is(obsValues,"try-error")){
obsValues <- NULL
}else{
obsKeyNames <- names(lapply(obsValueXML, xmlChildren)[["Key"]])
Expand All @@ -115,7 +115,7 @@ as.data.frame.SDMXAllCompactData <- function(x, nsExpr, labels = FALSE, ...) {
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)
if(is(keydf,"data.frame")) row.names(keydf) <- 1:nrow(obsAttrs)
}

#single Serie as DataFrame
Expand Down
2 changes: 1 addition & 1 deletion R/SDMXGenericData-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ as.data.frame.SDMXGenericData <- function(x, row.names=NULL, optional=FALSE,
seriekeydf <- as.data.frame(lapply(seriekeydf, as.character), stringsAsFactors=FALSE)
if(!is.null(obsdf)){
seriekeydf <- seriekeydf[rep(base::row.names(seriekeydf), nrow(obsdf)),]
if(class(seriekeydf) != "data.frame"){
if(!is(seriekeydf,"data.frame")){
seriekeydf <- data.frame(seriekeydf)
}
base::row.names(seriekeydf) <- 1:nrow(obsdf)
Expand Down
2 changes: 1 addition & 1 deletion R/readSDMX.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ readSDMX <- function(file = NULL, isURL = TRUE, isRData = FALSE,
#check from arguments if request has to be performed
buildRequest <- FALSE
if(!missing(provider)){
if(class(provider) != "SDMXServiceProvider"){
if(!is(provider,"SDMXServiceProvider")){
stop("Provider should be an instance of 'SDMXServiceProvider'")
}else{
providerId = slot(provider, "agencyId")
Expand Down
47 changes: 11 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
**rsdmx**
=======
[![Build Status](https://github.com/opensdmx/rsdmx/actions/workflows/r-cmd-check.yml/badge.svg?branch=master)](https://github.com/opensdmx/rsdmx/actions/workflows/r-cmd-check.yml)
[![codecov.io](https://codecov.io/github/opensdmx/rsdmx/coverage.svg?branch=master)](https://codecov.io/github/opensdmx/rsdmx?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rsdmx)](https://cran.r-project.org/package=rsdmx)
[![cran checks](https://badges.cranchecks.info/worst/rsdmx.svg)](https://cran.r-project.org/web/checks/check_results_rsdmx.html)
[![Github_Status_Badge](https://img.shields.io/badge/Github-0.6--1-blue.svg)](https://github.com/opensdmx/rsdmx)
Expand Down Expand Up @@ -60,12 +59,8 @@ Copyright (C) 2014 Emmanuel Blondel

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.

#### on OpenCPU
``rsdmx`` is available on the OpenCPU public cloud server. The package version corresponds to the ongoing revision (master branch in Github). See [https://public.opencpu.org/ocpu/github/opensdmx/rsdmx/](https://public.opencpu.org/ocpu/github/opensdmx/rsdmx/)

### Mailing list

A user google group is available at: [https://groups.google.com/forum/#!forum/rsdmx](https://groups.google.com/forum/#!forum/rsdmx)
#### on R-Universe
``rsdmx`` is available on the R-Universe public cloud server. The package version corresponds to the ongoing revision (master branch in Github). See [https://opensdmx.r-universe.dev/ui#package:rsdmx](https://opensdmx.r-universe.dev/ui#package:rsdmx)

## Quickstart

Expand Down Expand Up @@ -267,9 +262,8 @@ 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/nama_10_gdp/.CLV10_MEUR.B1GQ.BE/?startperiod=2005&endPeriod=2011)
* [**EUROSTAT portal**](https://ec.europa.eu/eurostat/web/main/home): [https://ec.europa.eu/eurostat/SDMX/diss-web/rest/data/nama_10_gdp/.CLV10_MEUR.B1GQ.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)**](https://ilostat.ilo.org/): [http://www.ilo.org/ilostat/sdmx/ws/rest/data/ILO,DF_CP_CUB_EAP_DWAP_NOC_RT/ALL?format=generic_2_0&detail=dataonly](http://www.ilo.org/ilostat/sdmx/ws/rest/data/ILO,DF_CP_CUB_EAP_DWAP_NOC_RT/ALL?format=generic_2_0&detail=dataonly)

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

Expand Down Expand Up @@ -322,12 +316,12 @@ sdmx.data <- setDSD(sdmx.data, sdmx.dsd)

#### Read _local_ datasets

This example shows you how to use ``rsdmx`` with _local_ SDMX files, previously downloaded from [EUROSTAT](http://ec.europa.eu/eurostat).
This example shows you how to use ``rsdmx`` with _local_ SDMX files, previously downloaded from [EUROSTAT](https://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)
download.file("https://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)
Expand All @@ -340,46 +334,27 @@ By default, ``readSDMX`` considers the data source is remote. To read a local fi

### 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
This section will introduce you on how to read SDMX **metadata** complete ``data structure definitions`` (DSD)

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)
#### Data Structures
This example illustrates how to read the complete list of data structures (or key families) from the [OECD StatExtracts portal](http://stats.oecd.org)
This example illustrates how to read the complete list of data structures (or key families) from the [OECD StatExtracts portal](https://stats.oecd.org)
```{r, echo = FALSE}
dsUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/ALL"
dsUrl <- "https://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.
This example illustrates how to read a complete DSD using a [OECD StatExtracts portal](https://stats.oecd.org) data source.

```{r, echo = FALSE}
dsdUrl <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1"
dsdUrl <- "https://stats.oecd.org/restsdmx/sdmx.ashx/GetDataStructure/TABLE1"
dsd <- readSDMX(dsdUrl)
```

Expand Down
17 changes: 4 additions & 13 deletions vignettes/quickstart.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For this, the SDMX standard provides various types of _documents_, also known as
* **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](https://sdmx.org/), or this [introduction by EUROSTAT](https://ec.europa.eu/eurostat/web/sdmx-infospace/trainings-tutorials/tutorials).
For more information about the SDMX standards, you can visit the [SDMX website](https://sdmx.org/), or this [introduction by EUROSTAT](https://ec.europa.eu/eurostat/web/sdmx-infospace/trainings-tutorials).

## How to deal with SDMX in R

Expand All @@ -39,10 +39,10 @@ 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:
``rsdmx`` can be installed from CRAN or from its development repository hosted in Github. For the latter, you will need the ``remotes`` package and run:

```{r, eval=FALSE, results="hide"}
devtools::install_github("opensdmx/rsdmx")
remotes::install_github("opensdmx/rsdmx")
```

## Load rsdmx
Expand Down Expand Up @@ -152,16 +152,7 @@ By default, ``readSDMX`` considers the data source is remote. To read a local fi

## 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)

### Codelists

Read codelists from [FAO data portal](http://data.fao.org/sdmx/index.html)
```{r,eval = FALSE,results="hide"}
clUrl <- "http://data.fao.org/sdmx/registry/codelist/FAO/CL_FAO_MAJOR_AREA/0.1"
clobj <- readSDMX(clUrl)
cldf <- as.data.frame(clobj)
```
This section will introduce you on how to read SDMX **metadata** complete ``data structure definition`` (DSD)

### Data Structure Definition (DSD)

Expand Down

0 comments on commit 5139c2a

Please sign in to comment.