0

I'm using RcppParallel in my own R package.

I know that I need to add Imports: RcppParallel to the DESCRIPTION file and importFrom(RcppParallel, RcppParallelLibs) to the NAMESPACE file.

My current workflow to compile my R package is:

  1. run Rcpp::compileAttributes()
  2. run devtools::document()
  3. manually add importFrom(RcppParallel, RcppParallelLibs) to the NAMESPACE file
  4. run devtools::install("MyPackage",quick = T,upgrade="never")

My question is what changes should I make to my R package, so that I can skip the manual step 3? I already add Imports: RcppParallel to the DESCRIPTION file and why does importFrom(RcppParallel, RcppParallelLibs) not show up in the NAMESPACE file after step 2?

Ding Li
  • 673
  • 1
  • 7
  • 19
  • 1
    You could read the documentation of the roxygen2 package because it lets you write to NAMESPACE programmatically. Starting with `RcppParallel::RcppParallel.package.skeleton()` should also set you up correctly--as that is what the function is for. Or maybe do not run `devtools::document()` if does things you do not like? – Dirk Eddelbuettel Sep 03 '21 at 16:12

2 Answers2

1

In one of your C++ source files add this to an existing entry

//' @importFrom RcppParallel RcppParallelLibs

When you run Rcpp::compileAttributes() this gets carried over to an R file where the roxygen2 package, when running in 'full mode' also rewriting NAMESPACE will add the entry.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
0

Use the devtools package for this. Each package you want to add to your own package add the command use_package

library(devtools)
use_package("RcppParallelw", min_version = T)

The use_package function will automatically add any entries needed in DESCRIPTION for you. Additionally, the min_version = T option will ensure that your package requires RcppParallelw at a version not lower than you currently have installed.

Marek Fiołka
  • 4,825
  • 1
  • 5
  • 20