<<

The phpSerialize Package

March 9, 2005

Title Serialize to PHP

Version 0.8-01

Author Dieter Menne

Description Serializes R objects for import by PHP into an associative array. Can be used to build interactive web pages with R.

Maintainer Dieter Menne

License GPL version 2 or newer

R topics documented:

phpSerialize ...... 1

Index 4

phpSerialize R to PHP Serialization

Description

Serializes R objects for PHP import into an associative array. Main use is for building web pages with R-support.

Usage

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)

1 2 phpSerialize

Arguments 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, 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.

Details 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.

Value Returns a string if file=NULL, or NULL if a file argument was supplied. For example, phpSerialize(("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.

Note Code was tested mainly with lm, lme and nlme.

Author(s) Dieter Menne h([email protected])i

References Serialize PHP: http://jpspan.sourceforge.net/examples/serialize_php.php. Manual PHP: http://www.php.net/manual/en/index.php phpSerialize 3

See Also capture.output

Examples # 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) Index

∗Topic connection phpSerialize, 1 ∗Topic phpSerialize, 1 capture.output, 2 phpSerialize, 1 phpSerializeAll (phpSerialize), 1

4