diff --git a/R/Class-SDMXDimension.R b/R/Class-SDMXDimension.R index 3540fc1..6386de1 100644 --- a/R/Class-SDMXDimension.R +++ b/R/Class-SDMXDimension.R @@ -38,6 +38,7 @@ setClass("SDMXDimension", conceptVersion = "character", #optional conceptAgency = "character", #optional conceptSchemeRef = "character", #optional + conceptSchemeVersion = "character", #optional conceptSchemeAgency = "character", #optional codelist = "character", #optional codelistVersion = "character", #optional @@ -63,6 +64,7 @@ setClass("SDMXDimension", conceptVersion = "1.0", conceptAgency = "ORG", conceptSchemeRef = "CONCEPT_SCHEME", + conceptSchemeVersion = "1.0", conceptSchemeAgency = "ORG", codelist = "CODELIST", codelistVersion = "1.0", diff --git a/R/Class-SDMXRequestParams.R b/R/Class-SDMXRequestParams.R index 21c86d4..932b76e 100644 --- a/R/Class-SDMXRequestParams.R +++ b/R/Class-SDMXRequestParams.R @@ -17,7 +17,8 @@ #' @slot flowRef an object of class "character" giving the flowRef to be queried #' @slot key an object of class "character" giving the key (SDMX url formatted) to be used for the query #' @slot start an object of class "character" giving the start time -#' @slot end an object of class "character" giving the end time +#' @slot end an object of class "character" giving the end time +#' @slot references an object of class "character" giving the instructions to return (or not) the artefacts referenced by the artefact to be returned #' @slot compliant an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications #' #' @section Warning: @@ -40,6 +41,7 @@ setClass("SDMXRequestParams", key = "character_OR_NULL", start = "character_OR_numeric_OR_NULL", end = "character_OR_numeric_OR_NULL", + references = "character_OR_NULL", compliant = "logical" ), prototype = list(), diff --git a/R/SDMXCode-methods.R b/R/SDMXCode-methods.R index a0f25da..30ed9f8 100644 --- a/R/SDMXCode-methods.R +++ b/R/SDMXCode-methods.R @@ -39,8 +39,16 @@ SDMXCode <- function(xmlObj, namespaces){ urn = xmlGetAttr(xmlObj, "urn") if(is.null(urn)) urn <- as.character(NA) - parentCode = xmlGetAttr(xmlObj, "parentCode") - if(is.null(parentCode)) parentCode <- as.character(NA) + parentCode <- as.character(NA) + parentId <- xmlGetAttr(xmlObj, "parentCode") + if(!is.null(parentId)) parentCode <- parentId + parentNode <- getNodeSet(xmlDoc(xmlObj), "//ns:Parent//Ref", namespaces = strNs) + if(length(parentNode) == 1) parentCode <- xmlGetAttr(parentNode[[1]], "id") + if(length(parentNode) > 1) { + parentCode <- sapply(parentNode, function(x) { xmlGetAttr(x, "id") }) + # we collapse the vector of parent codes into a single string as required by the SDMXCode class + parentCode <- paste(parentCode, collapse = ",") + } #elements #======== diff --git a/R/SDMXConcepts-methods.R b/R/SDMXConcepts-methods.R index 0cc21ff..b034c40 100644 --- a/R/SDMXConcepts-methods.R +++ b/R/SDMXConcepts-methods.R @@ -40,6 +40,11 @@ concepts.SDMXConcepts <- function(xmlObj, namespaces){ "//mes:Structures/str:Concepts/str:Concept", namespaces = c(mes = as.character(messageNs), str = as.character(strNs))) + conceptsXML <- c(conceptsXML, + getNodeSet(xmlObj, + "//mes:Structures/str:Concepts/str:ConceptScheme/str:Concept", + namespaces = c(mes = as.character(messageNs), + str = as.character(strNs)))) }else{ conceptsXML <- getNodeSet(xmlObj, "//mes:Concepts/str:Concept", diff --git a/R/SDMXData-methods.R b/R/SDMXData-methods.R index 6d0d486..4aab872 100644 --- a/R/SDMXData-methods.R +++ b/R/SDMXData-methods.R @@ -79,9 +79,9 @@ addLabels.SDMXData <- function(data, dsd){ clName <- components[clMatcher, "codelist"] if(is.null(clName) || all(is.na(clName))){ #try to grab codelist using regexpr on codelist - clMatcher <- regexpr(column, components$codelist, ignore.case = TRUE) - attr(clMatcher,"match.length")[is.na(clMatcher)] <- -1 - clName <- components[attr(clMatcher,"match.length")>1, "codelist"] + clMatcher2 <- regexpr(column, components$codelist, ignore.case = TRUE) + attr(clMatcher2,"match.length")[is.na(clMatcher2)] <- -1 + clName <- components[attr(clMatcher2,"match.length")>1, "codelist"] if(length(clName)>1) clName <- clName[1] } @@ -91,6 +91,34 @@ addLabels.SDMXData <- function(data, dsd){ if(!(clName %in% codelists)){ clName <- NULL } + }else if(length(clName)==0){ + #check if component has a conceptSchemeRef and if so try to resolve + #codelist from conceptscheme. + conceptSchemeRef <- components[clMatcher, "conceptSchemeRef"] + if(length(conceptSchemeRef)>0 && !is.na(conceptSchemeRef)){ + codelists <- sapply(slot(slot(dsd,"codelists"), "codelists"), slot, "id") + conceptSchemeVersion <- components[clMatcher, "conceptSchemeVersion"] + conceptSchemeAgency <- components[clMatcher, "conceptSchemeAgency"] + conceptSchemes <- slot(slot(dsd, "concepts"), "conceptSchemes") + clFound <- FALSE + for(conceptScheme in conceptSchemes){ + if(conceptSchemeRef == conceptScheme@id && + conceptSchemeAgency == conceptScheme@agencyID && + conceptSchemeVersion == conceptScheme@version){ + for(concept in conceptScheme@Concept){ + if(concept@id == column){ + coreRepresentation = concept@coreRepresentation + if(coreRepresentation %in% codelists){ + clName <- coreRepresentation + clFound <- TRUE + break + } + } + } + if(clFound){break} + } + } + } } }else{ diff --git a/R/SDMXDimension-methods.R b/R/SDMXDimension-methods.R index 2139602..ebd8586 100644 --- a/R/SDMXDimension-methods.R +++ b/R/SDMXDimension-methods.R @@ -45,6 +45,7 @@ SDMXDimension <- function(xmlObj, namespaces){ conceptVersion <- NULL conceptAgency <- NULL conceptSchemeRef <- NULL + conceptSchemeVersion <- NULL conceptSchemeAgency <- NULL codelist <- NULL codelistVersion <- NULL @@ -64,10 +65,16 @@ SDMXDimension <- function(xmlObj, namespaces){ #concepts if(!is.null(conceptRefXML)){ conceptRef = xmlGetAttr(conceptRefXML, "id") - conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") - conceptAgency = xmlGetAttr(conceptRefXML, "agencyID") - #TODO conceptSchemeRef? - #TODO conceptSchemeAgency + package = xmlGetAttr(conceptRefXML, "package") + if(package == "conceptscheme"){ + conceptSchemeRef = xmlGetAttr(conceptRefXML, "maintainableParentID") + conceptSchemeVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") + conceptSchemeAgency = xmlGetAttr(conceptRefXML, "agencyID") + }else{ + conceptVersion = xmlGetAttr(conceptRefXML, "maintainableParentVersion") + conceptAgency = xmlGetAttr(conceptRefXML, "agencyID") + } + } #codelists @@ -123,6 +130,7 @@ SDMXDimension <- function(xmlObj, namespaces){ 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(conceptSchemeVersion)) conceptSchemeVersion <- as.character(NA) if(is.null(conceptSchemeAgency)) conceptSchemeAgency <- as.character(NA) if(is.null(codelist)) codelist <- as.character(NA) @@ -201,6 +209,7 @@ SDMXDimension <- function(xmlObj, namespaces){ conceptVersion = conceptVersion, conceptAgency = conceptAgency, conceptSchemeRef = conceptSchemeRef, + conceptSchemeVersion = conceptSchemeVersion, conceptSchemeAgency = conceptSchemeAgency, codelist = codelist, codelistVersion = codelistVersion, diff --git a/R/SDMXREST21RequestBuilder-methods.R b/R/SDMXREST21RequestBuilder-methods.R index f9dae7f..00f739d 100644 --- a/R/SDMXREST21RequestBuilder-methods.R +++ b/R/SDMXREST21RequestBuilder-methods.R @@ -85,7 +85,8 @@ SDMXREST21RequestBuilder <- function(regUrl, repoUrl, accessKey = NULL, if(is.null(obj@version)) obj@version = "latest" req <- sprintf("%s/datastructure/%s/%s/%s/",obj@regUrl, obj@agencyId, obj@resourceId, obj@version) if(forceProviderId) req <- paste(req, obj@providerId, sep = "/") - req <- paste0(req, "?references=children") #TODO to see later to have arg for this + if(is.null(obj@references)) obj@references = "children" + req <- paste0(req, "?references=", obj@references) #require key if(!is.null(accessKey)){ diff --git a/R/SDMXRequestParams-methods.R b/R/SDMXRequestParams-methods.R index d2d2644..e492ab5 100644 --- a/R/SDMXRequestParams-methods.R +++ b/R/SDMXRequestParams-methods.R @@ -5,7 +5,7 @@ #' @usage #' SDMXRequestParams(regUrl, repoUrl, accessKey, #' providerId, agencyId, resource, resourceId, version, -#' flowRef, key, start, end, compliant) +#' flowRef, key, start, end, references = NULL, compliant) #' #' @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 @@ -21,6 +21,7 @@ #' @param key an object of class "character" giving the key (SDMX url formatted) to be used for the query #' @param start an object of class "character" giving the start time #' @param end an object of class "character" giving the end time +#' @param references an object of class "character" giving the instructions to return (or not) the artefacts referenced by the artefact to be returned #' @param compliant an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications #' #' @examples @@ -28,15 +29,15 @@ #' params <- SDMXRequestParams( #' regUrl = "", repoUrl ="", accessKey = NULL, #' providerId = "", agencyId ="", resource = "data", resourceId = "", -#' version = "", flowRef = "", key = NULL, start = NULL, end = NULL, compliant = FALSE +#' version = "", flowRef = "", key = NULL, start = NULL, end = NULL, references = NULL, compliant = FALSE #' ) #' @export #' SDMXRequestParams <- function(regUrl, repoUrl, accessKey, providerId, agencyId, resource, resourceId, version = NULL, - flowRef, key = NULL, start = NULL, end = NULL, compliant){ + flowRef, key = NULL, start = NULL, end = NULL, references = NULL, compliant){ new("SDMXRequestParams", regUrl = regUrl, repoUrl = repoUrl, accessKey = accessKey, providerId = providerId, agencyId = agencyId, resource = resource, resourceId = resourceId, version = version, - flowRef = flowRef, key = key, start = start, end = end) + flowRef = flowRef, key = key, start = start, end = end, references = references) } diff --git a/R/SDMXServiceProvider-methods.R b/R/SDMXServiceProvider-methods.R index 654e941..c50c2f6 100644 --- a/R/SDMXServiceProvider-methods.R +++ b/R/SDMXServiceProvider-methods.R @@ -168,7 +168,14 @@ setSDMXServiceProviders <- function(){ # nocov start builder = SDMXREST21RequestBuilder( regUrl = "https://api.imf.org/external/sdmx/2.1", repoUrl = "https://api.imf.org/external/sdmx/2.1", - compliant = TRUE) + compliant = TRUE, + formatter = list( + datastructure = function(obj){ + if(is.null(obj@references)) obj@references = "descendants" + return(obj) + } + ) + ) ) #OECD diff --git a/R/readSDMX.R b/R/readSDMX.R index 2f1c8bc..e2fd81c 100644 --- a/R/readSDMX.R +++ b/R/readSDMX.R @@ -7,7 +7,7 @@ #' provider = NULL, providerId = NULL, providerKey = NULL, #' agencyId = NULL, resource = NULL, resourceId = NULL, version = NULL, #' flowRef = NULL, key = NULL, key.mode = "R", start = NULL, end = NULL, dsd = FALSE, -#' headers = list(), validate = FALSE, +#' headers = list(), validate = FALSE, references = NULL, #' verbose = !is.null(logger), logger = "INFO", ...) #' #' @param file path to SDMX-ML document that needs to be parsed @@ -48,6 +48,8 @@ #' 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. +#' @param references an object of class "character" giving the instructions to return (or not) the +#' artefacts referenced by the artefact to be returned. #' @param dsd an Object of class "logical" if an attempt to inherit the DSD should be performed. #' Active only if \code{"readSDMX"} is used as helper method (ie if data is fetched using #' an embedded service provider. Default is FALSE @@ -138,7 +140,7 @@ readSDMX <- function(file = NULL, isURL = TRUE, isRData = FALSE, provider = NULL, providerId = NULL, providerKey = NULL, agencyId = NULL, resource = NULL, resourceId = NULL, version = NULL, flowRef = NULL, key = NULL, key.mode = "R", start = NULL, end = NULL, dsd = FALSE, - headers = list(), validate = FALSE, + headers = list(), validate = FALSE, references = NULL, verbose = !is.null(logger), logger = "INFO", ...) { #logger @@ -203,8 +205,10 @@ readSDMX <- function(file = NULL, isURL = TRUE, isRData = FALSE, key = key, start = start, end = end, + references = references, compliant = provider@builder@compliant ) + #formatting requestParams requestFormatter <- provider@builder@formatter requestParams <- switch(resource, @@ -451,8 +455,10 @@ readSDMX <- function(file = NULL, isURL = TRUE, isRData = FALSE, if(resource == "data"){ dsdObj <- readSDMX(providerId = providerId, providerKey = providerKey, - resource = "datastructure", resourceId = dsdRef, headers = headers, - verbose = verbose, logger = logger, ...) + resource = "datastructure", resourceId = dsdRef, headers = headers, + verbose = verbose, references = references, logger = logger, ...) + + if(is.null(dsdObj)){ log$WARN(sprintf("Impossible to fetch DSD for dataset '%s'", flowRef)) }else{ @@ -463,7 +469,7 @@ readSDMX <- function(file = NULL, isURL = TRUE, isRData = FALSE, dsdObj <- lapply(1:length(dsdRef), function(x){ flowDsd <- readSDMX(providerId = providerId, providerKey = providerKey, resource = "datastructure", resourceId = dsdRef[[x]], headers = headers, - verbose = verbose, logger = logger, ...) + verbose = verbose, references = references, logger = logger, ...) if(is.null(flowDsd)){ log$INFO(sprintf("Impossible to fetch DSD for dataflow '%s'",resourceId)) }else{ diff --git a/inst/extdata/SDMXCodelists_Example_hierarchical_2.1.xml b/inst/extdata/SDMXCodelists_Example_hierarchical_2.1.xml new file mode 100644 index 0000000..bfea630 --- /dev/null +++ b/inst/extdata/SDMXCodelists_Example_hierarchical_2.1.xml @@ -0,0 +1,3067 @@ + + + + + IDREF3313 + false + 2024-12-17T00:41:26.1595+00:00 + + + + + + + Common hierarchical codelist for PICTs + Liste hiérarchique de codes commune pour les PICTs + + + + ORDER + 10000 + 10000 + + + Pacific region + Région du Pacifique + + + + + ORDER + 20000 + 20000 + + + Melanesia + Mélanésie + + + + + ORDER + 30000 + 30000 + + + Micronesia + Micronésie + + + + + ORDER + 40000 + 40000 + + + Polynesia + Polynésie + + + + + ORDER + 100 + 1700 + + + American Samoa + Samoa américaines + + + + + + + + ORDER + 101 + 1701 + + + Eastern + Eastern + + + + + + + + ORDER + 102 + 1702 + + + Manu'a + Manu'a + + + + + + + + ORDER + 103 + 1703 + + + Unorganized + Unorganized + + + + + + + + ORDER + 104 + 1704 + + + Western + Western + + + + + + + + ORDER + 200 + 400 + + + Cook Islands + Îles Cook + + + + + + + + ORDER + 201 + 401 + + + Northern Group + Groupe du Nord + + + + + + + + ORDER + 202 + 402 + + + Rarotonga + Rarotonga + + + + + + + + ORDER + 203 + 403 + + + Southern Group + Groupe du Sud + + + + + + + + ORDER + 300 + 200 + + + Fiji + Fidji + + + + + + + + ORDER + 301 + 201 + + + Central + Centre + + + + + + + + ORDER + 302 + 202 + + + Eastern + Est + + + + + + + + ORDER + 303 + 203 + + + Northern + Nord + + + + + + + + ORDER + 304 + 204 + + + Western + Ouest + + + + + + + + ORDER + 800 + 100 + + + Micronesia (Federated States of) + États fédérés de Micronésie (pays) + + + + + + + + ORDER + 801 + 101 + + + Chuuk + Chuuk + + + + + + + + ORDER + 802 + 102 + + + Kosrae + Kosrae + + + + + + + + ORDER + 803 + 103 + + + Pohnpei + Pohnpei + + + + + + + + ORDER + 804 + 104 + + + Yap + Yap + + + + + + + + ORDER + 500 + 300 + + + Guam + Guam + + + + + + + + ORDER + 501 + 301 + + + Agana Heights + Agana Heights + + + + + + + + ORDER + 502 + 302 + + + Agat + Agat + + + + + + + + ORDER + 503 + 303 + + + Asan + Asan + + + + + + + + ORDER + 504 + 304 + + + Barrigada + Barrigada + + + + + + + + ORDER + 505 + 305 + + + Chalan-Pago-Ordot + Chalan-Pago-Ordot + + + + + + + + ORDER + 506 + 306 + + + Dededo + Dededo + + + + + + + + ORDER + 507 + 307 + + + Hagåtña + Hagåtña + + + + + + + + ORDER + 508 + 308 + + + Inarajan + Inarajan + + + + + + + + ORDER + 509 + 309 + + + Mangilao + Mangilao + + + + + + + + ORDER + 510 + 310 + + + Merizo + Merizo + + + + + + + + ORDER + 511 + 311 + + + Mongmong-Toto-Maite + Mongmong-Toto-Maite + + + + + + + + ORDER + 512 + 312 + + + Piti + Piti + + + + + + + + ORDER + 513 + 313 + + + Santa Rita + Santa Rita + + + + + + + + ORDER + 514 + 314 + + + Sinajana + Sinajana + + + + + + + + ORDER + 515 + 315 + + + Talofofo + Talofofo + + + + + + + + ORDER + 516 + 316 + + + Tamuning + Tamuning + + + + + + + + ORDER + 517 + 317 + + + Umatac + Umatac + + + + + + + + ORDER + 518 + 318 + + + Yigo + Yigo + + + + + + + + ORDER + 519 + 319 + + + Yona + Yona + + + + + + + + ORDER + 600 + 800 + + + Kiribati + Kiribati + + + + + + + + ORDER + 601 + 801 + + + Banaba + Banaba + + + + + + + + ORDER + 602 + 802 + + + Makin + Makin + + + + + + + + ORDER + 603 + 803 + + + Butaritari + Butaritari + + + + + + + + ORDER + 604 + 804 + + + Marakei + Marakei + + + + + + + + ORDER + 605 + 805 + + + Abaiang + Abaiang + + + + + + + + ORDER + 606 + 806 + + + Nth.Tarawa + Nth.Tarawa + + + + + + + + ORDER + 607 + 807 + + + Sth.Tarawa + Sth.Tarawa + + + + + + + + ORDER + 608 + 808 + + + Maiana + Maiana + + + + + + + + ORDER + 609 + 809 + + + Abemama + Abemama + + + + + + + + ORDER + 610 + 810 + + + Kuria + Kuria + + + + + + + + ORDER + 611 + 811 + + + Aranuka + Aranuka + + + + + + + + ORDER + 612 + 812 + + + Nonouti + Nonouti + + + + + + + + ORDER + 613 + 813 + + + Tabiteuea.Nth + Tabiteuea.Nth + + + + + + + + ORDER + 614 + 814 + + + Tabiteuea.Sth + Tabiteuea.Sth + + + + + + + + ORDER + 615 + 815 + + + Beru + Beru + + + + + + + + ORDER + 616 + 816 + + + Nikunau + Nikunau + + + + + + + + ORDER + 617 + 817 + + + Onotoa + Onotoa + + + + + + + + ORDER + 618 + 818 + + + Tamana + Tamana + + + + + + + + ORDER + 619 + 819 + + + Arorae + Arorae + + + + + + + + ORDER + 620 + 820 + + + Teeraina + Teeraina + + + + + + + + ORDER + 621 + 821 + + + Tabuaeran + Tabuaeran + + + + + + + + ORDER + 622 + 822 + + + Kiritimati + Kiritimati + + + + + + + + ORDER + 623 + 823 + + + Kanton + Kanton + + + + + + + + ORDER + 700 + 600 + + + Marshall Islands + Îles Marshall (pays) + + + + + + + + ORDER + 701 + 601 + + + Ailinglaplap + Ailinglaplap + + + + + + + + ORDER + 702 + 602 + + + Ailuk + Ailuk + + + + + + + + ORDER + 703 + 603 + + + Arno + Arno + + + + + + + + ORDER + 704 + 604 + + + Aur + Aur + + + + + + + + ORDER + 705 + 605 + + + Eneu + Eneu + + + + + + + + ORDER + 706 + 606 + + + Ebon + Ebon + + + + + + + + ORDER + 707 + 607 + + + Enewetak + Enewetak + + + + + + + + ORDER + 708 + 608 + + + Jabat + Jabat + + + + + + + + ORDER + 709 + 609 + + + Jaluit + Jaluit + + + + + + + + ORDER + 710 + 610 + + + Kili + Kili + + + + + + + + ORDER + 711 + 611 + + + Kwajalein + Kwajalein + + + + + + + + ORDER + 712 + 612 + + + Lae + Lae + + + + + + + + ORDER + 713 + 613 + + + Lib + Lib + + + + + + + + ORDER + 714 + 614 + + + Likiep + Likiep + + + + + + + + ORDER + 715 + 615 + + + Majuro + Majuro + + + + + + + + ORDER + 716 + 616 + + + Maloelap + Maloelap + + + + + + + + ORDER + 717 + 617 + + + Mejit + Mejit + + + + + + + + ORDER + 718 + 618 + + + Mili + Mili + + + + + + + + ORDER + 719 + 619 + + + Namdrik + Namdrik + + + + + + + + ORDER + 720 + 620 + + + Namu + Namu + + + + + + + + ORDER + 721 + 621 + + + Rongelap + Rongelap + + + + + + + + ORDER + 722 + 622 + + + Ujae + Ujae + + + + + + + + ORDER + 723 + 623 + + + Utirik + Utirik + + + + + + + + ORDER + 724 + 624 + + + Wotho + Wotho + + + + + + + + ORDER + 725 + 625 + + + Wotje + Wotje + + + + + + + + ORDER + 1200 + 500 + + + Northern Mariana Islands + Îles Mariannes du Nord + + + + + + + + ORDER + 1201 + 501 + + + Saipan + Saipan + + + + + + + + ORDER + 1202 + 502 + + + Tinian + Tinian + + + + + + + + ORDER + 1203 + 503 + + + Rota + Rota + + + + + + + + ORDER + 1000 + 1100 + + + New Caledonia + Nouvelle-Calédonie + + + + + + + + ORDER + 1001 + 1101 + + + Loyalty Islands + Îles Loyauté + + + + + + + + ORDER + 1002 + 1102 + + + Northern Province + Province Nord + + + + + + + + ORDER + 1003 + 1103 + + + Southern Province + Province Sud + + + + + + + + ORDER + 900 + 900 + + + Nauru + Nauru + + + + + + + + ORDER + 901 + 901 + + + Yaren + Yaren + + + + + + + + ORDER + 902 + 902 + + + Boe + Boe + + + + + + + + ORDER + 903 + 903 + + + Aiwo + Aiwo + + + + + + + + ORDER + 904 + 904 + + + Buada + Buada + + + + + + + + ORDER + 905 + 905 + + + Denigomodu + Denigomodu + + + + + + + + ORDER + 906 + 906 + + + Nibok + Nibok + + + + + + + + ORDER + 907 + 907 + + + Uaeboe + Uaeboe + + + + + + + + ORDER + 908 + 908 + + + Baitsi + Baitsi + + + + + + + + ORDER + 909 + 909 + + + Ewa + Ewa + + + + + + + + ORDER + 910 + 910 + + + Anibare + Anibare + + + + + + + + ORDER + 911 + 911 + + + Anetan + Anetan + + + + + + + + ORDER + 912 + 912 + + + Anabar + Anabar + + + + + + + + ORDER + 913 + 913 + + + Ijuw + Ijuw + + + + + + + + ORDER + 914 + 914 + + + Meneng + Meneng + + + + + + + + ORDER + 915 + 915 + + + Location + Location + + + + + + + + ORDER + 1100 + 1000 + + + Niue + Niue + + + + + + + + ORDER + 1101 + 1001 + + + Alofi South + Alofi South + + + + + + + + ORDER + 1102 + 1002 + + + Alofi North + Alofi North + + + + + + + + ORDER + 1103 + 1003 + + + Makefu + Makefu + + + + + + + + ORDER + 1104 + 1004 + + + Tuapa + Tuapa + + + + + + + + ORDER + 1105 + 1005 + + + Namukulu + Namukulu + + + + + + + + ORDER + 1106 + 1006 + + + Hikutavake + Hikutavake + + + + + + + + ORDER + 1107 + 1007 + + + Toi + Toi + + + + + + + + ORDER + 1108 + 1008 + + + Mutalau + Mutalau + + + + + + + + ORDER + 1109 + 1009 + + + Lakepa + Lakepa + + + + + + + + ORDER + 1110 + 1010 + + + Liku + Liku + + + + + + + + ORDER + 1111 + 1011 + + + Hakupu + Hakupu + + + + + + + + ORDER + 1112 + 1012 + + + Vaiea + Vaiea + + + + + + + + ORDER + 1113 + 1013 + + + Avatele + Avatele + + + + + + + + ORDER + 1114 + 1014 + + + Tamakautoga + Tamakautoga + + + + + + + + ORDER + 400 + 1400 + + + French Polynesia + Polynésie française + + + + + + + + ORDER + 401 + 1401 + + + Îles Australes + Îles Australes + + + + + + + + ORDER + 402 + 1402 + + + Îles du Vent + Îles du Vent + + + + + + + + ORDER + 403 + 1403 + + + Îles Marquises + Îles Marquises + + + + + + + + ORDER + 404 + 1404 + + + Îles Sous-le-Vent + Îles Sous-le-Vent + + + + + + + + ORDER + 405 + 1405 + + + Îles Tuamotu-Gambier + Îles Tuamotu-Gambier + + + + + + + + ORDER + 1400 + 1300 + + + Papua New Guinea + Papouasie-Nouvelle-Guinée + + + + + + + + ORDER + 1401 + 1301 + + + Bougainville + Bougainville + + + + + + + + ORDER + 1402 + 1302 + + + Central + Central + + + + + + + + ORDER + 1403 + 1303 + + + Chimbu + Chimbu + + + + + + + + ORDER + 1404 + 1304 + + + East New Britain + East New Britain + + + + + + + + ORDER + 1405 + 1305 + + + East Sepik + East Sepik + + + + + + + + ORDER + 1406 + 1306 + + + Eastern Highlands + Eastern Highlands + + + + + + + + ORDER + 1407 + 1307 + + + Enga + Enga + + + + + + + + ORDER + 1408 + 1308 + + + Gulf + Gulf + + + + + + + + ORDER + 1409 + 1309 + + + Hela + Hela + + + + + + + + ORDER + 1410 + 1310 + + + Jiwaka + Jiwaka + + + + + + + + ORDER + 1411 + 1311 + + + Madang + Madang + + + + + + + + ORDER + 1412 + 1312 + + + Manus + Manus + + + + + + + + ORDER + 1413 + 1313 + + + Milne Bay + Milne Bay + + + + + + + + ORDER + 1414 + 1314 + + + Morobe + Morobe + + + + + + + + ORDER + 1415 + 1315 + + + National Capital District + National Capital District + + + + + + + + ORDER + 1416 + 1316 + + + New Ireland + New Ireland + + + + + + + + ORDER + 1417 + 1317 + + + Oro + Oro + + + + + + + + ORDER + 1418 + 1318 + + + Sandaun + Sandaun + + + + + + + + ORDER + 1419 + 1319 + + + Southern Highlands + Southern Highlands + + + + + + + + ORDER + 1420 + 1320 + + + West New Britain + West New Britain + + + + + + + + ORDER + 1421 + 1321 + + + Western + Western + + + + + + + + ORDER + 1422 + 1322 + + + Western Highlands + Western Highlands + + + + + + + + ORDER + 1500 + 700 + + + Pitcairn + Îles Pitcairn + + + + + + + + ORDER + 1300 + 1200 + + + Palau + Palaos + + + + + + + + ORDER + 1301 + 1201 + + + Koror + Koror + + + + + + + + ORDER + 1302 + 1202 + + + Airai + Airai + + + + + + + + ORDER + 1303 + 1203 + + + Outlying States + Outlying States + + + + + + + + ORDER + 1304 + 1204 + + + West Babeldaob + West Babeldaob + + + + + + + + ORDER + 1305 + 1205 + + + East Babeldaob + East Babeldaob + + + + + + + + ORDER + 1700 + 1500 + + + Solomon Islands + Salomon + + + + + + + + ORDER + 1701 + 1501 + + + Choiseul + Choiseul + + + + + + + + ORDER + 1702 + 1502 + + + Western + Western + + + + + + + + ORDER + 1703 + 1503 + + + Isabel + Isabel + + + + + + + + ORDER + 1704 + 1504 + + + Central + Central + + + + + + + + ORDER + 1705 + 1505 + + + Rennell-Bell + Rennell-Bell + + + + + + + + ORDER + 1706 + 1506 + + + Guadalcanal + Guadalcanal + + + + + + + + ORDER + 1707 + 1507 + + + Malaita + Malaita + + + + + + + + ORDER + 1708 + 1508 + + + Makira-Ulawa + Makira-Ulawa + + + + + + + + ORDER + 1709 + 1509 + + + Temotu + Temotu + + + + + + + + ORDER + 1710 + 1510 + + + Honiara + Honiara + + + + + + + + ORDER + 1800 + 1800 + + + Tokelau + Tokelau + + + + + + + + ORDER + 1801 + 1801 + + + Anafu + Anafu + + + + + + + + ORDER + 1802 + 1802 + + + Fakaofo + Fakaofo + + + + + + + + ORDER + 1803 + 1803 + + + Nukunonu + Nukunonu + + + + + + + + ORDER + 1900 + 1900 + + + Tonga + Tonga + + + + + + + + ORDER + 1901 + 1901 + + + Ha'apai + Ha'apai + + + + + + + + ORDER + 1902 + 1902 + + + 'Eua + 'Eua + + + + + + + + ORDER + 1903 + 1903 + + + Niuas + Niuas + + + + + + + + ORDER + 1904 + 1904 + + + Tongatapu + Tongatapu + + + + + + + + ORDER + 1905 + 1905 + + + Vava'u + Vava'u + + + + + + + + ORDER + 2000 + 2000 + + + Tuvalu + Tuvalu + + + + + + + + ORDER + 2001 + 2001 + + + Nanumea + Nanumea + + + + + + + + ORDER + 2002 + 2002 + + + Nanumanga + Nanumanga + + + + + + + + ORDER + 2003 + 2003 + + + Niutao + Niutao + + + + + + + + ORDER + 2004 + 2004 + + + Nui + Nui + + + + + + + + ORDER + 2005 + 2005 + + + Vaitupu + Vaitupu + + + + + + + + ORDER + 2006 + 2006 + + + Nukufetau + Nukufetau + + + + + + + + ORDER + 2007 + 2007 + + + Funafuti + Funafuti + + + + + + + + ORDER + 2008 + 2008 + + + Nukulaelae + Nukulaelae + + + + + + + + ORDER + 2009 + 2009 + + + Niulakita + Niulakita + + + + + + + + ORDER + 2100 + 2100 + + + Vanuatu + Vanuatu + + + + + + + + ORDER + 2101 + 2101 + + + Torba + Torba + + + + + + + + ORDER + 2102 + 2102 + + + Sanma + Sanma + + + + + + + + ORDER + 2103 + 2103 + + + Penama + Penama + + + + + + + + ORDER + 2104 + 2104 + + + Malampa + Malampa + + + + + + + + ORDER + 2105 + 2105 + + + Shefa + Shefa + + + + + + + + ORDER + 2106 + 2106 + + + Tafea + Tafea + + + + + + + + ORDER + 2200 + 2200 + + + Wallis and Futuna + Wallis-et-Futuna + + + + + + + + ORDER + 2201 + 2201 + + + Alo + Alo + + + + + + + + ORDER + 2202 + 2202 + + + Sigave + Sigave + + + + + + + + ORDER + 2203 + 2203 + + + Hahake + Hahake + + + + + + + + ORDER + 2204 + 2204 + + + Hihifo + Hihifo + + + + + + + + ORDER + 2205 + 2205 + + + Mua + Mua + + + + + + + + ORDER + 1600 + 1600 + + + Samoa + Samoa + + + + + + + + ORDER + 1601 + 1601 + + + Apia Urban Area + Apia Urban Area + + + + + + + + ORDER + 1602 + 1602 + + + North West Upolu + North West Upolu + + + + + + + + ORDER + 1603 + 1603 + + + Rest of Upolu + Rest of Upolu + + + + + + + + ORDER + 1604 + 1604 + + + Savaii + Savaii + + + + + + + + ORDER + 50000 + 50000 + + + Pacific region (excluding PNG) + Région du Pacifique (sans PNG) + + + + + ORDER + 60000 + 60000 + + + Melanesia (excluding PNG) + Mélanésie (sans PNG) + + + + + \ No newline at end of file diff --git a/man/SDMXRequestParams.Rd b/man/SDMXRequestParams.Rd index 2b4629b..0f4e4e1 100644 --- a/man/SDMXRequestParams.Rd +++ b/man/SDMXRequestParams.Rd @@ -10,7 +10,7 @@ \usage{ SDMXRequestParams(regUrl, repoUrl, accessKey, providerId, agencyId, resource, resourceId, version, - flowRef, key, start, end, compliant) + flowRef, key, start, end, references = NULL, compliant) } \arguments{ \item{regUrl}{an object of class "character" giving the base Url of the SDMX service registry} @@ -39,6 +39,8 @@ mandatory for some service providers.} \item{end}{an object of class "character" giving the end time} +\item{references}{an object of class "character" giving the instructions to return (or not) the artefacts referenced by the artefact to be returned} + \item{compliant}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications} } \description{ @@ -72,6 +74,8 @@ an authentication or subscription user key/token has to be provided to perform r \item{\code{end}}{an object of class "character" giving the end time} +\item{\code{references}}{an object of class "character" giving the instructions to return (or not) the artefacts referenced by the artefact to be returned} + \item{\code{compliant}}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications} }} @@ -86,7 +90,7 @@ encapsulate it as slot, when parsing an SDMX-ML document. params <- SDMXRequestParams( regUrl = "", repoUrl ="", accessKey = NULL, providerId = "", agencyId ="", resource = "data", resourceId = "", - version = "", flowRef = "", key = NULL, start = NULL, end = NULL, compliant = FALSE + version = "", flowRef = "", key = NULL, start = NULL, end = NULL, references = NULL, compliant = FALSE ) } \author{ diff --git a/man/readSDMX.Rd b/man/readSDMX.Rd index 7dcc106..193687e 100644 --- a/man/readSDMX.Rd +++ b/man/readSDMX.Rd @@ -8,7 +8,7 @@ readSDMX(file = NULL, isURL = TRUE, isRData = FALSE, provider = NULL, providerId = NULL, providerKey = NULL, agencyId = NULL, resource = NULL, resourceId = NULL, version = NULL, flowRef = NULL, key = NULL, key.mode = "R", start = NULL, end = NULL, dsd = FALSE, - headers = list(), validate = FALSE, + headers = list(), validate = FALSE, references = NULL, verbose = !is.null(logger), logger = "INFO", ...) } \arguments{ @@ -75,6 +75,9 @@ an embedded service provider. Default is FALSE} be performed on the SDMX-ML document to check its SDMX compliance when reading it. Default is FALSE.} +\item{references}{an object of class "character" giving the instructions to return (or not) the +artefacts referenced by the artefact to be returned.} + \item{verbose}{an Object of class "logical" that indicates if rsdmx logs should appear to user. Default is set to \code{FALSE} (see argument \code{logger}).} diff --git a/tests/testthat/test_Codelists.R b/tests/testthat/test_Codelists.R index 33ba36e..00898fc 100644 --- a/tests/testthat/test_Codelists.R +++ b/tests/testthat/test_Codelists.R @@ -7,26 +7,43 @@ require(rsdmx, quietly = TRUE) require(testthat) context("SDMXCodelists") -test_that("Codelists - 2.0",{ +test_that("Codelists - 2.0", { file <- system.file("extdata", "SDMXCodelists_Example_2.0.xml", package = "rsdmx") xmlObj <- xmlParse(file) ns <- namespaces.SDMX(xmlObj) codelists <- SDMXCodelists(xmlObj, ns) 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",{ +test_that("Codelists - 2.1", { file <- system.file("extdata", "SDMXCodelists_Example_2.1.xml", package = "rsdmx") xmlObj <- xmlParse(file) ns <- namespaces.SDMX(xmlObj) codelists <- SDMXCodelists(xmlObj, ns) expect_is(codelists, "SDMXCodelists") expect_equal(length(codelists@codelists), 1L) - + + df <- as.data.frame(codelists) + expect_is(df, "data.frame") +}) + +test_that("Hierarchical codelists", { + file <- system.file("extdata", "SDMXCodelists_Example_hierarchical_2.1.xml", package = "rsdmx") + xmlObj <- xmlParse(file) + ns <- namespaces.SDMX(xmlObj) + codelists <- SDMXCodelists(xmlObj, ns) + expect_is(codelists, "SDMXCodelists") + expect_equal(length(codelists@codelists), 1L) + + # expect to read the right parentCode from the XML object when there is + expect_equal(codelists@codelists[[1]]@Code[[5]]@parentCode, "POL") + # expect to find an NA in parentCode when there is no parentCode in the XML object + expect_true(is.na(codelists@codelists[[1]]@Code[[1]]@parentCode)) + df <- as.data.frame(codelists) expect_is(df, "data.frame") }) \ No newline at end of file diff --git a/tests/testthat/test_Main_Helpers.R b/tests/testthat/test_Main_Helpers.R index 06c37bc..9d86bfa 100644 --- a/tests/testthat/test_Main_Helpers.R +++ b/tests/testthat/test_Main_Helpers.R @@ -154,14 +154,37 @@ test_that("IMF - datastructure",{ } }) +#No plans to dissiminate data on IMF provider, IMF data avaliable on IMF_DATA. + +#IMF_DATA +#---- + +#-> dataflow +test_that("IMF_DATA - dataflow",{ + testthat::skip_on_cran() + sdmx <- readSDMX(providerId = "IMF_DATA", resource = "dataflow") + if(!is.null(sdmx)){ + expect_is(sdmx, "SDMXDataFlows") + } +}) + +#-> datastructure +test_that("IMF_DATA - datastructure",{ + testthat::skip_on_cran() + sdmx <- readSDMX(providerId = "IMF_DATA", resource = "datastructure", resourceId = "IMF.STA,DSD_CPI") + if(!is.null(sdmx)){ + expect_is(sdmx, "SDMXDataStructureDefinition") + } +}) + #-> data -test_that("IMF - data",{ +test_that("IMF_DATA - data",{ testthat::skip_on_cran() - #TODO to test, sounds it's not public anymore - #sdmx <- readSDMX(providerId = "IMF", resource = "data", flowRef = "BOP_GBPM6", start = 2020, end = 2020) - #if(!is.null(sdmx)){ - # expect_is(sdmx, "SDMXStructureSpecificData") - #} + sdmx <- readSDMX(providerId = "IMF_DATA", resource = "data", flowRef = "IMF.STA,CPI", + key = list("USA", "CPI", "CP01", "IX", "A"), start = 2020, end = 2020) + if(!is.null(sdmx)){ + expect_is(sdmx, "SDMXStructureSpecificData") + } }) #OECD