pcAxisCubeMake: Creates PC-AXIS cube

View source: R/pcAxisCubeMake.R

pcAxisCubeMakeR 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)
headingLength Number of variables in "HEADING".
StubLength Number of variables in "STUB".
frequency Data frequency if "TIMEVAL" is present.
pxCubeVariable (data.frame)
variableName Variable name.
headingOrStud Indicator, whether the variable appears in "HEADING" or "STUB".
codesYesNo Indicator, whether there is "CODES" associated to the variable.
valuesYesNo Indicator, whether there is "VALUES" associated to the variable.
variableOrder Variable order number in "HEADING" or "STUB"
valueLength Number of different "CODES" and/or "VALUES" associated with the variable.
pxCubeVariableDomain (data.frame)
variableName Variable name.
code Value code when "CODES" is present.
value Value literal when "VALUES" is present.
valueOrder Variable order number in "CODES" and/or "VALUES".
eliminationYesNo Indicator, whether the value for the variables is present in "ELIMINATION".
pxCubeAttrN

data.frame list, one for each different parameters cardinalities appearing in "keyword"

  • pxCubeAttrN$A0 (data.frame)

    keyword Keyword.
    language Language code o "".
    length Number of elements of value list.
    value Associated data, keyword[language] = value.
  • pxCubeAttrN$A1 (data.frame)

    keyword Keyword.
    language Language code o "".
    arg1 Argument value.
    length Number of elements of value list.
    value Associated data , keyword[language](arg) = value.
  • pxCubeAttrN$A2 (data.frame)

    keyword Keyword.
    language Language code o "".
    arg1 Argument one value.
    arg2 Argument to value.
    length Value list number of elements.
    value Associated data , keyword[language](arg1,arg2) = value.
pxCubeData (data.frame)
StubLength + headingLength columns , with variables values, ordered according to "STUB" and followed by those appearing in "HEADING". Variables names correspond to variable names.
data associated value.

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)
    

qmrparser documentation built on April 24, 2022, 1:05 a.m.