Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tianyishi2001/r-helper-js

Helper functions for calling R in Node.js
https://github.com/tianyishi2001/r-helper-js

Last synced: about 1 month ago
JSON representation

Helper functions for calling R in Node.js

Awesome Lists containing this project

README

        

# r-helper-js

Helper functions for calling R in Node.js

## Installation

```bash
npm i r-helper
```

```typescript
import { Rcall, Rscript } from 'r-helper';
```

## Demos

## `Rcall()`

Construct a R function call as a string:

```javascript
// construct R function call (as a string) without arguments
Rcall("fun")
// --> fun()

// construct R function call with different primitive types"
Rcall("fun", [114, 5.14, true, false], { foo: "bar", baz: undefined })
// --> fun(114,5.14,TRUE,FALSE,foo="bar",baz=NA)

// construct nested call
Rcall("foo", [1, Rcall("bar", ["two", Rcall("baz", [true])])])
// --> foo(1,bar("two",baz(TRUE)))
```

### Signature of `Rcall()`

```typescript
function Rcall(Rfunction, args?: RArgs, kwargs?: RKwargs): RCall {/*...*/}
```

where:

```typescript
type RCall = string; // matches /.+\(.*\)/
type RArg = string | number | boolean | undefined | RCall;
type RArgs = Array;
type RKwargs = { [k: string]: RArg };
```

## `Rscript`

Make an Rscript command ready for execution in shell:

```typescript
Rscript(Rcall("foo", [1, Rcall("bar", ["two", Rcall("baz", [true])])]))
// Rscript -e 'foo(1,bar("two",baz(TRUE)))'
```