hellorust

Template R package with rust bindings

https://github.com/r-rust/hellorust

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.1%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Template R package with rust bindings

Basic Info
  • Host: GitHub
  • Owner: r-rust
  • License: other
  • Language: R
  • Default Branch: master
  • Homepage:
  • Size: 60.5 KB
Statistics
  • Stars: 278
  • Watchers: 8
  • Forks: 22
  • Open Issues: 0
  • Releases: 4
Created over 8 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.md

Hello Rust

R build status

Minimal Examples of Using Rust Code in R

Rust is a modern alternative to C and compiled rust code is ABI compatible with C. Many Rust libraries include C API headers so that the compiled rust code can be called from R/C/C++ as if it were C code. This package shows how to do this. The r-rust organization contains several more simple R packages interfacing with cargo crates.

To learn more about using Rust code in R packages, also have a look at the r-rust FAQ and the slides about this project presented at eRum2018!

Package Structure

Bundle your rust code in a the embedded cargo package (see the Cargo.toml file) and then the src/Makevars file is written such that R will automatically build the rust modules when the R package is installed.

hellorust ├─ configure ← checks if 'cargo' is installed ├─ src │ ├─ myrustlib ← bundled cargo package with your code │ | ├─ Cargo.toml ← cargo dependencies and metadata │ | ├─ src ← rust source code │ | └─ api.h ← C headers for exported rust API | | │ ├─ Makevars ← Ties everything together │ └─ wrapper.c ← C code for R package ├─ DESCRIPTION └─ R ← Standard R+C stuff

Vendoring

As per the new 2023 cran guidelines we now vendor the cargo crates in the R source packages in order to support offline installation. This is done in a two step process:

  1. (by package author) The vendor-update.sh script creates the vendor.tar.xz bundle that contains all the cargo sources. In addition, the vendor-authors.R script generates an inst/AUTHORS file that lists the authors of the dependencies, as required by CRAN. Both of these scripts are called in the package cleanup file and therefore run automatically during R CMD build when the source package is created.
  2. (by the user) At install time, the Makevars extracts the vendor.tar.xz bundle (when available) and generates a .cargo/config.toml file to instruct cargo build to use the vendored (offline) sources.

If you run R CMD INSTALL directly from a checkout (without building a source package), then no vendor.tar.xz is created and cargo falls back to downloading crates on-the-fly.

You can test or force the use of vendored sources by passing --offline to cargo build.

Installing this package

If Rust is available, clone this repository and run the regular R CMD INSTALL command:

R CMD INSTALL hellorust

Alternatively, to download and install from within R itself:

```r

install.packages("remotes")

remotes::install_github("r-rust/hellorust") ```

What is Cargo

The standard rust toolchain includes a great package manager cargo with a corresponding registry crates.io. Cargo makes it very easy to build a rust package including all dependencies into a static library that can easily be linked into an R package.

This is perfect for R because we can compile and link all rust code at build-time without any system dependencies. Rust itself has no substantial runtime so the resulting R package is entirely self contained. Indeed, rust has been designed specifically to serve well as an embedded language.

Installing Rust on Linux / MacOS

Note that cargo is only needed at build-time. Rust has no runtime dependencies. The easiest way to install the latest version of Rust (including cargo) is from: https://www.rust-lang.org/tools/install

Alternatively, you may install cargo from your OS package manager:

  • Debian/Ubuntu: sudo apt-get install cargo
  • Fedora/CentOS*: sudo yum install cargo
  • MacOS: brew install rustc

*Note that on CentOS you first need to enable EPEL via sudo yum install epel-release.

Installing Rust for R on Windows

In order for rust to work with R you need to install the toolchain using rustup and then add the x86_64-pc-windows-gnu target. First download rustup-init.exe and then install the default toolchain:

rustup-init.exe -y --default-host x86_64-pc-windows-gnu

Or if rust is already installed (for example on GitHub actions), you can simply add the target:

rustup target add x86_64-pc-windows-gnu

To compile 32bit packages also add the i686-pc-windows-gnu target, but 32-bit is no longer supported as of R 4.2.

GitHub Actions

Update 2023: This step is no longer needed because GitHub action runners now have the required Rust targets preinstalled by default.

To use GitHub actions, you can use the standard r workflow script in combination with this extra step:

- name: Add Rtools targets to Rust if: runner.os == 'Windows' run: | rustup target add i686-pc-windows-gnu rustup target add x86_64-pc-windows-gnu

In the real world

The gifski package has been on CRAN since 2018, and uses this same structure.

More Resources

Owner

  • Name: Rust in R
  • Login: r-rust
  • Kind: organization

Example R packages wrapping Rust Cargo crates

GitHub Events

Total
  • Issues event: 1
  • Watch event: 21
  • Issue comment event: 5
  • Push event: 14
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 3
  • Fork event: 3
Last Year
  • Issues event: 1
  • Watch event: 21
  • Issue comment event: 5
  • Push event: 14
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 3
  • Fork event: 3

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 14
  • Total pull requests: 11
  • Average time to close issues: 7 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 13
  • Total pull request authors: 6
  • Average comments per issue: 2.57
  • Average comments per pull request: 2.36
  • Merged pull requests: 11
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 2
  • Average time to close issues: 13 days
  • Average time to close pull requests: 21 days
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 1.0
  • Average comments per pull request: 3.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jeroen (2)
  • nfultz (1)
  • eitsupi (1)
  • Firstyear (1)
  • CGMossa (1)
  • o1iv3r (1)
  • yihui (1)
  • Bohdan-Khomtchouk (1)
  • yutannihilation (1)
  • rennis250 (1)
  • nx10 (1)
  • clauswilke (1)
  • coolbutuseless (1)
Pull Request Authors
  • CGMossa (5)
  • yutannihilation (4)
  • jeroen (2)
  • eitsupi (2)
  • robitalec (1)
  • klmr (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 320 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 13
  • Total maintainers: 1
proxy.golang.org: github.com/r-rust/hellorust
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 10 months ago
cran.r-project.org: hellorust

Minimal Examples of Using Rust Code in R

  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 320 Last month
Rankings
Stargazers count: 2.0%
Forks count: 4.1%
Dependent packages count: 29.8%
Average: 30.1%
Dependent repos count: 35.5%
Downloads: 79.3%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
src/myrustlib/Cargo.toml cargo
DESCRIPTION cran