Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable webr::eval_js() to return other types of R object #483

Merged
merged 10 commits into from
Sep 19, 2024

Conversation

georgestagg
Copy link
Member

With this, the webr::eval_js() function can now return other types of R object, not just scalar integers. Returned JavaScript objects are converted to R objects using the RObject generic constructor, and specific R object types can be returned by invoking the R object constructor directly in the evaluated JavaScript.

Examples:

> webr::eval_js("123 + 456")
[1] 579

> webr::eval_js("Math.sin(1)")
[1] 0.841471

> webr::eval_js("(new Date()).toUTCString()")
[1] "Wed, 18 Sep 2024 09:39:54 GMT"

> webr::eval_js("new RList({ foo: 123, bar: 456, baz: ['a', 'b', 'c']})")
$foo
[1] 123

$bar
[1] 456

$baz
$baz[[1]]
[1] "a"

$baz[[2]]
[1] "b"

$baz[[3]]
[1] "c"

@georgestagg georgestagg merged commit be0e296 into main Sep 19, 2024
4 checks passed
@georgestagg georgestagg deleted the eval-js-robj branch September 19, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant