writeList {PBSmodelling} | R Documentation |
Write an ASCII text representation in either "D"
format or "P"
format.
The "D"
format makes use of dput
and dget
, and produces an R
representation of the list. The "P"
format represents a simple list in an
easy-to-read, ad hoc PBSmodelling
format.
writeList(x, fname, format="D", comments="")
x |
R list object to write to an ASCII text file. |
fname |
file name of the text file containing the list. |
format |
format of the file to create: "D" or "P" . |
comments |
vector of character strings to use as initial-line comments in the file. |
The "D"
format is equivalent to using R's base
functions
dput
and dget
, which support all R objects.
The "P"
format only supports named lists of vectors, matrices, arrays, and data frames.
Scalars are treated like vectors. Nested lists are not supported.
The "P"
format writes each named element in a list using the
following conventions: (i) $ followed by the name of the data object
to denote the start of that object's description; (ii) $$ on the next line
to describe the object's structure - object type, mode(s), names (if vector),
rownames (if matrix or data), and colnames (if matrix or data); and
(iii) subsequent lines of data (one line for vector, multiple lines for matrix or data).
Multiple rows of data for matrices or data frames must have equal numbers of entries (separated by whitespace).
Using "P"
formatting, array data are written the same way that
they are displayed in the R console:
nrow=dim()[1]
, ncol=dim()[2]
repeated by scrolling through successively higher dimensions, increasing the
index from left to right within each dimension. The flattened table will have
dim()[2]
columns.
For complete details, see “PBSmodelling-UG.pdf” in the
R directory .../library/PBSmodelling/doc
.
readList
, openFile
, unpackList
, packList
## Not run: test <- list(a=10,b=euro,c=view(WorldPhones),d=view(USArrests)) writeList(test,"test.txt",format="P", comments=" Scalar, Vector, Matrix, Data Frame") openFile("test.txt") ## End(Not run)