Learn R Programming

seasonal (version 1.2.0)

import.spc: Import X-13 .spc Files (experimental)

Description

Utility function to import .spc files from X-13. It generates a list of calls to seas (and import.ts) that can be run in R. Evaluating these calls should perform the same X-13 procedure as the original .spc file. The print method displays the calls in a way that they can be copy-pasted into an R script.

Usage

import.spc(file)

## S3 method for class 'import.spc': print(x, ...)

Arguments

file
character, name of the X-13 .spc file
x
object of class import.spc
...
further arguments, not used

Value

  • returns an object of class import.spc, which is a list with the following (optional) objects of class call:
  • xthe call to retrieve the data for the input series
  • xtransthe call to retrieve the data for the xtrans series (if required by the call)
  • xregthe call to retrieve the data for the xreg series (if required by the call)
  • seasthe call to seas

See Also

import.ts, for importing X-13 data files.

seas for the main function of seasonal.

Examples

Run this code
# importing the orginal X-13 example file
import.spc(system.file("tests", "Testairline.spc", package="seasonal"))

### reading .spc with multiple user regression and transformation series

# running a complex seas call and save output in a temporary directory
tdir <- tempdir()
seas(x = AirPassengers, xreg = cbind(a = genhol(cny, start = 1, end = 4,
    center = "calendar"), b = genhol(cny, start = -3, end = 0,
    center = "calendar")), xtrans = cbind(sqrt(AirPassengers), AirPassengers^3), 
    transform.function = "log", transform.type = "temporary", 
    regression.aictest = "td", regression.usertype = "holiday", dir = tdir, 
    out = TRUE)

# importing the .spc file from the temporary location
ll <- import.spc(file.path(tdir, "iofile.spc"))

# ll is list containing four calls: 
# - 'll$x', 'll$xreg' and 'll$xtrans': calls to import.ts(), which read the
#   series from the X-13 data files
# - 'll$seas': a call to seas() which performs the seasonal adjustment in R
str(ll)

# to replicate the original X-13 operation, run all four calls in a series.
# You can either copy/paste and run the print() output:
ll

# or use eval() to evaluate the call(s). To evaluate the first call and
# import the x variable:
eval(ll$x)

# to run all four calls in 'll', use lapply() and eval():
ee <- lapply(ll, eval, envir = globalenv())
ee$seas  # the 'seas' object, produced by the final call to seas()

Run the code above in your browser using DataLab