# r-wrapper

> A simple R wrapper

Latest version **1.1.2** (published 2021-05-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install r-wrapper
pnpm add r-wrapper
yarn add r-wrapper
bun add r-wrapper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-05-18 |
| First published | 2019-09-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | park-brian |
| Maintainers | re.public |
| Keywords | r, wrapper |

## Links

- npm: https://www.npmjs.com/package/r-wrapper
- Repository: https://github.com/park-brian/r-wrapper
- Issues: https://github.com/park-brian/r-wrapper/issues
- npm.io page: https://npm.io/package/r-wrapper

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2021-05-18
- 1.1.1 — 2021-05-18
- 1.1.0 — 2020-09-09
- 1.0.3 — 2020-06-16
- 1.0.2 — 2019-10-11
- 1.0.1 — 2019-09-23
- 1.0.0 — 2019-09-23

## README

# r-wrapper

### Prerequisites
- Node.js 8+
- R 3.0+
  - jsonlite


### Installing
Ensure that R is in the current user's PATH.

```bash
# install jsonlite (note: Rscript.exe does not pick up all .libPaths() by default unless R_LIBS_USER is set, so the command below installs to the default .Library location)
Rscript -e "install.packages('jsonlite', repos='https://cloud.r-project.org/', lib = .Library)"

npm install --save r-wrapper
```

### Example file: _test.R_
```R
add <- function(a, b) {
    a + b
}

greet <- function(name, adjective) {
    paste('Hello', name, 'the', adjective)
}
```

### Example: run functions from _test.R_
```javascript
const r = require('r-wrapper');

// positional parameters are passed in through arrays
const sum = r('test.R', 'add', [2, 3]);
console.log(sum); // 5

// named parameters are passed in through objects
const greeting = r('test.R', 'greet', {
    name: 'John',
    adjective: 'Wise',
});
console.log(greeting); // "Hello John the Wise"

// child_process.execFileSync options can also be supplied
r('test.R', 'add', [1, 2], {
    /*
     * input: '...',
     * stdio: '...',
     * cwd: '...',
     * env: {...},
     * maxBuffer: x,
     * ...
     */
});
```


### Example: run functions from _test.R_ asynchronously
```javascript
const r = require('r-wrapper').async;

// assuming we have top-level await support, or the following code is executed inside an async function

// positional parameters are passed in through arrays
const sum = await r('test.R', 'add', [2, 3]);
console.log(sum); // 5

// named parameters are passed in through objects
const greeting = await r('test.R', 'greet', {
    name: 'John',
    adjective: 'Wise',
});
console.log(greeting); // "Hello John the Wise"

// child_process.execFile options can also be supplied
await r('test.R', 'add', [1, 2], {
    /*
     * cwd: '...',
     * env: {...},
     * maxBuffer: x,
     * ...
     */
});
```

### Notes

- To prevent atomic vectors of length 1 from being unboxed, wrap them with `I()`

---
_Source: https://npm.io/package/r-wrapper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
