Skip to content

Development

Aviezer Lifshitz edited this page Nov 26, 2021 · 3 revisions

In order to edit R code:

  1. Edit the relevant .R file.
  2. Call devtools::load_all() and make sure it works.
  3. Write some tests to verify the desired behaviour.
  4. Run devtools::test() and make sure no test fails.

In order to edit c++ code:

  1. Edit the relevant file in the src directory.
  2. Make sure you have an empty file named ~/.R/Makevars in your unix environment. See below. See also the note regarding parallel compilation.
  3. Call devtools::load_all() to compile the code. Now you can test your change.
  4. Write some tests to verify the desired behaviour.
  5. Run devtools::test() and make sure no test fails.

A note regarding Makevars

devtools::load_all() calls pkgbuild::compile_dll() that uses its own compilation flags (pkgbuild::compiler_flags(TRUE)) and ignores the ones we use in our Makefile. This currently causes compilation to fail due to include issues. Fortunately, the flags are not added when we have a file named ~/.R/Makevars in our environment. This is the easiest solution, but if for some reason we prefer not to rely on our environment, we another solution is to run devtools::load_all() with fake makevars environment:

makevars <- c(CFLAGS="-O3 -DNDEBUG -fpic -I$(R_INCLUDE_DIR) -Wformat -Wformat-security -Wal
    l -pedantic -fdiagnostics-color=always",
    CXXFLAGS="-O3 -DNDEBUG -fpic -I$(R_INCLUDE_DIR) -std=c++11 -Wformat -Wformat-security -Wall
     -pedantic -fdiagnostics-color=always",
    CXX11FLAGS="-O3 -DNDEBUG -fpic -I$(R_INCLUDE_DIR) -std=c++11 -Wformat -Wformat-security -Wa
    ll -pedantic -fdiagnostics-color=always",
    FFLAGS="-g -O3",
    FCFLAGS="-g -O3",
    PKG_LIBS = "-lpthread")
withr::with_makevars(makevars, devtools::load_all())

A note regarding parallel compilation

If you want compilation to happen in parallel (i.e. make -j): In R run usethis::edit_r_environ() and add the following line (e.g. in order to use 20 cores):

MAKE=make -j20
Clone this wiki locally