I have an Rcpp based R package which when checked by devtool::check() produces following warning:
Error in .doLoadActions(where, attach) : error in load action .A.1 for package tarantoolr: (function (ns) : could not find function "loadModule"
What might be the cause of such behavior and what is the best way to fix this issue?
Full build and check log from travis-ci can be viewed here, warnings are located around lines 1212 and 1223.
Package itself is located at Github.
Try running your package using devtools::check(document = FALSE) as I think your NAMESPACE file is being overwritten and made "empty" as you do not use roxygen2 to create the necessary entries
e.g. You need to create a file called tarantoolr-package.R that contains:
#' #importFrom(Rcpp, evalCpp)
#' #useDynLib(tarantoolr)
#' #exportPattern("^[[:alpha:]]+")
#' #details
#' We all live in a yellow submarine..
"_PACKAGE"
Without this file, again, the NAMESPACE file is empty and, thus, the global export of all function via exportPattern("^[[:alpha:]]+") does not occur. Hence, there are no known functions within the environment.
Related
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!
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
I am working with roxygen2 library and devtools. Building a package with the following structure:
Inside /data folder I have two .rda files with the information of each dataset. Let's call them data1.rda and data2.rda.
Inside /R folder I have two files, one with the functions created (and their explanation) and another one called data.R with the information of each dataset.
#' Description 1
#'
#' Simple definition
#'
#' #format The \code{data.frame} contains 2 variables:
#' \describe{
#' \item{a}{The first variable.}
#' \item{b}{The second variable.}
#' }
"data1"
When I run roxygen2::roxygenize() I get this message:
First time using roxygen2. Upgrading automatically...
Error in get(name, envir = env) : object 'data1' not found.
I have looked for similar questions, without an answer for this problem. Anyone has a suggestion?
It might be a silly question but are you running roxygenise on your loaded package? Meaning that you first run devtools::load_all(), and then roxygen2::roxygenise().
I've seen a couple of people making this mistake on other posts.
The roxygen2::roxygenize method does not load the package properly. But you can replace this step with devtools::document(package_path)
Please try adding these additional tags in your comments: #name, #docType, and #references
I would like to include the mice::mice function in my package to perform imputation on my data.
I use Roxygen to list imports
#' #param data dataset to be used for imputation
#' #importFrom dplyr select_
#' #importFrom mice mice complete
#' #return A list
#' #export
#'
impute_data <- function(data, vars, seed)
{
data_used <- select_(data,vars)
mice_data <- complete(mice(data_used, seed = seed))
return(mice_data)
}
This function works fine when I test the code, however when I build the package and try to use it, I get the following error
Error in check.method(setup, data) :
The following functions were not found: mice.impute.pmm,mice.impute.pmm, mice.impute.pmm, mice.impute.pmm, mice.impute.pmm
I tried to add to the imports all the functions mentioned in the error but it had no effect whatsoever on the outcome.
What am I missing? I've never found such a problem.
You are forgetting to handle the DESCRIPTION file! You only handle impute_data.R.
Your question is quite similar to:
What roxygen should I put when I use a function of another package in my function
I gave answer there (Please search for similar questions before posting any question). For your case:
First, being aware of your
sessionInfo()
getwd() # your R's working directory
.libPaths() # your R's library location
Step0 Download and install the necessary packages:
library(roxygen2)
library(devtools)
library(digest)
Step1 Put all your related ".R" files (yourfunction1.R, yourfunction2.R, yourfunction3.R, impute_data.R) to your R's working directory.
Step2 Create your package skeleton in your R's working directory:
Be sure that there is no folder named "yourpackage" in your R's working directory before running the following command. (from R's console)
package.skeleton(name = "yourpackage", code_files = c("yourfunction1.R", "yourfunction2.R", "yourfunction3.R", "impute_data.R"), path = ".")
After running package.skeleton, the folder yourpackage is created in your R's Working Directory.
Delete Read-and-delete-me file from Windows Explorer.
Delete "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder
(Do NOT delete "yourpackage.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder!)
Step3 At the end of the preamble of your ".R" file (impute_data.R), put the following (if you had not done it so in Step1):
#' #importFrom mice mice
#' #importFrom mice complete
#' #export
impute_data <- function(...) {...
Step4 In the DESCRIPTION file of your package, in the Imports part, add:
Imports:
mice(>= VersionNumber)
where VersionNumber is the version number of the mice package you are using. You can find the version number by right-click any function (from yourpackage) in Object Browser of RevolutionREnterprise; and going the bottom of the resultant .html help file. There, the version number of the package is shown.
In Step2, package.skeleton automatically produced a NAMESPACE file whose content is:
exportPattern("^[[:alpha:]]+")
Do not handle this NAMESPACE file manually.
Step5 roxygenize the package you wanna create ("yourpackage")
library(roxygen2)
roxygenize("yourpackage")
Upon roxygenization, the content of the NAMESPACE file of yourpackage is automatically converted from exportPattern("^[[:alpha:]]+") to
# Generated by roxygen2: do not edit by hand
export(impute_data)
importFrom(mice,mice)
importFrom(mice,complete)
Step6 Build your package:
(first, delete "src-i386" and "src-x64" folders (if any) in YourR'sWorkingDirectoryFolder\yourpackage folder from Windows Explorer)
(Be sure again that there is no "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder. If there is, delete it before building)
build("yourpackage")
Step7 Install your package:
install("yourpackage")
Step8 Check that all is going well by loading your package and running a function in the package.
library(yourpackage)
impute_data(a,b,1235) # "impute_data" is the function in the package "yourpackage"
Step9 Check that your package is loadable to CRAN (Comprehensive R Archieve Network) (if you wanna share your package):
(first, delete "src-i386" and "src-x64" folders (if any) in YourR'sWorkingDirectoryFolder\yourpackage folder from Windows Explorer)
(Be sure again that there is no "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder. If there is, delete it before checking)
From DOS Command Prompt:
Start – cmd - Enter. Pass to R's working directory (your R's working directory is known via getwd()) and do CRAN check:
cd C:\Users\User\Documents\Revolution
R CMD check yourpackage
From R's console:
devtools::check("C:/Users/User/Documents/Revolution/yourpackage")
Hello and even if the post is older,
recently, I came across the same problem and the proposed solutions by
Erdogan CEVHER and mickkk did not work for me. I solved it by actively loading the mice package, while loading my own package. For more detailed information consult R-Package-Dependencies.
In addition to the steps required during package development, here is what I recommend:
Part 1: Add mice to the Depends: (not Import:) field in the DESCRIPTION file of your package.
Depends: mice (>= VERSIONNUMBER)
Part 2: Use import(mice) in NAMESPACE (only for devtools::check())
import(mice)
Part 3: Reference each function using mice::, for example
mice::mice(data, method="pmm")
I am making an R package in Rstudio and I selected the option Configure Build Tools > Configure and select Use roxygen to generate NAMESPACE. I wrote my functions in Rcpp and this is what the NAMESPACE looks like when I generate it with roxygen2:
# Generated by roxygen2 (4.1.1): do not edit by hand
export(function1)
export(function2)
export(function3)
export(function4)
Since my functions are written with Rcpp, which I then export, then they will used in R via .Call. However, from writing R extensions we should use useDynLib() in such a case. This is why I think I am getting an error when I try to call function1 and the error is:
Error in .Call("Mypackage_function1", PACKAGE = "Mypackage", var1, :
"Mypackage_function1" not available for .Call() for package "Mypackage"
When I use the default NAMESPACE when I start a project in Rstudio, I have the following in NAMESPACE:
useDynLib(packagename)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
When I use the default NAMESPACE I can call the functions using .Call however I get a warning when I check the package that I am not generating the NAMESPACE using roxygen.
Is there a fix for this? Any advice is appreciated.
This is unrelated to the usage of RStudio: For Roxygen to generate the relevant useDynLib specification, you need to use the #useDynLib tag in a Roxygen doc comment:
#' #useDynLib packagename
You can do this anywhere (where you can use normal Roxygen comments) but it makes sense to put this into the package documentation, rather than the documentation of a specific function. Usually this resides in a file called R/packagename-package.r:
#' My package documentation
#' … bla bla …
#' #name packagename
#' #docType package
#' #useDynLib packagename
NULL
I am building R package. Recently, I deleted and renamed several functions in R/allFunctions.R. I had previously been able to automatically update NAMESPACE, but for some reason, I am not able to now, and get some errors as follows:
library(packageName)
library(roxygen2)
library(devtools)
install()
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/packageName’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/packageName’
Error: Command failed (1)
document()
Updating packageName documentation
Loading packageName
Warning message:
In setup_ns_exports(pkg, export_all) :
Objects listed as exports, but not present in namespace: functionOne, functionTwo
I see that clearly I have some objects that are not present in namespace that are listed as exports. However, I removed all #export in the allFunctions.R file. I see in NAMESPACE that some newly named function names are not there, and that some old (since renamed) function names are still there. I could change it by hand, but I know that is dangerous, and want to avoid those poor techniques.
If you have any ideas, please let me know! Thank you.
#jtr13's Answer worked for me as well. Just run devtools::document() a second time and the warning goes away.
> devtools::document()
Updating pavm documentation
Loading pavm
Writing NAMESPACE
Deleting evlCalcTime.Rd
Deleting initTimeStamp.Rd
Warning message:
In setup_ns_exports(pkg, export_all) :
Objects listed as exports, but not present in namespace: evlCalcTime,
initTimeStamp
> devtools::document()
Updating pavm documentation
Loading pavm
I just did a similar thing: I deleted 3 exported functions from R/allFunctions.R and ran devtools::document(). This gave me the following error:
Warning message:
In setup_ns_exports(pkg, export_all) :
Objects listed as exports, but not present in namespace: getAccounts, getClients, getDeposits
I solved the problem by manually deleting the 3 export() functions from the NAMESPACE file.
In my experience, this is often a typo-mismatch between function definition and roxygen statement, especially when camelCase notation is involved, for example:
#' #export functionOne
functionone <- function() { ... }