Skip to content

Commit

Permalink
#41 adding UtilityData support
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 13, 2015
1 parent 5760423 commit 683abe0
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 40 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ BugReports: https://github.com/opensdmx/rsdmx/issues
LazyLoad: yes
Collate:
Class-SDMXSchema.R Class-SDMXType.R Class-SDMXStructureType.R Class-SDMXHeader.R
Class-SDMX.R Class-SDMXGenericData.R Class-SDMXCompactData.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-SDMX.R Class-SDMXGenericData.R Class-SDMXCompactData.R Class-SDMXUtilityData.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
SDMXSchema-methods.R SDMXType-methods.R SDMXStructureType-methods.R SDMXHeader-methods.R
SDMX-methods.R SDMXGenericData-methods.R SDMXCompactData-methods.R SDMXMessageGroup-methods.R
SDMXSchema-methods.R SDMXType-methods.R SDMXStructureType-methods.R SDMXHeader-methods.R SDMX-methods.R
SDMXGenericData-methods.R SDMXCompactData-methods.R SDMXUtilityData-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
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exportClasses(
SDMXStructureType,
SDMXGenericData,
SDMXCompactData,
SDMXUtilityData,
SDMXMessageGroup,
SDMXConcept,
SDMXConceptScheme,
Expand All @@ -36,6 +37,7 @@ export(
SDMXStructureType,
SDMXGenericData,
SDMXCompactData,
SDMXUtilityData,
SDMXMessageGroup,
SDMXConcept,
SDMXConceptScheme,
Expand Down Expand Up @@ -82,6 +84,7 @@ exportMethods(

S3method(as.data.frame, SDMXGenericData)
S3method(as.data.frame, SDMXCompactData)
S3method(as.data.frame, SDMXUtilityData)
S3method(as.data.frame, SDMXMessageGroup)
S3method(as.data.frame, SDMXConcepts)
S3method(as.data.frame, SDMXCodelists)
36 changes: 27 additions & 9 deletions R/Class-SDMXHeader.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,37 @@ setClass("SDMXHeader",
validity = function(object){

# ID validation
if(is.null(object@ID)) return(FALSE)
if(attr(regexpr("[a-zA-Z0-9@-_@\\$]", object@ID),"match.length") == -1) return(FALSE)

if(is.null(object@ID)){
message("Missing 'ID' in header")
return(FALSE)
}
if(attr(regexpr("[a-zA-Z0-9@-_@\\$]", object@ID),"match.length") == -1){
message("Invalid 'ID' in header")
return(FALSE)
}

#Test/Truncated
if(!is.logical(object@Test)) return(FALSE)
if(!is.logical(object@Truncated)) return(FALSE)

if(!is.logical(object@Test)){
message("Invalid 'Test' value in header")
return(FALSE)
}
if(!is.logical(object@Truncated)){
message("Invalid 'Truncated' value in header")
return(FALSE)
}

#Dates/Time validation
if(is.na(object@Prepared)) return(FALSE)
if(is.na(object@Prepared)){
message("Invalid 'Prepared' value in header")
return(FALSE)
}

#Sender/Receiver validation
if(is.na(object@Sender$id) || nchar(object@Sender$id) == 0) return(FALSE)
if(nchar(object@Receiver$id) == 0) return(FALSE)
if(is.na(object@Sender$id) || nchar(object@Sender$id) == 0){
message("Missing 'Sender' id in header")
return(FALSE)
}
if(nchar(object@Receiver$id) == 0) return(FALSE)

#TODO KeyFamilyRef validation
#TODO KeyFamilyAgency validation
Expand Down
11 changes: 6 additions & 5 deletions R/Class-SDMXType.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ setClass("SDMXType",
validity = function(object){
type <- getType(object);
valid <- switch(type,
"StructureType" = TRUE,
"GenericDataType" = TRUE,
"CompactDataType" = TRUE,
"MessageGroupType" = TRUE,
FALSE
"StructureType" = TRUE,
"GenericDataType" = TRUE,
"CompactDataType" = TRUE,
"UtilityDataType" = TRUE,
"MessageGroupType" = TRUE,
FALSE
);
if(valid == FALSE)
warning(paste("Unknown SDMXType ", type, sep=""));
Expand Down
13 changes: 13 additions & 0 deletions R/Class-SDMXUtilityData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# E.Blondel - 2015/01/13
#=======================

#SDMX UtilityData class
setClass("SDMXUtilityData",
contains = "SDMX",
representation(),
prototype = list(),
validity = function(object){
#eventual validation rules
return(TRUE);
}
)
18 changes: 18 additions & 0 deletions R/SDMXUtilityData-methods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# E.Blondel - 2015/01/13
#=======================

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));
39 changes: 20 additions & 19 deletions R/readSDMX.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
readSDMX <- function(file, isURL = TRUE){

#load data
status <- 0
status <- 0
if(isURL == FALSE){
if(!file.exists(file))
stop("File ", file, "not found\n")
Expand Down Expand Up @@ -46,24 +46,25 @@ readSDMX <- function(file, isURL = TRUE){

#encapsulate in S4 object
obj <- NULL
if(status){
type <- SDMXType(xmlObj)@type
obj <- switch(type,
"StructureType" = getSDMXStructureObject(xmlObj),
"GenericDataType" = SDMXGenericData(xmlObj),
"CompactDataType" = SDMXCompactData(xmlObj),
"MessageGroupType" = SDMXMessageGroup(xmlObj),
NULL
)

if(is.null(obj)){
if(type == "StructureType"){
strTypeObj <- SDMXStructureType(xmlObj)
type <- getStructureType(strTypeObj)
}
stop(paste("Unsupported SDMX Type '",type,"'",sep=""))
}
}
if(status){
type <- SDMXType(xmlObj)@type
obj <- switch(type,
"StructureType" = getSDMXStructureObject(xmlObj),
"GenericDataType" = SDMXGenericData(xmlObj),
"CompactDataType" = SDMXCompactData(xmlObj),
"UtilityDataType" = SDMXUtilityData(xmlObj),
"MessageGroupType" = SDMXMessageGroup(xmlObj),
NULL
)

if(is.null(obj)){
if(type == "StructureType"){
strTypeObj <- SDMXStructureType(xmlObj)
type <- getStructureType(strTypeObj)
}
stop(paste("Unsupported SDMX Type '",type,"'",sep=""))
}
}
return(obj);
}

4 changes: 3 additions & 1 deletion man/SDMXType-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ SDMXType(xmlObj)

\author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com}}
\note{
At now, the following types have been implemented and tested: \code{GenericDataType}, \code{CompactDataType}, and {MessageGroupType}. At now the \code{MessageGroupType} was only modeled to allow reading OECD generic data which is provided. Other message types handled in \code{MessageGroup} document type are not yet supported.
At now, the following types have been implemented and tested: \code{GenericDataType}, \code{CompactDataType}, \code{UtilityDataType} and {MessageGroupType}.

The \code{MessageGroupType} was only modeled to allow reading OECD generic data which is provided. Other message types handled in \code{MessageGroup} document type are not yet supported.
}

\section{Warning }{this class is not useful in itself, but all SDMX non-abstract classes will encapsulate itas slot, when parsing an SDMX-ML document}
Expand Down
23 changes: 23 additions & 0 deletions man/SDMXUtilityData-class.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
\name{SDMXUtilityData-class}
\docType{class}
\alias{SDMXUtilityData-class}
\alias{SDMXUtilityData}
\alias{SDMXUtilityData-method}


\title{Class "SDMXUtilityData"}
\description{ A basic class to handle a SDMX-ML utility data set}
\section{Objects from the Class}{are never to be generated; will be used by the \link{readSDMX} main parser function}


\usage{
SDMXUtilityData(xmlObj)
}

\arguments{
\item{xmlObj}{an object of class "XMLInternalDocument"}
}

\author{ Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com}}

\keyword{classes}

0 comments on commit 683abe0

Please sign in to comment.