Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
extendr-api
A safe and user friendly R extension interface.
- Build rust extensions to R.
- Convert R packages to Rust crates.
This library aims to provide an interface that will be familiar to first-time users of Rust or indeed any compiled language.
See [Robj] for much of the content of this crate. [Robj] provides a safe wrapper for the R object type.
Use attributes and macros to export to R.
use *;
// Export a function or impl to R.
// define exports using extendr_module
extendr_module!
In R:
result <- fred
[Robj] is a wrapper for R objects. The r!() and R!() macros let you build R objects using Rust and R syntax respectively.
use *;
test!
In Rust, we prefer to use iterators rather than loops.
use *;
test!
To index a vector, first convert it to a slice and then remember to use 0-based indexing. In Rust, going out of bounds will cause and error (a panic) unlike C++ which may crash.
use *;
test!
Much slower, but more general are these methods:
use *;
test!
The [R!] macro lets you embed R code in Rust and takes Rust expressions in {{ }} pairs.
The [Rraw!] macro will not expand the {{ }} pairs.
use *;
test!
The [r!] macro converts a rust object to an R object and takes parameters.
use *;
test!
You can call R functions and primitives using the [call!] macro.
use *;
test!
Rust has a concept of "Owned" and "Borrowed" objects.
Owned objects, such as [Vec] and [String] allocate memory which is released when the object lifetime ends.
Borrowed objects such as &[i32] and &str are just pointers to annother object's memory and can't live longer than the object they reference.
Borrowed objects are much faster than owned objects and use less memory but are used only for temporary access.
When we take a slice of an R vector, for example, we need the original R object to be alive or the data will be corrupted.
use *;
test!
Feature gates
extendr-api has some optional features behind these feature gates:
ndarray
: provides the conversion between R's matrices and ndarray.num-complex
: provides the conversion between R's complex numbers and num-complex.serde
: provides the Serde support.graphics
: provides the functionality to control or implement graphics devices.
License
MIT