Skip to content

Commit

Permalink
#104 support DSD inheritance for SDMXDataFlows document
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Aug 2, 2016
1 parent 45e29b6 commit e626d2d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rsdmx
Version: 0.5-5
Date: 2016-07-23
Date: 2016-08-02
Title: Tools for Reading SDMX Data and Metadata
Authors@R: c(
person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com"),
Expand Down
6 changes: 4 additions & 2 deletions R/Class-SDMXDataFlow.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ setClass("SDMXDataFlow",
#elements
Name = "list", #at least one
Description = "list", #optional
dsdRef = "character"
dsdRef = "character",
dsd = "SDMXDataStructureDefinition_OR_NULL"
),
prototype = list(
#attributes
Expand All @@ -64,7 +65,8 @@ setClass("SDMXDataFlow",
en = "dataflow description",
fr = "description du dataflow"
),
dsdRef = "someId"
dsdRef = "someId",
dsd = NULL
),
validity = function(object){

Expand Down
3 changes: 2 additions & 1 deletion R/SDMXDataFlow-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ SDMXDataFlow <- function(xmlObj, namespaces){
#elements,
Name = flowNames,
Description = flowDescriptions,
dsdRef = dsdRef
dsdRef = dsdRef,
dsd = NULL
)
}
40 changes: 30 additions & 10 deletions R/readSDMX.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,21 @@ readSDMX <- function(file = NULL, isURL = TRUE,
}

#attempt to get DSD in case of helper method
if(buildRequest && resource == "data" && dsd){
if(buildRequest && resource %in% c("data","dataflow") && dsd){

if(providerId %in% c("ESTAT", "ISTAT", "WBG_WITS")){
if(resource == "data" && providerId %in% c("ESTAT", "ISTAT", "WBG_WITS")){
if(verbose) message("-> Attempt to fetch DSD ref from dataflow description")
flow <- readSDMX(providerId = providerId, resource = "dataflow",
resourceId = flowRef, verbose = TRUE)
dsdRef <- slot(slot(flow, "dataflows")[[1]],"dsdRef")
rm(flow)
}else{
dsdRef <- slot(obj,"dsdRef")
dsdRef <- NULL
if(resource == "data"){
dsdRef <- slot(obj, "dsdRef")
}else if(resource=="dataflow"){
dsdRef <- lapply(slot(obj,"dataflows"), slot,"dsdRef")
}
if(!is.null(dsdRef)){
if(verbose) message(paste0("-> DSD ref identified in dataset = '", dsdRef, "'"))
if(verbose) message("-> Attempt to fetch & bind DSD to dataset")
Expand All @@ -356,14 +361,29 @@ readSDMX <- function(file = NULL, isURL = TRUE,
if(verbose) message("-> Attempt to fetch & bind DSD to dataset using 'flowRef'")
}
}

dsdObj <- readSDMX(providerId = providerId, resource = "datastructure",

#fetch DSD
dsdObj <- NULL
if(resource == "data"){
dsdObj <- readSDMX(providerId = providerId, resource = "datastructure",
resourceId = dsdRef, verbose = verbose)
if(is.null(dsdObj)){
if(verbose) message("-> Impossible to fetch DSD")
}else{
if(verbose) message("-> DSD fetched and associated to dataset!")
slot(obj, "dsd") <- dsdObj
if(is.null(dsdObj)){
if(verbose) message(sprintf("-> Impossible to fetch DSD for dataset %s", flowRef))
}else{
if(verbose) message("-> DSD fetched and associated to dataset!")
slot(obj, "dsd") <- dsdObj
}
}else if(resource == "dataflow"){
dsdObj <- lapply(1:length(dsdRef), function(x){
flowDsd <- readSDMX(providerId = providerId, resource = "datastructure",
resourceId = dsdRef[[x]], verbose = verbose)
if(is.null(flowDsd)){
if(verbose) message(sprintf("-> Impossible to fetch DSD for dataflow %s",resourceId))
}else{
if(verbose) message("-> DSD fetched and associated to dataflow!")
slot(slot(obj,"dataflows")[[x]],"dsd") <<- flowDsd
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/rsdmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' Type: \tab Package\cr
#' Version
#' : \tab 0.5-5\cr
#' Date: \tab 2016-07-23\cr
#' Date: \tab 2016-08-02\cr
#' License: \tab GPL(>=2.0)\cr
#' LazyLoad: \tab yes\cr
#' }
Expand Down
2 changes: 1 addition & 1 deletion man/rsdmx.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ currently focuses on the SDMX XML standard format (SDMX-ML).
Type: \tab Package\cr
Version
: \tab 0.5-5\cr
Date: \tab 2016-07-23\cr
Date: \tab 2016-08-02\cr
License: \tab GPL(>=2.0)\cr
LazyLoad: \tab yes\cr
}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_DataFlows.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ test_that("DataFlows - 2.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")
expect_equal(flow.df[1, "dsd"], NULL)
})

0 comments on commit e626d2d

Please sign in to comment.