-1

Summary

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.>

Removal steps

  • git rm R/simulate.R
  • in 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.

What I tried

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.

Progress update

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!

williamjds
  • 13
  • 5
  • Welcome to StackOverflow. We may be able to help if you provide a link to a repo. Right now there is nothing reproducible here (and please also note that none of the Rcpp suggests or implies `devtools` -- we recommend `R CMD ....` commands directly. Your problem, though, is mostly likely a local setup issue on your machine. R can be picky about compilers and libraries; use the official tools and follow the guidelines. Or stick to Linux where things work out of the box. (I didn't downvote but the question could be improved as indicated.) – Dirk Eddelbuettel Jan 25 '22 at 14:02
  • @DirkEddelbuettel, thank you for the feedback! I updated the question with a link to the pull request with the changes that break `R CMD check` as well as a link to the Github actions that show the `R CMD check` runs both on `macOS-latest` and `ubuntu-20.4`. – williamjds Jan 25 '22 at 14:42
  • Ok but how about stepping back and observing. You have two existence proofs that the package is sane, on two different platforms. What does that make you suspect is the root cause of your local issue? – Dirk Eddelbuettel Jan 25 '22 at 15:05
  • If the problem occurred only with my local `R CMD check .`, I would assume that my R installation or C++ developer tools setup is broken. In the linked PR, the issue occurs in the `macOS-latest` Github actions run of the `R-CMD-check` action. I am currently assuming that the Github actions developer tools are in a working state. This makes me think that either this is a `macOS` related issue, or that the changes break the check. In the `ubuntu-20.4` run, checking the tests fails too, albeit with a different message (edited question). Are the changes breaking the check? Am I missing something? – williamjds Jan 25 '22 at 15:34

1 Answers1

0

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

williamjds
  • 13
  • 5