Title: | Develop R Packages using Rust |
Version: | 0.4.9 |
Description: | A framework is provided to develop R packages using 'Rust' https://www.rust-lang.org/ with minimal overhead, and more wrappers are easily added. Help is provided to use 'Cargo' https://doc.rust-lang.org/cargo/ in a manner consistent with CRAN policies. 'Rust' code can also be embedded directly in an R script. The package is not official, affiliated with, nor endorsed by the Rust project. |
URL: | https://github.com/dbdahl/cargo-framework (repository) |
BugReports: | https://github.com/dbdahl/cargo-framework/issues |
License: | MIT + file LICENSE | Apache License 2.0 |
Depends: | R (≥ 4.2.0) |
Suggests: | roxygen2 (≥ 7.2.3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-07-17 19:35:31 UTC; dahl |
Author: | David B. Dahl |
Maintainer: | David B. Dahl <dahl@stat.byu.edu> |
Repository: | CRAN |
Date/Publication: | 2023-07-17 20:20:05 UTC |
Browse API Documentation
Description
This function opens in a web browser the documentation of the Rust API.
Usage
api_documentation()
Value
NULL
, invisibly.
Identify Authorship of Rust Crates
Description
Since depending crates are vendored by the build_for_cran
function, the authorship and copyright must be
declared in the DESCRIPTION
file prior to building the source package
for The Comprehensive R Archive Network (CRAN). This function helps to identify these attributions but is not
guaranteed to the exhaustive, so manual inspection in warranted before submitting to CRAN.
Usage
authors()
Value
NULL
, invisibly.
Build a Source Package for Submission to CRAN
Description
This function builds a source package in preparation for submission to
The Comprehensive R Archive Network (CRAN).
and saved it in the root of a package.
In particular, Rust crates upon which the package depends are “vendored”
within the source package in the archive file src/rust/vendor.tar.xz
, so
that lacking internet access will not give a check warning nor error on CRAN.
The package's configure
script tests for the existence of this archive
file and, when present, runs Cargo (Rust's package manager) in compliance with the
CRAN Repository Policies
in that Cargo will only use two CPU cores and will clean-up cached values (i.e.,
remove detritus).
Usage
build_for_cran(...)
Arguments
... |
Options passed to |
Details
Since depending crates are vendored, the authorship and copyright must be
declared in the DESCRIPTION
file prior to building the source package
for CRAN. See the authors
function for help in attribution.
This function will rebuild roxygen2 documentation if the DESCRIPTION file indicates that roxygen2 is used and the package is installed.
This function does not test the package. The developer is strongly encouraged to both inspect and test the package before submitting to CRAN.
Value
The exit status codeR CMD build, invisibly.
Install Rust Toolchain
Description
This function downloads the ‘rustup’ installer, run it, and adds targets to compile for all the CRAN build machines.
Usage
install(force = FALSE)
Arguments
force |
If |
Value
Invisibly, TRUE
if successful and FALSE
otherwise.
Make a Skeleton for a New Package
Description
A new Rust-based package is created at the supplied path and the package is installed.
Usage
new_package(path)
Arguments
path |
A path where the package is created. The name of the package is taken as the last element in the file path. |
Run Cargo
Description
This function runs Cargo (Rust's package manager) with the ...
arguments passed as command line arguments.
Usage
run(
...,
minimum_version = ".",
search_methods = c("cache", "convention", "path"),
leave_no_trace = FALSE,
environment_variables = list(),
rustflags = NULL,
verbose = TRUE,
run_twice = FALSE,
stdout = "",
stderr = ""
)
Arguments
... |
Character vector of command line arguments passed to the
|
minimum_version |
A character string representing the minimum version of
Rust that is needed. Or a path to the root of a package (i.e., the
directory containing the DESCRIPTION file), in which case the value is
found from the field: |
search_methods |
A character vector potentially containing values
|
leave_no_trace |
If |
environment_variables |
A named character vector providing environment
variables which should be temporarily set while running Cargo. Note that
the |
rustflags |
A character vector from which the
|
verbose |
If |
run_twice |
Should the cargo command be run twice? The environment
variable |
stdout |
See argument of the same name in |
stderr |
See argument of the same name in |
Value
The same value and behavior as the base::system2()
function, except
a non-zero exit code will be given in Cargo is not found.
Examples
if (run("--version") != 0) {
message("Cargo is not installed. Please run cargo::install() in an interactive session.")
}
Define an R Function Implemented in Rust
Description
This function takes Rust code as a string from the last unnamed argument, takes variable names for all other unnamed arguments, compiles the Rust function, and wraps it as an R function.
Usage
rust_fn(
...,
dependencies = character(0),
minimum_version = "1.31.0",
verbose = FALSE,
cached = TRUE,
longjmp = TRUE,
invisible = FALSE,
force = FALSE
)
Arguments
... |
Rust code is taken as a string from the last unnamed argument, and variable names come for all other unnamed arguments. See example. |
dependencies |
A character vector of crate dependencies, e.g.,
|
minimum_version |
A character string representing the minimum version of
Rust that is needed. Or a path to the root of a package (i.e., the
directory containing the DESCRIPTION file), in which case the value is
found from the field: |
verbose |
If |
cached |
Should Cargo use previously compiled artifacts? |
longjmp |
Should the compiled function use the faster (but experimental) longjmp functionality when Rust code panics? |
invisible |
Should the compiled function return values invisibly? |
force |
If |
Value
An R function implemented with the supplied Rust code.