To install the package, run:
remotes::install_github("extendr/rextendr")
Note that this will install the package but does not guarantee that the package can do anything useful. You will also need to set up a working Rust toolchain. See the installation instructions for libR-sys for help. If you can successfully build libR-sys you’re good.
Basic use example:
library(rextendr)
# create a Rust function
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")
# call it from R
add(2.5, 4.7)
#> [1] 7.2
The package also enables a new chunk type for knitr, extendr
, which
compiles and evaluates Rust code. For example, a code chunk such as this
one:
```{extendr}
rprintln!("Hello from Rust!");
let x = 5;
let y = 7;
let z = x*y;
z
```
would create the following output in the knitted document:
rprintln!("Hello from Rust!");
let x = 5;
let y = 7;
let z = x*y;
z
#> Hello from Rust!
#> [1] 35
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.