R/JSconsole.R

Defines functions JSconsole

#' @import V8 rstudioapi
#' @noRd
JSconsole <- function(){
  editor <- getSourceEditorContext()
  selection <- editor[["selection"]][[1L]][["text"]]
  code <- ifelse(selection != "",
                 selection,
                 paste0(editor[["contents"]], collapse = "\n"))
  ctx <- v8()
  if(ctx$validate(code)){
    ctx$eval(code)
    ctx$console()
  }else{
    message("Invalid code.")
    invisible()
  }
}

Try the JSconsole package in your browser

Any scripts or data that you put into this service are public.

JSconsole documentation built on Oct. 23, 2020, 5:19 p.m.