phpSerialize          package:phpSerialize          R Documentation

_R _t_o _P_H_P _S_e_r_i_a_l_i_z_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     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)

_A_r_g_u_m_e_n_t_s:

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

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

     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.

_N_o_t_e:

     Code was tested mainly with lm, lme and nlme.

_A_u_t_h_o_r(_s):

     Dieter Menne (dieter.menne@menne-biomed.de)

_R_e_f_e_r_e_n_c_e_s:

     Serialize PHP: <URL:
     http://jpspan.sourceforge.net/examples/serialize_php.php>.  Manual
     PHP: <URL: http://www.php.net/manual/en/index.php>

_S_e_e _A_l_s_o:

     'capture.output'

_E_x_a_m_p_l_e_s:

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

