read.3d.lsd {LSDinterface} | R Documentation |
Read one instance of LSD variables (time series) from multiple LSD results files into a 3D array
Description
This function reads the data series associated to a specific instance of each selected variable from a set of LSD results files (.res) and saves them into a 3-dimensional array (time step x variable x file).
Usage
read.3d.lsd( files, col.names = NULL, nrows = -1, skip = 0,
check.names = TRUE, instance = 1, nnodes = 1,
posit = NULL, posit.match = c( "fixed", "glob", "regex" ) )
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, |
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 |
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 (1) is to read first instances. |
nnodes |
integer: the maximum number of parallel computing nodes (parallel threads) in the current computer to be used for reading the files. The default, |
posit |
a string, a vector of strings or an integer vector describing the LSD object position of the variable(s) to select. If an integer vector, it should define the position of a SINGLE LSD object. If a string or vector of strings, each element should define one or more different LSD objects, so the returning matrix may contain variables from more than one object. By setting |
posit.match |
a string defining how the |
Details
Selection restriction arguments can be provided as needed; when not specified, all available cases are considered, but just one instance
is considered.
When posit
is supplied together with col.names
or instance
, the selection process is done in two steps. Firstly, the column names and the instance position set by col.names
and instance
are selected. Secondly, the instances defined by posit
are selected from the first selection set.
See select.colnames.lsd
and select.colattrs.lsd
for examples on how to apply advanced selection options.
Value
Returns a 3D array containing data series from the selected variables.
The array dimension order is: time x variable x file.
Note
If the selected files don't have the same columns available (names and instances), after column selection, an error is produced.
Author(s)
Marcelo C. Pereira
See Also
list.files.lsd()
read.4d.lsd()
,
read.single.lsd()
,
read.multi.lsd()
,
read.list.lsd()
,
read.raw.lsd()
Examples
# get the list of file names of example LSD results
files <- list.files.lsd( system.file( "extdata", package = "LSDinterface" ) )
# read first instance of all variables from files (one level each),
# pasting the directory where the example files are (not required if in working dir)
inst1Array <- read.3d.lsd( files )
print( inst1Array[ 5 : 10, 1 : 7, 1 ] )
print( inst1Array[ 5 : 10, 1 : 7, 2 ] )
print( inst1Array[ 5 : 10, 1 : 7, 3 ] )
# read first instance of a set of variables named _A1p and _growth1
ab1Array <- read.3d.lsd( files, c( "_A1p", "_growth1" ) )
print( ab1Array[ 20 : 25, , 1 ] )
print( ab1Array[ 20 : 25, , 2 ] )
print( ab1Array[ 20 : 25, , 3 ] )
# read instance 2 of all variables, skipping the initial 20 time steps
# and keeping up to 30 time steps (from t = 21 up to t = 30)
inst2Array21_30 <- read.3d.lsd( files, skip = 20, nrows = 30, instance = 2 )
print( inst2Array21_30[ , , "Sim1_1" ] ) # use the file name to retrieve
print( inst2Array21_30[ , , "Sim1_2" ] )
# read instance 5 of all variables in second-level objects, using up to 2 cores
inst5array2 <- read.3d.lsd( files, instance = 2, posit = "*_*",
posit.match = "glob", nnodes = 2 )
print( inst5array2[ 11 : 20, , 1 ] )