Description Usage Arguments Value Note Author(s) References See Also Examples
This function takes an R language object or a file containing
R code and attempts to convert it to equivalent JavaScript code.
It provides ways to merge R objects into the code (via the
substitute
parameter).
1 | jsTranslate(code, substitute = list(), jsGlobals = character(), addSemiColon = NA, ...)
|
code |
either a language object (e.g. an expression, call, if statement, etc.) or the name of file containing R code. |
substitute |
a list of R objects that can be inlined within the generated JavaScript code. These are serialized to JSON format and any reference to these values in the code causes this JSON representation to be substituted. |
jsGlobals |
the names of variables that are to be considered global in the JavaScript code. |
addSemiColon |
currently ignored. |
... |
for methods to add parameters that they understand. |
A string giving the JavaScript code. This is of class "JavaScriptCode". We may introduce additional sub-classes, e.g. JavaScriptFunction
We might do more work to identify the global variables and also to identify where JavaScript variables should be declared, i.e. where to place the "var" declaration.
Duncan Temple Lang
JavaScript: The Definitive Guide, David Flanagan, O'Reilly \& Associates, Inc.
See the jsRewrite
function and its methods for how the
translation is done.
1 2 3 4 5 6 7 8 9 10 11 12 | jsTranslate(quote(if(is(x, "numeric")) x))
jsTranslate(quote( x <- x + 1))
# Rewrite a function.
f = system.file("sampleCode", "function.R", package = "RJavaScript")
jsTranslate(f)
# Replace references to R variables.
f = system.file("sampleCode", "assign.R", package = "RJavaScript")
jsTranslate(f, list(init = c(1, 2, 3)))
jsTranslate(f, list(init = c(1, 2, 3), w = list(abc = 1, xyz = "foo")))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.