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 package
  • rextendr::use_extendr() creates the Rust infrastructure
  • rextendr::document() document and update Rust function definitions

Developer workflow

The typical workflow for developing an extendr package involves:

  1. Modify the Rust source code
  2. Update the bindings documentation using rextendr::document()
  3. Load the package devtools::load_all()
  4. Test the R functions
  5. 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
usethis::create_package("geohashrs")
# in the newly created package
library(rextendr)

# add extendr scaffolding
use_extendr()

# compile and document the Rust functions
document()

# load the R package
devtools::load_all()

# run the hello_world()!
hello_world()