Last data update: 2014.03.03

R: Read LSD variables (time series) from a LSD results file (a...
read.single.lsdR Documentation

Read LSD variables (time series) from a LSD results file (a single instance of each variable only)

Description

This function reads the data series associated to one instance of each selected variable from a LSD results file (.res). Just a single instance (time series of a single LSD object) is read at each call.

Usage

read.single.lsd(file, col.names = NULL, nrows = -1, skip = 0,
                check.names = TRUE, instance = 1)

Arguments

file

the name of the LSD results file which the data are to be read from. If it does not contain an absolute path, the file name is relative to the current working directory, getwd(). This can be a compressed file (see file) and must include the appropriated extension (usually .res or .res.gz).

col.names

a vector of optional names for the variables. The default is to read all (unique) variables.

nrows

integer: the maximum number of time steps (rows) to read in. Negative and other invalid values are ignored. The default is to read all rows.

skip

integer: the number of time steps (rows) of the results file to skip before beginning to read data. The default is to read from the first time step (t = 1).

check.names

logical. If TRUE then the names of the variables are checked to ensure that they are syntactically valid variable names. If necessary they are adjusted (by make.names) so that they are, and also to ensure that there are no duplicates.

instance

integer: the instance of the variable to be read, for variables that exist in more than one object. This number is based on the position (column) of the variable in the results file. The default is to read the first instance.

Value

Returns a matrix containing the selected variables' time series contained in the results file.

Note

This function is useful to extract time series for variables that are single instanced, like summary statistics. For multi-instanced variables, see read.multi.lsd. For extracting data from multiple similar files (like sensitivity analysis results), see read.list.lsd (multi-instanced variables) and read.3d.lsd (single-instanced variables).

Author(s)

Marcelo C. Pereira

See Also

read.multi.lsd, read.list.lsd, read.3d.lsd, read.4d.lsd, read.raw.lsd

Examples

# Save current work directory and change to the examples directory
currWD <- getwd()
setwd(system.file("extdata", package = "LSDinterface"))

# Load a sample .res file into a simple matrix (first instances only)
macroVar <- read.single.lsd("Sim1_1.res")

# See matrix in the data viewer (require package 'utils')
#View(macroVar)

# read second instance of a set of variables named '_A1p' and '_growth1'
ag2Table <- read.single.lsd("Sim1_2.res.gz", c("_A1p", "_growth1"), instance = 2)
#View(ag2Table)

# reads first instance of all variables, skipping the initial 20 time steps
# and keeping up to 50 time steps (from t = 21 up to t = 70)
var21_70 <- read.single.lsd("Sim1_1.res", skip = 20, nrows = 50)
#View(var21_70)

# Restore working directory
setwd(currWD)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(LSDinterface)
Loading required package: abind
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LSDinterface/read.single.lsd.Rd_%03d_medium.png", width=480, height=480)
> ### Name: read.single.lsd
> ### Title: Read LSD variables (time series) from a LSD results file (a
> ###   single instance of each variable only)
> ### Aliases: read.single.lsd
> ### Keywords: ~kwd1 ~kwd2
> 
> ### ** Examples
> 
> # Save current work directory and change to the examples directory
> currWD <- getwd()
> setwd(system.file("extdata", package = "LSDinterface"))
> 
> # Load a sample .res file into a simple matrix (first instances only)
> macroVar <- read.single.lsd("Sim1_1.res")
> 
> # See matrix in the data viewer (require package 'utils')
> #View(macroVar)
> 
> # read second instance of a set of variables named '_A1p' and '_growth1'
> ag2Table <- read.single.lsd("Sim1_2.res.gz", c("_A1p", "_growth1"), instance = 2)
> #View(ag2Table)
> 
> # reads first instance of all variables, skipping the initial 20 time steps
> # and keeping up to 50 time steps (from t = 21 up to t = 70)
> var21_70 <- read.single.lsd("Sim1_1.res", skip = 20, nrows = 50)
> #View(var21_70)
> 
> # Restore working directory
> setwd(currWD)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>