File: JS.R

package info (click to toggle)
r-cran-v8 2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 476 kB
  • sloc: cpp: 977; sh: 68; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#' Mark character strings as literal JavaScript code
#'
#' This function \code{JS()} marks character vectors with a special class, so
#' that it will be treated as literal JavaScript code. It was copied from the
#' htmlwidgets package, and does exactly the same thing.
#'
#' @param ... character vectors as the JavaScript source code (all arguments
#'   will be pasted into one character string)
#' @author Yihui Xie
#' @export
#' @examples ct <- v8()
#' ct$eval("1+1")
#' ct$eval(JS("1+1"))
#' ct$assign("test", JS("2+3"))
#' ct$get("test")
JS <- function(...) {
  x <- c(...)
  if (is.null(x)) return()
  if (!is.character(x))
    stop("The arguments for JS() must be a chraracter vector")
  x <- paste(x, collapse = '\n')
  structure(x, class = unique(c("JS_EVAL", oldClass(x))))
}