Last data update: 2014.03.03

R: Read one or all instances of LSD variables (time series) from...
read.list.lsdR Documentation

Read one or all instances of LSD variables (time series) from a LSD results file into a list

Description

This function reads the data series associated to a specific or all instances of each selected variable from a LSD results file (.res) and saves them into separated matrices (one per variable).

Usage

read.list.lsd(files, col.names = NULL, nrows = -1, skip = 0,
              check.names = TRUE, instance = 0, pool = FALSE)

Arguments

files

a character vector containing the names of the LSD results files which the data are to be read from. If they do not contain an absolute path, the file names are relative to the current working directory, getwd(). These can be compressed files 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 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 (0) is to read all instances.

pool

logical. If TRUE, variables instances from all files are concatenated (by colums) into a single matrix. If FALSE (the default), each file is saved as a separated matrix.

Value

Returns a list containing matrices with the selected variables' time series in the results file. If 'pool = TRUE', the list contains a single, consolidated matrix (column names are not unique).

Note

When using the option 'pool = TRUE', columns from multiple files are consolidated with their original names, so names will not be unique anymore. You may use unique to change column names so they become unique, if required. The returned matrices may be potentially very wide, in particular if variables are not well selected(see col.names above) or if there is a large number of instances.

Author(s)

Marcelo C. Pereira

See Also

read.single.lsd, read.multi.lsd, read.3d.lsd, read.4d.lsd, read.raw.lsd, unique

Examples

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

# reads all instances of all variables from three files (one matrix each)
tableList <- read.list.lsd(c("Sim1_1.res", "Sim1_2.res", "Sim1_3.res"))

# See parts of the 3D array in the data viewer (require package 'utils')
#View(tableList[[ 1 ]])
#View(tableList[[ 2 ]])
#View(tableList[[ 3 ]])

# read all instances of a set of variables named '_A1p' and '_growth1'
# and pool data
abTable <- read.list.lsd(c("Sim1_1.res.gz", "Sim1_2.res.gz"), c("_A1p", "_growth1"), pool = TRUE)
#View(abTable)

# reads instance 4 of all variables, skipping the initial 20 time steps
# and keeping up to 50 time steps (from t = 21 up to t = 70)
inst4List21_70 <- read.list.lsd(c("Sim1_1.res", "Sim1_2.res"), skip = 20, nrows = 50, instance = 4)
#View(inst4List21_70[[ 1 ]])
#View(inst4List21_70[[ 2 ]])

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.list.lsd.Rd_%03d_medium.png", width=480, height=480)
> ### Name: read.list.lsd
> ### Title: Read one or all instances of LSD variables (time series) from a
> ###   LSD results file into a list
> ### Aliases: read.list.lsd
> ### Keywords: ~kwd1 ~kwd2
> 
> ### ** Examples
> 
> # Save current work directory and change to the examples directory
> currWD <- getwd()
> setwd(system.file("extdata", package = "LSDinterface"))
> 
> # reads all instances of all variables from three files (one matrix each)
> tableList <- read.list.lsd(c("Sim1_1.res", "Sim1_2.res", "Sim1_3.res"))
> 
> # See parts of the 3D array in the data viewer (require package 'utils')
> #View(tableList[[ 1 ]])
> #View(tableList[[ 2 ]])
> #View(tableList[[ 3 ]])
> 
> # read all instances of a set of variables named '_A1p' and '_growth1'
> # and pool data
> abTable <- read.list.lsd(c("Sim1_1.res.gz", "Sim1_2.res.gz"), c("_A1p", "_growth1"), pool = TRUE)
> #View(abTable)
> 
> # reads instance 4 of all variables, skipping the initial 20 time steps
> # and keeping up to 50 time steps (from t = 21 up to t = 70)
> inst4List21_70 <- read.list.lsd(c("Sim1_1.res", "Sim1_2.res"), skip = 20, nrows = 50, instance = 4)
> #View(inst4List21_70[[ 1 ]])
> #View(inst4List21_70[[ 2 ]])
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>