Last data update: 2014.03.03

R: Serialize R objects as Javsscript/ActionScript variables
asJSVarsR Documentation

Serialize R objects as Javsscript/ActionScript variables

Description

This function takes R objects and serializes them as Javascript/ActionScript values. It uses the specified names in the R call as Javascript variable names. One can also specify qualifiers (‘public’, ‘protected’, ‘private’) and also types. These are optional, but useful, in ActionScript.

Usage

asJSVars(..., .vars = list(...), qualifier = character(), types = character())

Arguments

...

name = value pairs where the value is an R object that is converted to JSON format and name is the name of the corresponding Javascript variable.

.vars

this is an alternative to ... as a way to specify a collection of name = value pairs that is already in a list.

qualifier

a character vector (recycled as necessary) which is used as qualifiers for the individual ActionScript variables. The values should be public, protected or private.

types

either a logical value or a character vector (which is recycled if necessary). If this is TRUE, then we compute the Javascript type for each of the R objects (using the non-exported function jsType)

Value

A character vector of length 1 giving the variable declarations and initializations.

Author(s)

Duncan Temple Lang <duncan@wald.ucdavis.edu>

See Also

toJSON

Examples

 cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5)))
 cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5), types = TRUE))
 cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5),
        qualifier = "protected", types = TRUE))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(RJSONIO)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RJSONIO/asJSVars.Rd_%03d_medium.png", width=480, height=480)
> ### Name: asJSVars
> ### Title: Serialize R objects as Javsscript/ActionScript variables
> ### Aliases: asJSVars
> ### Keywords: IO programming
> 
> ### ** Examples
> 
>  cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5)))
a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ;

myMatrix = [ [ 1, 4, 7, 10, 13 ],
           [ 2, 5, 8, 11, 14 ],
           [ 3, 6, 9, 12, 15 ] ] ;>  cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5), types = TRUE))
a : Array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ;

myMatrix : Array = [ [ 1, 4, 7, 10, 13 ],
                   [ 2, 5, 8, 11, 14 ],
                   [ 3, 6, 9, 12, 15 ] ] ;>  cat(asJSVars( a =  1:10, myMatrix = matrix(1:15, 3, 5),
+         qualifier = "protected", types = TRUE))
protected a : Array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ;

protected myMatrix : Array = [ [ 1, 4, 7, 10, 13 ],
                             [ 2, 5, 8, 11, 14 ],
                             [ 3, 6, 9, 12, 15 ] ] ;> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>