I am working on an R package that uses Rcpp. I took over the project with many issues and I am trying to fix them. The problem with this is that I don't know how to create a minimal example for reproduction in this situation because the package is quite large and I was not involved in the early setup. I would appreciate suggestions on how to go about it, I am new to writing packages in R/Rcpp.
I got it into a state that it passes automated R CMD checks both on macOS and Linux in Github Actions.
There is a deprecated file named "R/simulate.R" that contains one function that is no longer used. I am trying to remove this file.
The relevant lines are:
...
#' @useDynLib myPackage
#' @export
#' @import CompQuadForm
#' @import doParallel
#' @import Rcpp
#' @import RcppArmadillo
#' @import Matrix
#' @import mvtnorm
#' @import PHENIX
simulate <- function(...) {...}
I used devtools::document()
to update the autogenerated files in the package.
With this, the lines
import(Matrix)
import(PHENIX)
import(Rcpp)
import(RcppArmadillo)
import(doParallel)
import(mvtnorm)
were removed from the file NAMESPACE
.
After the removal, when I run R CMD check .
on macOS-latest
, I get the following error:
* checking tests ... ERROR
Running ‘testthat.R’
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> library(testthat)
> library(myPackage)
>
> test_check("myPackage")
libc++abi: __cxa_guard_acquire detected recursive initialization
Running R CMD check .
on ubuntu-20.4
gives the following error when checking tests:
Error: <rlib_error_2_0 in process_get_error_connection(self, private):
stderr is not a pipe.>
git rm R/simulate.R
devtools::document()
leads to the following changes:
modified: NAMESPACE
deleted: R/simulate.R
deleted: man/simulate.Rd
R CMD check .
produces the above error.I found this issue with a similar problem and therefore tried to reinstall packages with install.packages(c('Rcpp', 'RcppArmadillo', 'httpuv'))
The issue persists.
I tried git grep -nrw "simulate"
to search for the function that was defined in the file to find forgotten use of the file but nothing shows up.
Instead of running devtools::document()
, I only deleted the line export(simulate)
manually from the file NAMESPACE
. With this, the lines
import(Matrix)
import(PHENIX)
import(Rcpp)
import(RcppArmadillo)
import(doParallel)
import(mvtnorm)
remain in the file NAMESPACE
.
These lines were autogenerated from annotations to the function that I removed by deleting R/simulate.R
:
...
#' @useDynLib myPackage
#' @export
#' @import CompQuadForm
#' @import doParallel
#' @import Rcpp
#' @import RcppArmadillo
#' @import Matrix
#' @import mvtnorm
#' @import PHENIX
simulate <- function(...) {...}
Now, R CMD check .
runs correctly.
I guess this means I do not understand the annotations and the NAMESPACE
yet and there is another dependency that requires these imports in the NAMESPACE
.
If there is a problem with how I am asking the question, I would be happy to get feedback as well. I am also new to posting a question.
Thank you!
The deprecated file was the only file that had the annotation #' @import Rcpp
that made sure devtools::document()
would include import(Rcpp)
in the NAMESPACE
file.
I solved the problem by annotating the main R function of the package that uses Rcpp functions with #' @import Rcpp
.
After that, devtools::document()
cleaned up the autogenerated files and left the package intact.
I would greatly appreciate if someone who understands R package development better, could explain what went wrong and maybe link to the best resources that explain annotations and the NAMESPACE
file! Thank you