20 Hello, world!
Objective
Scaffold an extendr-powered R package using rextendr
and run the hello_world()
function.
We’re now ready to create our R package.
Developer functions
To develop a Rust-based R package, there are a few functions we need to familiarize ourselves with.
I don’t use RStudio anymore so I set create_package(rstudio = FALSE)
to not have Rproj.user
created.
usethis::create_package()
creates an R packagerextendr::use_extendr()
creates the Rust infrastructurerextendr::document()
document and update Rust function definitions
Developer workflow
The typical workflow for developing an extendr package involves:
- Modify the Rust source code
- Update the bindings documentation using
rextendr::document()
- Load the package
devtools::load_all()
- Test the R functions
- Repeat
Exercise
- Create a new package called
{geohashrs}
using{usethis}
- Include extendr in the new package by running
rextendr::use_extendr()
- Compile the package by using
rextendr::document()
- Load the package using
devtools::load_all()
- Run
hello_world()
Solution
View solution
::create_package("geohashrs")
usethis# in the newly created package
library(rextendr)
# add extendr scaffolding
use_extendr()
# compile and document the Rust functions
document()
# load the R package
::load_all()
devtools
# run the hello_world()!
hello_world()