This function JS() marks character vectors with a special class, so that it will be treated as literal JavaScript code when evaluated on the client-side.

JS(...)

Arguments

...

character vectors as the JavaScript source code (all arguments will be pasted into one character string)

Author

Yihui Xie

Examples

library(htmlwidgets) JS('1 + 1')
#> [1] "1 + 1" #> attr(,"class") #> [1] "JS_EVAL"
list(x = JS('function(foo) {return foo;}'), y = 1:10)
#> $x #> [1] "function(foo) {return foo;}" #> attr(,"class") #> [1] "JS_EVAL" #> #> $y #> [1] 1 2 3 4 5 6 7 8 9 10 #>
JS('function(x) {', 'return x + 1;', '}')
#> [1] "function(x) {\nreturn x + 1;\n}" #> attr(,"class") #> [1] "JS_EVAL"