22 Hello, world!
TipObjective
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 infrastructuredevtools::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
devtools::document() - Load the package
devtools::load_all() - Test the R functions
- Repeat
Exercise
- Create a new package called
{rurl}using{usethis} - Include extendr in the new package by running
rextendr::use_extendr() - Compile the package by using
devtools::document() - Load the package using
devtools::load_all() - Run
hello_world()
Solution
View solution
usethis::create_package("rurl")
# add extendr scaffolding
rextendr::use_extendr()
# compile and document the Rust functions
devtools::document()
# load the R package
devtools::load_all()
# run the hello_world()!
hello_world()