"object not found" during package build/install - r

I'm at a loss to debug building/installing a package. Building a package "MyProjekt" through
> devtools::build("MyProjekt")
works fine, even though
> devtools::document()
Updating MyProjekt documentation
Loading MyProjekt
Error: object 'rank' not found whilst loading namespace 'MyProjekt'
fails.
Attempting to install the built (pure R) package
> install.packages(pkgs="./MyProjekt.tar.gz")
...
Error: package or namespace load failed for 'MyProjekt':
object 'rank' not found whilst loading namespace 'MyProjekt'
Error: loading failed
Execution halted
...
ERROR: loading failed for 'i386', 'x64'
also fails.
Unfortunately the term 'rank' is a common term in my domain and I have hundreds of hits when searching in my files for that term.
How might I start a systematic way to hunt this bug down?

The toolchain mistakenly generates S3method(...) in the NAMESPACE file.
Follow this answer and edit the NAMESPACE file by hand. Replace occurrences of S3method(f) with export(f).
I'm not certain this is repeatable. The generated files appear to be not just written, but also read during a subsequent package build (by devtools? by roxygen2?). Add your comments if this works/does not work for you.

Related

clusterProfiler cannot load package

I am trying to load clusterProfiler, but regardless of how I install the package or whether I un-install or re-install, I continue to get the below error when I attempt to load it. I have also recently installed and loaded patchwork. Appreciate any tips.
Error: package or namespace load failed for ‘clusterProfiler’:
object ‘patchworkGrob’ is not exported by 'namespace:patchwork'
I had the same issue, and I solved it by loading the library(patchwork) before loading clusterProfiler.
Hope it helps~

"package or namespace load failed" error in loading R package from GitHub

I am trying to load a package in RStudio from GitHub but I get an error.
I have also updated all the packages in order to see if this was the problem but I still get the same error. I have a MAC pc (I don't know if this may cause some problems).
The link of the package that I would like to load is:
https://github.com/andrewraim/COMMultReg
and there is written that in order to load it I need to run
library(devtools)
install_github("andrewraim/COMMultReg")
But when I run the second line I get as error:
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘COMMultReg’ in namespaceExport(ns, exports):
undefined exports: d_cmb, d_cmb_sample, d_cmm, d_cmm_sample, gunterize, loglik_score_fim_cmm, normconst_cmb, normconst_cmm, r_cmb
Errore: loading failed
Esecuzione interrotta
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/COMMultReg’
Warning message:
In i.p(...) :
installation of package ‘/var/folders/n0/4lmr1lrj7qqfylmh6s8qx0nr0000gn/T//RtmpldrmHr/file72e1e4469d/COMMultReg_0.1.0.tar.gz’ had non-zero exit status
Can somebody help me telling me what to do?
Thanks!!
The package has no function named d_cmb, but it tries to export that function. That's what the error message says, and it's true.
I think the reason for this error is that the author used Roxygen2 to generate his NAMESPACE file where the exports are declared, but that file is out of sync with the contents of the package.
It's possible this happened because the author forgot to commit a new file containing the new code. In that case, the best solution is to contact the author, and point out the issue.
Alternatively, it may have happened because at one time there was a d_cmb function, but the author removed it, without updating the NAMESPACE file. This one you might be able to fix yourself.
To fix this, you'll need to run Roxygen2 yourself, which is a little more complicated than just installing what's on Github. Here are the steps:
Fork the package to your own Github account if you have one. (This step is optional, but it makes some later steps easier.)
Download the source for the package. In RStudio, the quickest way to do this is to create a new project using Version Control, Git, and give the URL
of your forked copy, or the original URL if you skipped that.
Run Roxygen2 on the package. In RStudio, you do this by choosing "Document" in the "More" menu of the Build tab.
Try to build it. If you're lucky, it will now build properly. If not, fix the next problem.
This is very important: send your changes back to the original author. If you forked the package, this is easy; if not, figure out a way to do it.
this is the maintainer of the COMMultReg package. I didn't know about this thread until now, but it sounds like you were able to get started from the answer by user2554330.
The functions d_cmb, d_cmb_sample, etc are supposed to be exported. I think the problem may have been that, at the time of the question, I did not have src/RcppExports.cpp and R/RcppExports.R checked into Github. This seems to be necessary to use install_github on a package with exported Rcpp functions. Those were checked in around 8 months ago. (Coincidentally not long after this question was posted?)
Please let me know if you still having trouble with the install. Otherwise, enjoy the package!

A package that needs compilation cannot be installed with a different name

I have a github clone of the glue R package for reasons. The name of this package is changed into glue.1.3.1 in this repository from its DESCRIPTION file for similar reasons. As a control group, I have an identical repository but this one's name is not changed in any way
If I do
devtools::install_github('oganm/glue.1.3.1')
the installation will fail
Error: package or namespace load failed for ‘glue.1.3.1’ in library.dynam(lib, package, package.lib):
shared object ‘glue.so’ not found
Error: loading failed
Execution halted
If I do
devtools::install_github('oganm/glue)
the installation will be successful.
If I do the same thing to most other packages, there are no problems but it seems like the source code of pacakges that need compilation, the change in the package name causes problems. For instance, you can repeat the issue with dplyr here
The question is, what causes this issue? What do I need to do so that I can reliably change names of packages that require compilation?

R packages not loading via library()

I have been experiencing the problem of not being able to load package libraries in R. The packages install fine via instal.packages(), but I get the error
Error: package or namespace load failed for ‘adegenet’ in library.dynam(lib, package, package.lib):
shared object ‘httpuv.so’ not found
Error: package ‘adegenet’ could not be loaded
When I attempt to load the package 'adegenet' (and any other packages).
I recall this behaviour started to occur when I used remove.packages() to remove shiny in order to install the development version on GitHub (shiny-Incubator).
I am unsure as to what is going on. Any ideas on how to restore everything? I updated to the most recent R version, but this did not fix things.
It seems that during your uninstallation procedure you managed to remove a component of httpuv and/or Rcpp. This should get things working again:
install.packages(c("Rcpp", "httpuv"))

working with package without Namespace in R

I have got betaversion from website. The only available is windows installation as mybetapackage.zip file. When I installed the package, it does not work when I load it.
> utils:::menuInstallLocal()
> require(mypackage)
Loading required package: mypackage
Failed with error: ‘package ‘mypackage’ does not have a NAMESPACE and should be re-installed’
Is it possible to use this beta package someway ?
Edits:
I tried the following instructions to create own namespace. Namespace file contains the following:
exportPattern("^[^\\.]")
Now I am getting following warning.
Warning message:
In readLines(file) :
incomplete final line found on 'C:/Users/user/Documents/R/win-library/2.14/RCropStat/NAMESPACE
Based on the discussion above I am answering my own questions. All credit goes to who discussed this issue.
Create a file with the following text and put an extra line to avoid an error. Same in the directory for the package where you have description file.
exportPattern("^[^\\.]")

Resources