R CMD install : clean libs before a new installation - r

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.

Related

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

I want to install package xlsx on R 2.8.1 on windows but I have to use .tar.gz old package when I need .zip

For reasons that are too long to explain here, I must use R.2.8.1 (unfortunately). I need to have the xlsx package installed on it. Since I am on R 2.8.1, about ten years old, I can't use the latest version of xlsx but an older version, for instance xlsx_0.1.3 from 2010 seems a good choice. However the previous releases per R-CRAN policy are only available in tar.gz.
This is very unfortunate to me because I have to use RGui on windows which only accepts .Zip packages in installation. Therefore I tried the following stuff, in vain:
1-I tried to use Rcmd but I get the following error message:
C:\Program Files (x86)\R\R-2.8.1\bin>Rcmd INSTALL C:\Users\username\Downloads\xlsx_0.1.3.tar.gz
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\PROGRA~2\R\R-28~1.1/bin/INSTALL line 42.
so I give up on this one.
2-Then I think that the best solution is to convert the package xlsx_0.1.3.tar.gz into a compatible xlsx_0.1.3.zip package by building it using R.2.8.1 but I can't make it. Here is one of the things I have tried so far.
I have unziped xlsx_0.1.3.tar.gz and I organized it in the following way, which brought me the furthest:
Documents\xlsx
Documents\xlsx\activate.bat
Documents\xlsx\build_xlsx.bat
Documents\xlsx\R
Documents\xlsx\R\inst
Documents\xlsx\R\man
Documents\xlsx\R\other
Documents\xlsx\R\R
Documents\xlsx\R\DESCRIPTION
Documents\xlsx\R\NAMESPACE
Documents\xlsx\R\NEWS
Documents\xlsx\R\WISHLIST
inside activate.bat, I wrote:
SET TMP=C:\Users\username\Documents\TOTO\xlsx\tmp
SET TEMP=%TMP%
SET RTOOLSPATH=C:\DEV_307\toto\Rtools
SET RPATH=C:\DEV\toto\R\R-2.8.1
SET PATH=%RTOOLSPATH%\bin;%RTOOLSPATH%\MinGW\bin;%RPATH%\bin;%PATH%
inside build_xlsx.bat, I wrote:
R CMD BUILD R
R CMD check --no-examples --no-tests R
R CMD build --docs=normal --binary R
Then I still get:
C:\Users\username\Documents\TOTO\xlsx>R CMD BUILD R
* checking for file 'R/DESCRIPTION' ... OK
* preparing 'R':
* checking DESCRIPTION meta-information ... OK
* installing the package to re-build vignettes
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\DEV\toto\R\R-2.8.1/bin/INSTALL line 42.
ERROR
Installation failed.
Removing 'C:/Users/username/Documents/Rinst1210839349'
Thank you for your help
I can't include structured content in comments. This is really a comment.
The structure of source packages (which is what you have with xlsx_0.1.3.tar.gz if you pulled it from the CRAN archives) hasn't changed (much) since 2.8.1.
You'll also need to grab rJava_0.8-3.tar.gz and xlsxjars_0.2.0.tar.gz from the archive as xlsxjars + xlsx rely on rJava.
Extract each (since Windows R 2.8.1 seems to not grok gz files). They should make rJava, xlsxjars and xlsx directories each.
Move to the parent directory of both.
Run:
R CMD javareconf
R CMD build rJava
R CMD INSTALL rJava_0.8-3.zip # I believe this will be the name
R CMD build xlsxjars
R CMD INSTALL xlsxjars_0.2.0.zip
R CMD build xlsx
R CMD INSTALL xlsx_0.1.3.zip
and you should be gtg.

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.

How to specify lib directory when installing development version R Packages from github repository

In Ubuntu, I am installing all the R packages in the directory, /usr/lib/R/site-library by specifying lib option in install.packages().
But when I try to install the development version of the R packages using, install_github(), it always installs in a local repository of the system user.
.libPaths() has 4 directories including the local repository. So, I have 2 questions,
Will it install in any of the other 3 repositories if i remove the local repository from .libPaths()?
Is there any way to specify installation library path in install_github()?
I am using Ubuntu 12.04 64bit and R 3.0.1
----------------------UPDATE--------------------------------
Unable to remove the local repository from .libPaths()
If I try to install using install_github() in RStudio, it installs in the local repository since lib is not specified.
If I try to install using install_github() as non-root user, it installs in the local repository since lib is not specified.
If I try to install using install_github() as root user, it installs in the /usr/local/lib/R/site-library since lib is not specified.
Is there any to specify installation lib?
To add specified library paths in devtools, we need to use with_libpaths()
Arguments for with_libpaths() are, with_libpaths(new, code)
Following is an example for using with_libpaths(),
library(devtools)
with_libpaths(new = "/usr/lib/R/site-library/", install_github('rCharts', 'ramnathv'))
Courtesy: Hadley, here :)
And other than with_libpaths(), there are more options for in devtools::with_something()
in_dir: working directory
with_collate: collation order
with_envvar: environmental variables
with_libpaths: library paths, replacing current libpaths
with_lib: library paths, prepending to current libpaths
with_locale: any locale setting
with_options: options
with_path: PATH environment variable
with_par: graphics parameters
More explanations here
install_github takes a ... argument that passes to devtools::install. devtools::install has an args argument.
args
An optional character vector of additional command line arguments to be passed to R CMD install. This defaults to the value of the option "devtools.install.args".
R CMD install takes a library argument
Options:
-h, --help print short help message and exit
-v, --version print INSTALL version info and exit
-c, --clean remove files created during installation
--preclean remove files created during a previous run
-d, --debug turn on debugging messages
and build a debug DLL
-l, --library=LIB install packages to library tree LIB
So the following should work:
devtools::install_github("repo", args = c('--library="./mypath/gdfgdg/"'))
however it doesnt appear to be replacing the call to R CMD install
"C:/PROGRA~1/R/R-31~1.0/bin/x64/R" --vanilla CMD INSTALL \
"C:\Users\john\AppData\Local\Temp\RtmpucrXMD/RSelenium_1.3.2.tar.gz" \
--library="C:/Users/john/Documents/R/win-library/3.1" --install-tests \
--library="C:/Users/john/Desktop/"
This is more of a workaround, but I found a way using the command-line version of R.
Starting from Ubuntu:
sudo -i R
the trick (I found) is to use -i option
Then from R:
.libPaths()
my local R directory does not appear; the default directory is the one that I want.
Then, I install.packages() or install_github() with impunity.
Hope this helps,
Ian

How to execute the version of R which installed in a local folder?

I unpacked the new version of R package and inside a folder I gave commands:
./configure
make
Now I want to run it, if I give command:
$ R
Then it runs the older version. and I have no privilege to deal with it. so I want to run the new installed version. any help?
Perhaps it needs to be exported but i am not familiar with these steps.
thanks
To execute the new version of R, run bin/R within the installation directory.
To move it to a globally accessible location, run
make install
If you don't have permission to do so (as you indicate), you can alter the directory that make install moves R to to one where you do have permission at the ./configure step:
./configure --prefix=/where/you/want/R/to/go
make
make install

Resources