{"id":14067799,"url":"https://github.com/extendr/rextendr","last_synced_at":"2025-04-08T11:14:34.470Z","repository":{"id":37957343,"uuid":"314690638","full_name":"extendr/rextendr","owner":"extendr","description":"An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically","archived":false,"fork":false,"pushed_at":"2025-03-31T16:49:16.000Z","size":9268,"stargazers_count":208,"open_issues_count":39,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-01T10:11:07.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://extendr.github.io/rextendr/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/extendr.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-20T23:09:23.000Z","updated_at":"2025-03-31T16:46:33.000Z","dependencies_parsed_at":"2023-11-19T00:24:08.390Z","dependency_job_id":"0a1a0775-0aa3-4174-ae39-105ce65dc888","html_url":"https://github.com/extendr/rextendr","commit_stats":{"total_commits":167,"total_committers":10,"mean_commits":16.7,"dds":0.652694610778443,"last_synced_commit":"9376cd282d20d7ea330a868f88f42d491bd743d1"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Frextendr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Frextendr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Frextendr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Frextendr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extendr","download_url":"https://codeload.github.com/extendr/rextendr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829512,"owners_count":21002997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:05:47.241Z","updated_at":"2025-04-08T11:14:34.439Z","avatar_url":"https://github.com/extendr.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  message = FALSE,\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# Call Rust code from R \u003cimg width=\"120px\" alt=\"rextendr logo\" align=\"right\" src=\"man/figures/rextendr-logo.png\"\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/rextendr)](https://CRAN.R-project.org/package=rextendr)\n[![rextendr status badge](https://extendr.r-universe.dev/badges/rextendr)](https://extendr.r-universe.dev/rextendr)\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![R build status](https://github.com/extendr/rextendr/workflows/R-CMD-check/badge.svg)](https://github.com/extendr/rextendr/actions)\n[![Codecov test coverage](https://codecov.io/gh/extendr/rextendr/graph/badge.svg)](https://app.codecov.io/gh/extendr/rextendr)\n\u003c!-- badges: end --\u003e\n\n## Installation\n\nTo install release version from CRAN, run:\n\n```{r, eval = FALSE}\ninstall.packages(\"rextendr\")\n```\n\nor use `{remotes}`\n\n```{r, eval = FALSE}\nremotes::install_cran(\"rextendr\")\n```\n\nYou can also install `{rextendr}` from [r-universe](https://extendr.r-universe.dev/rextendr):\n\n```{r, results = \"hide\"}\ninstall.packages(\"rextendr\", repos = c(\"https://extendr.r-universe.dev\", \"https://cloud.r-project.org\"))\n```\n\nLatest development version can be installed from GitHub:\n\n```{r, eval = FALSE}\nremotes::install_github(\"extendr/rextendr\")\n```\n\nTo 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.\n\n## Usage\n\n### Sitrep\n\nA 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:\n\n```{r eval=FALSE, echo=TRUE}\nrust_sitrep()\n# Rust infrastructure sitrep:\n# ✔ \"rustup\": 1.26.0 (5af9b9484 2023-04-05)\n# ✔ \"cargo\": 1.72.0 (103a7ff2e 2023-08-15)\n# ℹ host: x86_64-pc-windows-msvc\n# ℹ toolchain: stable-x86_64-pc-windows-msvc (default)\n# ℹ target: x86_64-pc-windows-gnu\n```\n\nIf, for instance, no toolchain is found, you will see something like this:\n\n```{r eval=FALSE, echo=TRUE}\nrust_sitrep()\n# Rust infrastructure sitrep:\n# ✔ \"rustup\": 1.26.0 (5af9b9484 2023-04-05)\n# ✔ \"cargo\": 1.72.0 (103a7ff2e 2023-08-15)\n# ℹ host: x86_64-pc-windows-msvc\n# ! Toolchain stable-x86_64-pc-windows-msvc is required to be installed and set as default\n# ℹ Run `rustup toolchain install stable-x86_64-pc-windows-msvc` to install it\n# ℹ Run `rustup default stable-x86_64-pc-windows-msvc` to make it default\n```\n\nFinally, if you are missing the required target (on all platforms but Windows `{rextendr}` uses default target), the report will resemble the following:\n\n```{r eval=FALSE, echo=TRUE}\nrust_sitrep()\n# Rust infrastructure sitrep:\n# ✔ \"rustup\": 1.26.0 (5af9b9484 2023-04-05)\n# ✔ \"cargo\": 1.72.0 (103a7ff2e 2023-08-15)\n# ℹ host: x86_64-pc-windows-msvc\n# i toolchains: nightly-x86_64-pc-windows-msvc and stable-x86_64-pc-windows-msvc (default)\n# i targets: x86_64-pc-windows-msvc and i686-pc-windows-msvc\n# ! Target x86_64-pc-windows-gnu is required on this host machine\n# i Run `rustup target add x86_64-pc-windows-gnu` to install it\n```\n\n### Code examples\n\nBasic use example:\n\n```{r}\nlibrary(rextendr)\n\n# create a Rust function\nrust_function(\"fn add(a:f64, b:f64) -\u003e f64 { a + b }\")\n\n# call it from R\nadd(2.5, 4.7)\n```\n\nSomething more sophisticated:\n\n```{r}\nlibrary(rextendr)\n\n# Rust function that computes a sum of integer or double vectors, preserving the type\n\nrust_function(\n  \"fn get_sum(x : Either\u003cIntegers, Doubles\u003e) -\u003e Either\u003cRint, Rfloat\u003e {\n      match x {\n          Either::Left(x) =\u003e Either::Left(x.iter().sum()),\n          Either::Right(x) =\u003e Either::Right(x.iter().sum()),\n      }\n  }\",\n  use_dev_extendr = TRUE, # Use development version of extendr from GitHub\n  features = \"either\", # Enable support for Either crate\n)\n\nx \u003c- 1:5\ny \u003c- c(1, 2, 3, 4, 5)\n\ntibble::tibble(\n  Name = c(\"x\", \"y\"),\n  Data = list(x, y),\n  Types = purrr::map_chr(Data, typeof),\n  Sum = purrr::map(Data, get_sum),\n  SumRaw = purrr::flatten_dbl(Sum),\n  ResultType = purrr::map_chr(Sum, typeof)\n)\n```\n\nThe 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:\n````markdown\n`r ''````{extendr}\nrprintln!(\"Hello from Rust!\");\n\nlet x = 5;\nlet y = 7;\nlet z = x*y;\n\nz\n```\n````\nwould create the following output in the knitted document:\n```{extendr}\nrprintln!(\"Hello from Rust!\");\n\nlet x = 5;\nlet y = 7;\nlet z = x*y;\n\nz\n```\n\n## See also\n\n- The [cargo-framework](https://github.com/dbdahl/cargo-framework) and associated R package [cargo](https://cran.r-project.org/package=cargo)\n- The [r-rust](https://github.com/r-rust) organization\n\n-----\n\nPlease 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Frextendr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextendr%2Frextendr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Frextendr/lists"}