-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#116 add saveSDMX & support of RData file in readSDMX
- Loading branch information
Showing
10 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' @name saveSDMX | ||
#' @aliases saveSDMX | ||
#' @title saveSDMX | ||
#' @description \code{saveSDMX} is the function to save R SDMX object | ||
#' | ||
#' @usage saveSDMX(sdmxObj, file) | ||
#' | ||
#' @param sdmxObj an object of class \code{\link{SDMX-Class}} to save | ||
#' @param file a connection or the name of the file where the R object is saved to | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' # Not run by 'R CMD check' | ||
#' # (reliable remote datasource but with possible occasional unavailability) | ||
#' | ||
#' #examples using embedded providers | ||
#' sdmx <- readSDMX(providerId = "OECD", resource = "data", flowRef = "MIG", | ||
#' key = list("TOT", NULL, NULL), start = 2011, end = 2011) | ||
#' saveSDMX(sdmx, "sdmx.rda") | ||
#' } | ||
#' | ||
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} | ||
#' | ||
|
||
saveSDMX <- function(sdmxObj, file){ | ||
saveRDS(sdmxObj, file, refhook = XML::xmlSerializeHook) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/saveSDMX.R | ||
\name{saveSDMX} | ||
\alias{saveSDMX} | ||
\title{saveSDMX} | ||
\usage{ | ||
saveSDMX(sdmxObj, file) | ||
} | ||
\arguments{ | ||
\item{sdmxObj}{an object of class \code{\link{SDMX-Class}} to save} | ||
|
||
\item{file}{a connection or the name of the file where the R object is saved to} | ||
} | ||
\description{ | ||
\code{saveSDMX} is the function to save R SDMX object | ||
} | ||
\examples{ | ||
\donttest{ | ||
# Not run by 'R CMD check' | ||
# (reliable remote datasource but with possible occasional unavailability) | ||
|
||
#examples using embedded providers | ||
sdmx <- readSDMX(providerId = "OECD", resource = "data", flowRef = "MIG", | ||
key = list("TOT", NULL, NULL), start = 2011, end = 2011) | ||
saveSDMX(sdmx, "sdmx.rda") | ||
} | ||
} | ||
\author{ | ||
Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# test_saveSDMX.R | ||
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com> | ||
# | ||
# Description: Unit tests for SDMX save methods | ||
#======================= | ||
require(rsdmx, quietly = TRUE) | ||
require(testthat) | ||
context("saveSDMX") | ||
|
||
test_that("saveSDMX",{ | ||
file <- system.file("extdata", "SDMXCodelists_Example_2.0.xml", package = "rsdmx") | ||
sdmx <- readSDMX(file, isURL = FALSE) | ||
sdmx.copy <- sdmx | ||
saveSDMX(sdmx.copy, "tmp.RData") | ||
rm(sdmx.copy) | ||
sdmx.copy <- readSDMX("tmp.RData", isRData = TRUE) | ||
|
||
for(slotName in slotNames(sdmx)){ | ||
if(slotName == "xmlObj"){ | ||
expect_true(all(sapply(XML::compareXMLDocs(sdmx@xmlObj, sdmx.copy@xmlObj), length) == 0)) | ||
}else{ | ||
expect_true(identical(slot(sdmx,slotName), slot(sdmx.copy,slotName))) | ||
} | ||
} | ||
|
||
}) |