Home Reference Source
import R from 'libr-bridge/R'
public class | source

R

Class for accessing R via libR.

Static Member Summary

Static Public Members
public static get

Acquire global environment in R.

public static get

libR: Object: *

Initialized libR object for accessing R.

Static Method Summary

Static Public Methods
public static

Check whether R class is globally initialized or not.

public static

range(a: integer, b: integer): Array

Python like range function.

Constructor Summary

Public Constructor
public

Constructor function for class R

Member Summary

Public Members
public

[e]: *

Method Summary

Public Methods
public

eval(code: string, silent: boolean): *

Execute R code.

public

evalWithTry(code: string, silent: boolean): *

Execute R code with R try.

public

Execute R code without error handling.

public

eval_raw(code: string, silent: boolean): SEXPWrap

Execute R code.

public

func(name: string): function

Acquire bridging function to access R function.

public

Acquire bridging function to access R function.

public

getVar(varname: string): *

Acquire value of R variable

public

Acquire names attribute of R variable

public

Set callback on R's computation.

public

overrideReadConsole(onReadConsole: function)

Use your own console input/output instead of R's default one.

public

Use your own console input/output instead of R's default one.

public

overrideWriteConsole(onWriteConsole: function)

Use your own console input/output instead of R's default one.

public

Finish using R.

public

setVar(varname: string, value: object)

Set value to R variable

public

setVarNames(varname: string, value: object)

Set names attribute to R variable

Private Methods
private

Bridging function for R function.

private

Bridging function for R function.

private

__eval_langsxp(langsxp: *, silent: boolean): *

Execute R code with LANGSXP

private

Find functions in R environment.

private

Load some R functions.

Static Public Members

public static get GlobalEnv: boolean: * source

Acquire global environment in R.

Return:

boolean

SEXP of global environment.

public static get libR: Object: * source

Initialized libR object for accessing R.

Return:

Object

libR

Static Public Methods

public static isInitialized(): boolean source

Check whether R class is globally initialized or not.

Return:

boolean

Returns true if R is already loaded.

public static range(a: integer, b: integer): Array source

Python like range function. Be careful, this is not R ':' operator range(0, 3) == [0, 1, 2], which is not eq. to 0:3

Params:

NameTypeAttributeDescription
a integer

from

b integer

to (this value won't be included)

Return:

Array

value in a <= x < b. range(0, 3) == [0, 1, 2]

Public Constructors

public constructor() source

Constructor function for class R

Public Members

public [e]: * source

Public Methods

public eval(code: string, silent: boolean): * source

Execute R code.

Params:

NameTypeAttributeDescription
code string

R code

silent boolean

Suppress error message if true.

Return:

*

JavaScript compatible object of returned value.

Throw:

Error

When execution fails.

Example:

	let value = R.eval("sum(c(1, 2, 3))")		// value will be 6

public evalWithTry(code: string, silent: boolean): * source

Execute R code with R try. This is more safe than R#eval.

Params:

NameTypeAttributeDescription
code string

R code

silent boolean

Suppress error message if true.

Return:

*

Returned value. Returns undefined on error.

public eval_direct(code: string): SEXPWrap source

Execute R code without error handling. App crashes when execution/parse failure. Please use this function with care.

Params:

NameTypeAttributeDescription
code string

R code

Return:

SEXPWrap

SEXPWrap object of returned value. Returns undefined on error.

See:

public eval_raw(code: string, silent: boolean): SEXPWrap source

Execute R code.

Params:

NameTypeAttributeDescription
code string

R code

silent boolean

Suppress error message if true.

Return:

SEXPWrap

SEXPWrap object of returned value. Returns undefined on error.

Throw:

Error

When execution fails.

See:

  • eval, R_ParseEvalString

public func(name: string): function source

Acquire bridging function to access R function. Functions receive JavaScript value, and returns JavaScript compatible objects.

Params:

NameTypeAttributeDescription
name string

name of R function

Return:

function

Bridging function

Example:

const sum = R.func("sum")
console.log(sum([1, 2, 3]))		// prints 6

public func_raw(name: string): function source

Acquire bridging function to access R function. This function doesn't convert to/from SEXP. Receives SEXPWrap, and returns SEXPWrap. Please use carefully.

Params:

NameTypeAttributeDescription
name string

name of R function

Return:

function

Bridging function

See:

public getVar(varname: string): * source

Acquire value of R variable

Params:

NameTypeAttributeDescription
varname string

Name of variable

Return:

*

Value in the R variable.

public getVarNames(varname: string): string source

Acquire names attribute of R variable

Params:

NameTypeAttributeDescription
varname string

Name of variable

Return:

string

Associated name attribute for the specified R variable. If no name, undefined will be returned.

public overrideBusy(onBusy: function) source

Set callback on R's computation.

Params:

NameTypeAttributeDescription
onBusy function

Function called on busy/job finish

public overrideReadConsole(onReadConsole: function) source

Use your own console input/output instead of R's default one.

Params:

NameTypeAttributeDescription
onReadConsole function

Function on console read

public overrideShowMessage(onMessage: function) source

Use your own console input/output instead of R's default one.

Params:

NameTypeAttributeDescription
onMessage function

Function on showing message

public overrideWriteConsole(onWriteConsole: function) source

Use your own console input/output instead of R's default one.

Params:

NameTypeAttributeDescription
onWriteConsole function

Function on console write

public release() source

Finish using R.

public setVar(varname: string, value: object) source

Set value to R variable

Params:

NameTypeAttributeDescription
varname string

Name of variable

value object

Value you want to set to variable.

public setVarNames(varname: string, value: object) source

Set names attribute to R variable

Params:

NameTypeAttributeDescription
varname string

Name of variable

value object

Value you want to set to names attributes

Private Methods

private __RFuncBridge(func: function): * source

Bridging function for R function. Please do not call this function manually.

Params:

NameTypeAttributeDescription
func function

SEXPWrap object of R function

Return:

*

JavaScript compatible returned value

private __RFuncBridge_raw(_func: function): SEXPWrap source

Bridging function for R function. This bridging function doesn't handle SEXP. Please do not call this function manually.

Params:

NameTypeAttributeDescription
_func function

SEXPWrap object of R function

Return:

SEXPWrap

SEXPWrap object of returned value

private __eval_langsxp(langsxp: *, silent: boolean): * source

Execute R code with LANGSXP

Params:

NameTypeAttributeDescription
langsxp *
silent boolean
  • optional
  • default: false

Return:

*

private __func_sexp(name: string): SEXPWrap source

Find functions in R environment. Please do not call this function manually.

Params:

NameTypeAttributeDescription
name string

name of function

Return:

SEXPWrap

SEXPWrap object of R function

private __initializeRfunc() source

Load some R functions. Please do not call manually.