pcAxisCubeMake {qmrparser} | R Documentation |
Creates PC-AXIS cube
Description
From the constructed syntactical tree, structures in R are generated. These structures contain the PC-AXIS cube information.
Usage
pcAxisCubeMake(cstream)
Arguments
cstream |
tree returned by the PC-AXIS file syntactical analysis |
Value
It returns a list with the following elements:
pxCube (data.frame) |
| |||||||||||||||||||||||||||||||||
pxCubeVariable (data.frame) |
| |||||||||||||||||||||||||||||||||
pxCubeVariableDomain (data.frame) |
| |||||||||||||||||||||||||||||||||
pxCubeAttrN |
data.frame list, one for each different parameters cardinalities appearing in "keyword"
| |||||||||||||||||||||||||||||||||
pxCubeData (data.frame) |
|
Returned value short version is:
Value: pxCube (headingLength, StubLength) pxCubeVariable (variableName , headingOrStud, codesYesNo, valuesYesNo, variableOrder, valueLength) pxCubeVariableDomain(variableName , code, value, valueOrder, eliminationYesNo) pxCubeAttr -> list pxCubeAttrN(key, {variableName} , value) pxCubeData ({variableName}+, data) varia signatura
References
PC-Axis file format.
https://www.scb.se/en/services/statistical-programs-for-px-files/px-file-format/
PC-Axis file format manual. Statistics of Finland.
https://tilastokeskus.fi/tup/pcaxis/tiedostomuoto2006_laaja_en.pdf
Examples
## Not run:
## significant time reductions may be achieve by doing:
library("compiler")
enableJIT(level=3)
## End(Not run)
name <- system.file("extdata","datInSFexample6_1.px", package = "qmrparser")
stream <- streamParserFromFileName(name,encoding="UTF-8")
cstream <- pcAxisParser(stream)
if ( cstream$status == 'ok' ) {
cube <- pcAxisCubeMake(cstream)
## Variables
print(cube$pxCubeVariable)
## Data
print(cube$pxCubeData)
}
## Not run:
#
# Error messages like
# " ... invalid multibyte string ... "
# or warnings
# " input string ... is invalid in this locale"
#
# For example, in Linux the error generated by this code:
name <- "https://www.ine.es/pcaxisdl//t20/e245/p04/a2009/l0/00000008.px"
stream <- streamParserFromString( readLines( name ) )
cstream <- pcAxisParser(stream)
if ( cstream$status == 'ok' ) cube <- pcAxisCubeMake(cstream)
#
# is caused by files with a non-readable 'encoding'.
# In the case where it could be read, there may also be problems
# with string-handling functions, due to multibyte characters.
# In Windows, according to \code{link{Sys.getlocale}()},
# file may be read but accents, ñ, ... may not be correctly recognised.
#
#
# There are, at least, the following options:
# - File conversion to utf-8, from the OS, with
# "iconv - Convert encoding of given files from one encoding to another"
#
# - File conversion in R:
name <- "https://www.ine.es/pcaxisdl//t20/e245/p04/a2009/l0/00000008.px"
stream <- streamParserFromString( iconv( readLines( name ), "IBM850", "UTF-8") )
cstream <- pcAxisParser(stream)
if ( cstream$status == 'ok' ) cube <- pcAxisCubeMake(cstream)
#
# In the latter case, latin1 would also work, but accents, ñ, ... would not be
# correctly read.
#
# - Making the assumption that the file does not contain multibyte characters:
#
localeOld <- Sys.getlocale("LC_CTYPE")
Sys.setlocale(category = "LC_CTYPE", locale = "C")
#
name <-
"https://www.ine.es/pcaxisdl//t20/e245/p04/a2009/l0/00000008.px"
stream <- streamParserFromString( readLines( name ) )
cstream <- pcAxisParser(stream)
if ( cstream$status == 'ok' ) cube <- pcAxisCubeMake(cstream)
#
Sys.setlocale(category = "LC_CTYPE", locale = localeOld)
#
# However, some characters will not be correctly read (accents, ñ, ...)
## End(Not run)
[Package qmrparser version 0.1.6 Index]