Installing packages into a library ignoring other libraries - r

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.

Related

library installation how to have one path to install packages instead of two

i have two library path how can I override that via an argument to both install.packages() (from inside R) or R CMD INSTALL (outside R).
or override by setting the R_LIBS_USER variable.
The usual reason to end up with two libraries is that the system library is not writable when you install new packages.
So if you only want one path in .libPaths(), always run with elevated permissions ("Run as administrator" on Windows, use sudo on others) when you install packages.
It's probably a better idea not to install packages in the system library other than the base packages that come with R, because it's very easy to forget to change privileges, and then you can end up with two libraries again, and have one version of a package in the system library and a different version in the user library.

Precompile R packages for specific Linux flavor

We have established a simple local CRAN-like repository for R packages. There are many users, all of which use the same version of Linux.
Is there a way of convincing R to provide pre-compiled Linux packages instead just source ones? The compilation step takes a considerable amount of time for anyone using our repository. It should be possible to precompile and reuse the same binaries, since we can guarantee that the Linux version is consistent for all users.
How could one hack something like this together?
In the very narrow sense of "all of which use the same version of Linux" you actually have an option (that happens to be relatively littler known). Create binary packages using e.g.
R CMD INSTALL --build nameOfDirectoryWithSources
As R CMD INSTALL --help says it
--build build binaries of the installed package(s)
and these are not .deb or .rpm alike packages: no dependency information or alike is added. But they do exactly what you ask for: save on compilation time.
I am not aware of a repository structure one can build of this though.

How to use R CMD Install without dependencies check?

I'm running R CMD INSTALL --build package on a windows computer. My package imports a couple of other packages which themselves depend on some more packages. I have all dependencies installed in the local r_libs folder and everything works.
Now sometimes I have the my package source code on a different windows computer. On this computer I don't have all the dependency packages installed.
When I try to use R CMD INSTALL --build package, I get the obvious "ERROR: dependencies 'package a', 'package b', etc, are not available for package".
My question is: Can I build the package using R CMD INSTALL --build without the dependency checks and without removing the Import and Depends entries in the DESCRIPTION file?
After consulting --help, I tried the --no-test-load option but no luck.
I reckon you want to build a .zip binary version of the package on a computer where not all dependencies are installed. And I'm afraid I'll have to disappoint you, as this won't be possible.
Building a binary package is done in two steps: first the package is installed from source (that's why you have to use R CMD INSTALL and then the created binaries are zipped in a convenient format for installation on a windows machine. The dependencies are checked at time of installation from source, and any missing dependencies will throw the error you're facing.
As R needs information from the dependencies at time of installation from source, you can't get around installing them before building the whole thing. This also makes sense. An installed package in R contains a set of .rds files which contain package information in a more convenient format for R. In order to create that information for the NAMESPACE file, it needs to be able to access the packages from which functions are imported. If not, it can't construct the correct information about the namespace.
So your only option is to install the dependencies on the computer you use to build. And if you actually want to use the package on that computer, you'll have to install those dependencies anyway.
More information:
R Internals : https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Package-Structure
Writing R Extensions: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-namespaces

R install packages from Shell

I am trying to implement a reducer for Hadoop Streaming using R. However, I need to figure out a way to access certain libraries that are not built in R, dplyr..etc. Based on my research seems like there are two approaches:
(1) In the reducer code, install the required libraries to a temporary folder and they will be disposed when the session is done, like this:
.libPaths(c(.libPaths(), temp <- tempdir()))
install.packages("dplyr", lib=temp, repos='http://cran.us.r-project.org')
library(dplyr)
...
However, this approach will have a dramatic overhead depending on how many libraries you are trying to install. So most of the time will be wasted on installing libraries(sophisticated libraries like dplyr has tons of dependencies which will take minutes to install on a vanilla R session).
So sounds like I need to install it before hand, which leads us to approach2.
(2) My cluster is fairly big. And I have to use some tool like Ansible to make it work. So I prefer to have one Linux shell command to install the library. I have seen R CMD INSTALL... before, however, it feels like will only install packages from source file instead of doing install.packages() in R console, figure out the mirror, pull the source file, install it in one command.
Can anyone show me how to use one command line in shell to non-interactively install a R package?
(sorry for this much background knowledge, if anyone thinks I am not even following the right phylosophy, feel free to leave in the comment how this whole cluster R package should be managed.)
tl;dr
Rscript -e 'install.packages("drat", repos="https://cloud.r-project.org")'
You mentioned you are trying to install dplyr into custom lib location on your disk. Be aware that dplyr package does not support that. You can read more in dplyr#4641.
Moreover if you are installing private package published in internal CRAN-like repository (created by drat or tools::write_PACKAGES), you can easily combine repos argument and resolve dependencies from CRAN automatically.
Rscript -e 'install.packages("priv.pkg", repos=c("cran.priv","https://cloud.r-project.org"))'
This is very handy feature of R repositories, although for production use I would recommend to cache packages from CRAN locally, and use those, so you will never be surprised by a breaking changes in your dependencies. For quality information about handling R in production I suggest to look into talk by Wit Jakuczun at WhyR2019 How to make R great for machine learning in (not only) Enterprise: slides, video.
You may find littler useful. It is a command-line front-end / variant of R (which uses the R-embedding interface).
I use the install.r script all the time to install package from the shell. There is a second variant with more command-line argument parsing but it has an added dependency.

Installing the R interpeter and R as a shared library uder the same tree

I am a bit confused about how to install R (via compilation) as a shared library.
The instructions here (Rpy2) say that I should do the following:
# <go to the R source directory>
make distclean
./configure --enable-R-shlib
make
make install
but the first make (make distclean) would remove any previous installation of R under the same directory tree (e.g. the contents of the bin folder).
What if I want to use the same installation for the R interpreter and the shared libraries? For example, say I want to use the interpreter to install R packages, and then the shared library of the installation to call R (and those packages) from Rpy2.
Otherwise, how can I install R packages for use through Rpy2?
./configure --enable-R-shlib
Will tell to build R's shared libraries in addition to what is normally built (the executable, the documentation, etc...)
Also
make install
will install R (default is /usr/local). This is where you'll want to find your R executable. Calling make distclean will only affect the build directory, not the installed R.

Resources