R API

The webR R API is provided via a pre-installed webr support package.

Evaluate JavaScript code

Description

This function evaluates the given character string as JavaScript code. The result is returned as an integer.

Usage

eval_js(code)

Arguments

code

The JavaScript code to evaluate.

Details

The JavaScript code is evaluated using emscripten_run_script_int from the Emscripten C API. In the event of a JavaScript exception an R error condition will be raised with the exception message.

This is an experimental function that may undergo a breaking change in the future so as to support different return types.

Value

Integer result of evaluating the code.

Evaluate R code for webR

Description

This function evaluates the provided R code with various settings in place to configure behavior. The function is intended to be used by the webR evalR API, rather than invoked directly by the end user.

Usage

eval_r(
  code,
  conditions = TRUE,
  streams = FALSE,
  autoprint = FALSE,
  handlers = TRUE,
  env = parent.frame()
)

Arguments

code

The R code to evaluate.

conditions

If TRUE, capture and return conditions raised during execution.

streams

If TRUE, capture and return the stdout and stderr streams.

autoprint

If TRUE, code automatically prints as if it were written at an R console.

handlers

If TRUE, execute the R code using a tryCatch, with handlers in place.

env

The environment in which to evaluate.

Prompt user to install missing packages from a webR binary repo

Description

When enabled, packageNotFoundError errors cause a menu prompt to be shown to the user asking if they would like to attempt to download the missing package.

If the user replies in the negative, the package error is thrown as it would normally. If the user replies in the affirmative, the package is downloaded using install().

If it is possible to do so, execution will continue without interrupting the current program.

Usage

global_prompt_install()

Install one or more packages from a webR binary package repo

Description

Install one or more packages from a webR binary package repo

Usage

install(packages, repos = NULL, lib = NULL)

Arguments

packages

Character vector containing the names of packages to install.

repos

Character vector containing the URIs of the webR repos to use.

lib

The library directory where the packages will be installed.

Test an installed R package by running the package examples and tests

Description

This function runs R package examples and tests. The implementation is based on tools::testInstalledPackage(), with modifications for webR where the system() function cannot be used.

Usage

test_package(pkg)

Arguments

pkg

Name of the package to test.

Value

0 if the test was successful, otherwise 1.