rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically

https://github.com/extendr/rextendr

Science Score: 36.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
  • Committers with academic emails
    1 of 15 committers (6.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.9%) to scientific vocabulary

Keywords from Contributors

ffi-bindings rmarkdown visualisation reporting data-manipulation grammar tidy-data literate-programming pandoc tidyverse
Last synced: 10 months ago · JSON representation

Repository

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically

Basic Info
Statistics
  • Stars: 224
  • Watchers: 7
  • Forks: 30
  • Open Issues: 36
  • Releases: 6
Created over 5 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  message = FALSE,
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# Call Rust code from R rextendr logo


[![CRAN status](https://www.r-pkg.org/badges/version/rextendr)](https://CRAN.R-project.org/package=rextendr)
[![rextendr status badge](https://extendr.r-universe.dev/badges/rextendr)](https://extendr.r-universe.dev/rextendr)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R build status](https://github.com/extendr/rextendr/workflows/R-CMD-check/badge.svg)](https://github.com/extendr/rextendr/actions)
[![Codecov test coverage](https://codecov.io/gh/extendr/rextendr/graph/badge.svg)](https://app.codecov.io/gh/extendr/rextendr)


## Installation

To install release version from CRAN, run:

```{r, eval = FALSE}
install.packages("rextendr")
```

or use `{remotes}`

```{r, eval = FALSE}
remotes::install_cran("rextendr")
```

You can also install `{rextendr}` from [r-universe](https://extendr.r-universe.dev/rextendr):

```{r, results = "hide"}
install.packages("rextendr", repos = c("https://extendr.r-universe.dev", "https://cloud.r-project.org"))
```

Latest development version can be installed from GitHub:

```{r, eval = FALSE}
remotes::install_github("extendr/rextendr")
```

To execute Rust code, you will also need to set up a working Rust toolchain. See the [installation instructions for libR-sys](https://github.com/extendr/libR-sys) for help. If you can successfully build libR-sys you're good.

## Usage

### Sitrep

A good first step is to check the status of Rust toolchain and available targets using `rust_sitrep()`. If everything is OK, you should see something like this:

```{r eval=FALSE, echo=TRUE}
rust_sitrep()
# Rust infrastructure sitrep:
# ✔ "rustup": 1.26.0 (5af9b9484 2023-04-05)
# ✔ "cargo": 1.72.0 (103a7ff2e 2023-08-15)
# ℹ host: x86_64-pc-windows-msvc
# ℹ toolchain: stable-x86_64-pc-windows-msvc (default)
# ℹ target: x86_64-pc-windows-gnu
```

If, for instance, no toolchain is found, you will see something like this:

```{r eval=FALSE, echo=TRUE}
rust_sitrep()
# Rust infrastructure sitrep:
# ✔ "rustup": 1.26.0 (5af9b9484 2023-04-05)
# ✔ "cargo": 1.72.0 (103a7ff2e 2023-08-15)
# ℹ host: x86_64-pc-windows-msvc
# ! Toolchain stable-x86_64-pc-windows-msvc is required to be installed and set as default
# ℹ Run `rustup toolchain install stable-x86_64-pc-windows-msvc` to install it
# ℹ Run `rustup default stable-x86_64-pc-windows-msvc` to make it default
```

Finally, if you are missing the required target (on all platforms but Windows `{rextendr}` uses default target), the report will resemble the following:

```{r eval=FALSE, echo=TRUE}
rust_sitrep()
# Rust infrastructure sitrep:
# ✔ "rustup": 1.26.0 (5af9b9484 2023-04-05)
# ✔ "cargo": 1.72.0 (103a7ff2e 2023-08-15)
# ℹ host: x86_64-pc-windows-msvc
# i toolchains: nightly-x86_64-pc-windows-msvc and stable-x86_64-pc-windows-msvc (default)
# i targets: x86_64-pc-windows-msvc and i686-pc-windows-msvc
# ! Target x86_64-pc-windows-gnu is required on this host machine
# i Run `rustup target add x86_64-pc-windows-gnu` to install it
```

### Code examples

Basic use example:

```{r}
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)
```

Something more sophisticated:

```{r}
library(rextendr)

# Rust function that computes a sum of integer or double vectors, preserving the type

rust_function(
  "fn get_sum(x : Either) -> Either {
      match x {
          Either::Left(x) => Either::Left(x.iter().sum()),
          Either::Right(x) => Either::Right(x.iter().sum()),
      }
  }",
  use_dev_extendr = TRUE, # Use development version of extendr from GitHub
  features = "either", # Enable support for Either crate
)

x <- 1:5
y <- c(1, 2, 3, 4, 5)

tibble::tibble(
  Name = c("x", "y"),
  Data = list(x, y),
  Types = purrr::map_chr(Data, typeof),
  Sum = purrr::map(Data, get_sum),
  SumRaw = purrr::flatten_dbl(Sum),
  ResultType = purrr::map_chr(Sum, typeof)
)
```

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:
````markdown
`r ''````{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:
```{extendr}
rprintln!("Hello from Rust!");

let x = 5;
let y = 7;
let z = x*y;

z
```

## See also

- The [cargo-framework](https://github.com/dbdahl/cargo-framework) and associated R package [cargo](https://cran.r-project.org/package=cargo)
- The [r-rust](https://github.com/r-rust) organization

-----

Please note that this project is released with a [Contributor Code of Conduct](https://github.com/extendr/rextendr/blob/main/CODE-OF-CONDUCT.md). By participating in this project you agree to abide by its terms.

Owner

  • Name: Extendr
  • Login: extendr
  • Kind: organization

Extension libraries for R in Rust

GitHub Events

Total
  • Create event: 14
  • Release event: 3
  • Issues event: 47
  • Watch event: 30
  • Delete event: 9
  • Issue comment event: 222
  • Push event: 111
  • Pull request event: 77
  • Pull request review event: 117
  • Pull request review comment event: 92
  • Fork event: 4
Last Year
  • Create event: 14
  • Release event: 3
  • Issues event: 47
  • Watch event: 30
  • Delete event: 9
  • Issue comment event: 222
  • Push event: 111
  • Pull request event: 77
  • Pull request review event: 117
  • Pull request review comment event: 92
  • Fork event: 4

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 266
  • Total Committers: 15
  • Avg Commits per committer: 17.733
  • Development Distribution Score (DDS): 0.695
Past Year
  • Commits: 50
  • Committers: 8
  • Avg Commits per committer: 6.25
  • Development Distribution Score (DDS): 0.74
Top Committers
Name Email Commits
Ilia Kosenkov i****v@o****m 81
Claus Wilke w****e@a****u 58
Hiroaki Yutani y****i@g****m 42
Josiah Parry j****y@g****m 17
eitsupi 5****i 14
CGMossa c****a@g****m 14
Malcolm Barrett m****t 13
Alberson Miranda 4****a 11
Kenneth Blake Vernon 5****n 9
Etienne Bacher 5****r 2
Wenjie Sun s****e@g****m 1
Thomas Down t****s@t****k 1
Seth s****k@g****m 1
Robin Lovelace R****e 1
Brancen Gregory b****y@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 125
  • Total pull requests: 198
  • Average time to close issues: 5 months
  • Average time to close pull requests: 15 days
  • Total issue authors: 37
  • Total pull request authors: 15
  • Average comments per issue: 3.46
  • Average comments per pull request: 2.57
  • Merged pull requests: 159
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 33
  • Pull requests: 81
  • Average time to close issues: 21 days
  • Average time to close pull requests: 7 days
  • Issue authors: 14
  • Pull request authors: 9
  • Average comments per issue: 1.18
  • Average comments per pull request: 1.68
  • Merged pull requests: 58
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • JosiahParry (22)
  • Ilia-Kosenkov (21)
  • eitsupi (8)
  • yutannihilation (8)
  • albersonmiranda (7)
  • kbvernon (7)
  • etiennebacher (5)
  • CGMossa (5)
  • Jaage (4)
  • latot (3)
  • daniellga (3)
  • malcolmbarrett (2)
  • sorhawell (2)
  • multimeric (2)
  • Neutron3529 (2)
Pull Request Authors
  • Ilia-Kosenkov (86)
  • JosiahParry (41)
  • albersonmiranda (31)
  • kbvernon (20)
  • eitsupi (17)
  • CGMossa (17)
  • yutannihilation (16)
  • etiennebacher (4)
  • malcolmbarrett (2)
  • brancengregory (2)
  • Neutron3529 (2)
  • beniaminogreen (2)
  • wenjie1991 (1)
  • bquast (1)
  • alexhroom (1)
Top Labels
Issue Labels
bug (10) enhancement (6) question (6) good first issue (3) need more details (2) showstopper (1) help wanted (1)
Pull Request Labels
enhancement (1) CRAN (1)

Packages

  • Total packages: 2
  • Total downloads:
    • cran 498 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 6
    (may contain duplicates)
  • Total versions: 12
  • Total maintainers: 1
proxy.golang.org: github.com/extendr/rextendr
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 10 months ago
cran.r-project.org: rextendr

Call Rust Code from R using the 'extendr' Crate

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 6
  • Downloads: 498 Last month
Rankings
Stargazers count: 2.7%
Forks count: 3.9%
Dependent repos count: 12.0%
Average: 13.9%
Downloads: 22.0%
Dependent packages count: 28.8%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • dtolnay/rust-toolchain master 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
.github/workflows/lint.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v3 composite
  • dtolnay/rust-toolchain stable composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test_pkg_gen.yaml actions
  • actions/checkout v3 composite
  • dtolnay/rust-toolchain master composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 4.0 depends
  • brio * imports
  • callr * imports
  • cli * imports
  • desc * imports
  • dplyr * imports
  • glue * imports
  • jsonlite * imports
  • pkgbuild * imports
  • processx * imports
  • purrr * imports
  • rlang >= 1.0.0 imports
  • rprojroot * imports
  • stringi * imports
  • tibble * imports
  • withr * imports
  • devtools * suggests
  • knitr * suggests
  • mockr * suggests
  • rmarkdown * suggests
  • rstudioapi * suggests
  • testthat >= 3.0.2 suggests
  • usethis * suggests
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
inst/templates/Cargo.toml cargo