Run tests on multiple inter-dependency packages - r

I wonder what would be the best way of testing multiple packages. Let's say we have two local packages:
src/pkg1
src/pkg2
The package pkg1 has a dependency on pkg2. I test all packages using R CMD check in the makefile:
for pkg in src/*; do \
R CMD check $$pkg
Which fails because of the missing dependencies. For example in Java you can include all missing code in the path. I can install first all R src/pkgs but this will leave artifacts on the end of the test in the R.
Is there any recommended way to perform such tests in R or installing all packages is the only solution? Maybe there is a way to use a specific folder for tests only so no other already installed packages would be affected?

Turns out I can use "-l" flag with both
R CMD INSTALL -l /path
and with
R CMD check -l /path
That should solve the problem but won't really cover the issues with more complex inter-dependencies.

Related

R CMD build versus devtools::build() (Non-standard file/directory found at top level)

I am writing an R package and build and test it with:
Rscript -e "devtools::document()" && R CMD build . && Rscript -e "devtools::test();devtools::check()"
I get a note:
checking top-level files
Non-standard file/directory found at top level:
‘PosteriorBootstrap_0.0.1.tar.gz’
I get the note whether devtools::check() comes first or second.
This
thread suggests:
The note is telling you that you usually shouldn't have a file called
build in the top level of your package.
The tar.gz file is created by R CMD build and I get the same error even if I delete it before running it.
This
thread
suggests adding the tar.gz file to .Rbuildinore, which removes the note.
Another way to remove it is to run everything from devtools:
Rscript -e "devtools::document(); devtools::build(); devtools::load_all('.'); devtools::test(); devtools::check()"
And then I don't get that note.
What's the difference between R CMD build and devtools::build() and why does the former throw that note?
You are combining a number of steps that perform similar and/or competing functions. I would suggest reading this for a best-practice build and check workflow.
When you run R CMD build it builds the package to the current directory, which is the top level package directory. Therefore, when you run your checks, it sees the .tar.gz file in the package root, which is a non-standard file to have in a package, thus the warning. devtools::build() is smart and builds the package to the package parent directory (regardless of where you are calling it from). Trying to call R CMD commands mixed with devtools functions can create issues, because devtools also calls R CMD commands, so you may be duplicating actions at various points in time or causing commands to be called in the incorrect order.
Per the link above, a best-practice workflow would be:
Rscript -e "devtools::document();devtools::check();devtools::build()"
called from the package root, and you avoid dealing with R CMD altogether. If you want to use R CMD it would look something like this:
Rscript -e "devtools::document()" && cd .. && R CMD build PosteriorBootstrap && R CMD check PosteriorBootstrap*.tar.gz
starting in the package root and then changing to the parent directory.

Installing R packages in macOS Mojave: Error in if (nzchar(SHLIB_LIBADD))

I have been trying to install R packages directly from the terminal but I am struggling much more than setting up the libraries I want in Windows. Sometimes it works if I install every single dependency for more complex packages by downloading them from CRAN and placing them in the R folder.
I appreciate this is not efficient but the recurrent error if I run R within the terminal while installing some of the packages is the following:
** libs
Error in if (nzchar(SHLIB_LIBADD)) SHLIB_LIBADD else character() :
argument is of length zero
* removing ‘/anaconda3/lib/R/library/<package name>’
[...]
In install.packages("<package name>") :
installation of package ‘fpc’ had non-zero exit status
I have been looking across many forums but the only solution I found so far is to install single dependencies manually by downloading them and dropping them in the master R folder. It is taking way longer than expected.
Any suggestion will be appreciated. Thanks
in my case (centos 7):
/home/xilab/miniconda3/lib/R/etc/Makeconf is a empty file!
find ~ -name Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-h8900bf8_2/lib/R/etc/Makeconf
/home/xilab/miniconda3/envs/python2.7/lib/R/etc/Makeconf
/home/xilab/miniconda3/lib/R/etc/Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf is not empty,so:
mv /home/xilab/miniconda3/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf.backup
cp /home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf
problem solved!
I have seen this problem in conda version of R where /yours/anaconda/environment/lib/R/etc/ has a file Makeconf.mro.original together with an empty Makeconf file. This should not be intended.
During installation of some packages R checks what is within this Makeconf file, one such check is for SHLIB_LIBADD.
I just backed up the empty (or whatever) Makeconf file. Then copied Makeconf.mro.original to Makeconf.
This solved my case.
EDIT:
Recently I saw in centos-machine that Makeconf.mro.original file is not made after install.packages("name of library") failed. There is no easy solution for this.
In my case R installation was inside a conda environment. So, I created a new conda environment with R installation. The fresh installation has a Makeconf file in etc directory. So, I copied the Makeconf file from fresh R to my previously working R's etc directory.
It may be better to keep a backup copy of Makeconf from etc to a Makeconf.bak for future problems, in your working R etc directory.
I hope this helps for some cases.
I had this problem when trying to run install.packages("RPostgres") in a conda-installed version of R . The solution was to use conda as the package manager instead of R's install.packages function. That meant running these commands at a normal system command prompt (not in R):
conda search -c conda-forge RPostgres
# shows various versions of r-rpostgres
conda install -c conda-forge r-rpostgres

Installing packages into a library ignoring other libraries

I currently have testthat installed on my machine. I want to install the package and all its dependencies (recursively) into a separate library. The problem is that when I try to do this using install.packages("testthat", lib = "newdir"), its dependencies, such as xml2 are not installed along with it. How can I install a package and all its dependencies into a new library?
I would do the following:
use install2.r from littler with its -l argument for the target library (and I do things like this all the time for reverse dependency checks
maybe use a properly set/reset .libPaths() so that the current installation you are doing does not "see" the existing installations; worst case you make a copy of install2.r and set/reset .libPaths() there; you may need to experiment with Rscript vs r to launch it as r gets some values "baked in" during its compilation
Taken together it is basically what we do when we keep a separate R-devel on a box as well.
Edit: You can of course script this with install2.r -- it is just a wrapper to install.packages(). But it happens to be setting the relevant arguments.

R CMD check with specified library path

I am working on a package which I can load using devtools. But
R CMD check asm
gives me an error message
Error : package ‘seedDisp’ required by ‘asm’ could not be found
Which is kind of obvious as it is not installed in the global library.
But: I have installed installed in a local library (./library) and I have a .Rprofile file in the directory from which I run the checks as follow:
.libPaths(normalizePath("library"))
So when I run R and use devtools and load_all(.) it loads as the package seedDisp is installed.
It seems that R CMD check does ignore the library location which is set via the .Rprofile file.
So I tried
R CMD CHECK -l ./library asm_0.0.1.tar.gz
but it seems that -l only is used to install in and not to look for installed packages.
How can I tell R CMD check to look for installed packages in the library at ./library ?
One way to do this is via the R_LIBS_USER variable so I generally do
R_LIBS_USER=/some/other/path R CMD check asm_0.0.1.tar.gz
If that variable is generally set on your system, you need to do the usual trick of appending, or just set it in your shell via e.g.
export R_LIBS_USER="/some/other/path:${R_LIBS_USER}"
R CMD check asm_0.0.1.tar.gz
This mechanism is independent of how you call R CMD check it will work with or with devtools.

R CMD install : clean libs before a new installation

If there is any option I can set to R CMD INSTALL to remove all installed libs ( under package installation directory) before a new installation?
I tried
R CMD install -c --preclean
But it does not work. Should I create a clean config?
PS : I am under windows.
EDIT more context:
I am developing a package. I generate the lib automatically at each build. So I need to remove the old ones each time I have a modification. Removing the entire library is Ok for me also.
I know this is old, but I just ran into this myself. I am assuming here by "installed libs" you mean libraries internal to your package on which your package depends. (In my case, it is libzip and libzippp that I am cleaning up.)
My solution was here: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Configure-and-cleanup
Under a Unix-alike only, an executable (Bourne shell) script cleanup is executed as the last thing by R CMD INSTALL if option --clean was given, and by R CMD build when preparing the package for building from its source.
I created a file named "cleanup" that is a Bash script and change directories, call make distclean and remove so and o files there. This is called at the beginning and the end of the build/install process. The cleanup script is called from within the package directory.

Resources