| phpSerialize {phpSerialize} | R Documentation |
Serializes R objects for PHP import into an associative array. Main use is for building web pages with R-support.
phpSerialize(x, file = NULL, append = FALSE, associative = "1D", simplifyMono=TRUE, phpTestCode = FALSE) phpSerializeAll(include=NULL, exclude=NULL, file = NULL, append = FALSE, associative = "1D", simplifyMono=TRUE, phpTestCode = FALSE)
x |
an object |
file |
a file name or a connection, or NULL to return the output as a string. If the connection is not open it will be opened and then closed on exit. |
append |
append or overwrite the file? |
associative |
a character string of "1D" (default),
"2D" or "no". For "1D", only scalars
and vectors are serialized as associative arrays which can
be retrieved by name, while arrays are exported with numeric indexes.
For "2D", arrays are also exported by name. For "no",
objects are serialized with numerical indexes only, and factors are
serialized as integers. |
simplifyMono |
if TRUE (default), unnamed vectors of length 1
are reduced to scalars, which is easier to understand in PHP.
For simplyMono=FALSE, these vectors are serialized as arrays
with length 1. We need another level of indexing ([1]) in PHP,
but we are closer to the way R ticks. Named vectors are are always
serialized as arrays to preserve the name, even if associative="no".
|
phpTestCode |
if TRUE, php test code for direct display of the associative PHP-array is added. |
include |
a vector of characters strings of the objects in
ls(1) to be serialized. If NULL, all ls(1)
objects will be serialized. Partial matching is used, so
with include="lm.", objects like lm.test and lm.best
are included. |
exclude |
a vector of character strings of objects excluded from
serialization. Partial matching is used, so exclude="HTML" will
remove objects like HTMLAll and HTMLlme, but not myHTML.
Items in exclude have precedence over those in include. |
See the sample directory for an extended test case and
the web directory for an Apache-tested web application.
Matrices with dimensions > 2 and complex numbers are currently not supported.
Returns a string if file=NULL, or NULL if a file argument was supplied.
For example, phpSerialize(c("a","b")) produces the output string
a:2:{i:1;s:1:"a";i:2;s:1:"b";},
giving Array([1]=>a,[2]=>b) after unserializing in PHP.
Code was tested mainly with lm, lme and nlme.
Dieter Menne (dieter.menne@menne-biomed.de)
Serialize PHP: http://jpspan.sourceforge.net/examples/serialize_php.php. Manual PHP: http://www.php.net/manual/en/index.php
# htest object
wc = wilcox.test(rnorm(10)+2,rnorm(10)+5)
phpSerialize(wc)
#lm summary
group = gl(2,10,20, labels=c("Ctl","Trt"))
weight = c(rnorm(10)+10, rnorm(10)+6)
sumlm = summary(lm(weight ~ group))
phpSerialize(sumlm,phpTestCode=TRUE)
phpSerializeAll(include="w",exclude="sum",phpTestCode=TRUE)