R: force install package and dependancies in user library - r

Apologies if this has been answered before but I can't find any related answer.
Is there an option to force install packages in R and their dependencies in a user library even if they exists on a common/system library?
For example, package "viridis" requires "viridisLite", however if the later is installed on the system library it will not be automatically installed on the user library when installing "viridis". This can cause some errors.

Related

R: force reinstallation of package's dependencies

My system installation of R is controlled by administrators, who make changes upon request from multiple users without coordination. This causes problems for me because some packages installed in my user library interact badly with upgraded packages in the system library. This breaks cron jobs and I have to spend time maintaining it.
When running install.packages or an equivalent, is there a way to make R ignore system-installed packages, and install all transitive dependencies in my user library? For example, I tried running R_LIBS=/path/to/lib R but the system install is still on .libPaths(), and dependencies of my package are still not installed in my user library.
Oh! It looks like renv is just what I want.

Do packages installed from Github need Rtools?

I am creating my first package, which shall be installed through Github. I thought that Rtools was needed only for the person creating it. However, people that tried to install it using Github were asked to update Rtools. Is this really necessary?
Doing some research, I found this: https://community.rstudio.com/t/missing-rtools-should-i-be-worried/27817
One of the answers says the following:
"This means that if you are going to install packages that need
compilation, you also have to install Rtools in your system. "
This is the repo with the package: https://github.com/datazoompuc/PNAD_Covid/tree/master/R/datazoom_pnad_covid
What does this actually mean? How do I know that my package needs compilation?
I thought that Rtools was needed only for the person creating it.
Yes, if and only if you distribute it as a binary. Then the creator uses Rtools to compile and link, and the user just installs, and enjoys.
That is how CRAN works as CRAN compiles for Windows users.
GitHub, however, is foremost a source repository so the installation from GitHub is using a source mode ... and every user will need to compile, and hence have Rtools. (Unless the package and all its depedencies are R-code only.)
You can also have a package repository on GitHub using e.g. the drat package to create it, but that is getting us a little further from the original question.
Your package "needs compilation" — i.e. needs Rtools to install from source (on Windows) — if it contains C or Fortran components, i.e. if you have anything in the src/ directory of your package ...
If you, the package author, don't know if you have C or Fortran code as part of your package, then you almost certainly don't.
It's quite possible that devtools is being overzealous, i.e. detecting that users have a not-most-current Rtools and suggesting (requiring??) that they update it, even though it's not needed for this installation.

While I install my R package (for testing) it also re-installs all the dependencies (first time) that are already present on the system

I have a code to track objects in the images. This code uses few function from the package clue. So clue is already installed in my system. Now I have created a package using the same code.
My description file has following lines.
Depends: R (>= 3.4.3),
clue
Because clue is already installed, I thought it will not get installed again when I use install("mypackage"). But to my surprise it re-installed the package. I have tried this with other installed packages, too. When I give it as "depends" or "import", it re-installs the packages. I do not want to re-install the packages if they are already on my system. Is there a way to tell R package installer to avoid re-installing packages that exist on the user's system? Some of these packages are quite large and take a lot of time to install. In addition, I have installed some packages with binary source/dependency that required me to give path for several libraries.
You can just use
install.packages(..., dependencies = FALSE)
or if you use devtools::install:
install(..., dependencies = FALSE)

installed directory not writable, cannot update packages 'boot', 'class', 'KernSmooth', 'mgcv', 'nnet', 'rpart', 'spatial' [duplicate]

This question already has answers here:
installation path not writable R, unable to update packages
(9 answers)
Closed 2 years ago.
I installed the Bioconductor packages on R version 3.1.2 on Ubuntu 14.04 and received the message below:
The downloaded source packages are in
‘/tmp/RtmpZYw0Qp/downloaded_packages’ Warning message: installed
directory not writable, cannot update packages 'boot', 'class',
'KernSmooth', 'mgcv', 'nnet', 'rpart', 'spatial'
What does it mean, and how does it affect using the above packages on R?
I faced the same problem working in R-studio. The solution is to give root access to R.
In Windows, that means you need to run the program as an Administrator.
In Unix/Linux, you should launch R from the terminal by doing sudo R.
Then, once you're running with sufficient privileges, you can try installing your package and it should work.
The warning means that there are more recent versions of the listed packages available, but your version cannot be updated because the directory in which the packages are installed cannot be written to. Usually this means that R was installed with 'system administrator' privileges, but that you are trying to update packages as a regular user.
The consequence is that the features or bug fixes implemented in the updated packages are not available to you. The specific consequences could range from minor typographical corrections on a man page through serious bug fixes. Qualitatively, my bet is that it 'does not matter' for most uses.
The solution is to update these packages when running R as a user with permission to write to packages in the installed directories -- typically the last element of the output of .libPaths(), or more fine-grained via installed.packages()[, "LibPath"]
I faced the same problem today when installing three Bioconductor packages under Windows. Two (dependencies of the package I really wanted) were already on my system in newer forms (as described in #Martin-Morgan solution) and so no action was necessary. However, one was not installed. For this, third package, I had success in doing an installation from the local file that was downloaded during the failed install without having to escalate privileges (which was my next step as outlined by #Ninadmw).
In R, go to the menu Packages/Install Package(s) from local files and navigate to the local download directory listed, which in your case was /tmp/RtmpZYw0Qp/downloaded_packages, and select the package you want to install.
In RStudio (which you should use), go to the menu Tools\Install Packages, change the install from field to Package Archive File (.zip; .tar.gz), use Browse... to navigate to the listed download directory, which in your case was /tmp/RtmpZYw0Qp/downloaded_packages and select the package you want to install. Then click on the Install button.

Package installation issues with R 3.1.0

My Fedora system (Fedora 20, all up to date) has just had R updated to version 3.1.0. Since then, I've had issues installing multiple packages. glmnet failed previously, and now I'm having trouble with treemap. More specifically, I get an error during treemap installation that httpuv has zero exit status.
I never had issues with the previous version of R. Any reason this version should have such problems??
There could be many causes to do with your OS, version, permissions, other installed packages/software, etc, etc. Without seeing the full error message it's hard to know.
One possibility specific to httpuv is root privileges. I've noticed a few threads on various forums when searching for installation errors with this package and Linux, many of them mentioning root v. non-root issues. In another case, libuv needed to be upgraded.
I encounter package installation problems daily and I have some more general work-arounds as well. Hopefully one of these will solve your problem.
Install the package from source
download.file(url="http://cran.r-project.org/src/contrib/httpuv_1.3.0.tar.gz", destfile = "httpuv.tar.gz")
install.packages("httpuv.tar.gz", type = "source", repos = NULL)
Install using devtools via GitHub if the package supports it
Install RTools and re-try your package installation
Install an older version of the package
If those above do not work, then I dig deeper by referring to advice given to me by a VP of IT in my company. These comments were made in reference to frequent package installation problems I encountered when switching from Windows to Solaris:
There are two types of install/make problems. Missing .h files
and/or missing .so/.a libs. The reason for these are multiple:
1.- the package that delivers these is not installed. This means that those files cannot be found anywhere in the /usr tree. Solution is
install right package, make sure the files are there
2.- the includes are not found by the install configurator. This means some environment variable or install option is not properly set (this
is our case for RODBC). Figuring out which variable to set is
challenging without looking at the package documentation [fortunately, documentation is not hard to find!]
3.- the libs are not in the LD_LIBRARY_PATH, easy to fix.
4.- There is a deeper compile/link error, meaning the package is not compatible with the rest of the sw, or has not been properly ported.

Resources