Understanding install.packages() behaviour re repos and dependencies - r

I (finally) just installed ggplot2 by doing it from R directly and turning off antivirus. (It had previously failed out on moving the temp files for stringi and magrittr, so I followed the advice in StackOverflow.)
And it worked. But I have a few puzzles about its behaviour. The command I used was:
install.packages("ggplot2", repos = getOption("repos"), dependencies = TRUE)
Two things that happened as a result puzzled me:
it didn't ask me what repos I wanted to use - but just went to
imperial (which is fine with me)
it didn't install the dependencies - which I discovered when I did
library, so I installed the missing ones manually one by one (luckily
there were only two - the two that had failed out when I had tried an
install from RStudio with my antivirus on)
I have read the documentation on install.packages() but haven't understood it, as both these behaviours were different from what I expected. I thought I would get a query about what repos to go to, and I thought I would get the dependencies tagging along on the install.
Can someone explain?
Thanks.

It always install dependencies. That is the whole point of
having repos -- and why CRAN was so important over these 20 years, and
declaring dependencies in DESCRIPTION.
Now, I set my repos in the startup file (Rprofile.site in my case, see help(Startup) and its examples section for how). You can also just call options() before calling install.packages(). The dependencies=TRUE is also superfluous.
But thinks you need to check and did not tell us: source or binary installation? What OS? What is your R version and does it mesh with what the repos expect -- a current version on R?

Related

Facing trouble in loading packages in R studio [duplicate]

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?
The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

Updated R, copied library, still can't find packages, and can't seem to install all dependencies

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?
The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

how to make devtools install_github to install dependency packages from CRAN instead of compiling source

EDIT: see edit in end.
I have a R package in github and I'm using devtools::install_github to install it, which also install dependency packages.
Recently this process will install httpuv as source package, but compiling it in Mac meet errors with automake (something like this). I installed automake, then there was error with clang: error: unsupported option '-fopenmp'.
The issue and the possible solutions 1 2 seemed to be quite complicated. I think the CRAN version of httpuv probably will work for me, and I don't want my users to go through so many errors and fixing compiler errors.
I'd like to just install all dependency packages from CRAN in binary. For some packages that do need the more up to date version, I have specified it in my package description with remote section.
I checked install_github, then install, then install.packages. It seemed that the default behavior for binary vs source package is
An alternative (and the current default) is "both" which means ‘use
binary if available and current, otherwise try source’. The action if
there are source packages which are preferred but may contain code
which needs to be compiled is controlled by
getOption("install.packages.compile.from.source").
My getOption("install.packages.compile.from.source") is interactive. This is actually a preferred behavior for me. However I never see the interactive prompt.
I tried to give a type = "binary" parameter in install_github, but it doesn't seem to work, maybe it's not passed to every dependency package install?
EDIT:
I found the situation is a little bit more complex:
my app specified to install shiny github version via remote in description. shiny specified to install httpuv github version in remote section too. So this is actually the intended behavior.
I'm not sure if there is a solution available, other than require CRAN version of shiny in my package.
EDIT 2: It's more complex than my previous findings.
I removed remote section in my package description, supposedly only CRAN version is needed. However install_github still install most dependencies from github.
I finally found out that I have these dependencies github version installed, so their description in my local disk have the github remote information, and install_github found this information and "upgrade" them again, even when some of them have no change.
So I need to uninstall them first, only use CRAN version.
The really problem here is that if a dependency package is already new, it should not be installed. It could be a bug of devtools.
install_github passes arguments to devtools::install, and there upgrade_dependencies= FALSE and maybe even dependencies = FALSE might be what you're after:
install_github("you/urPackage", upgrade_dependencies = FALSE)

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.

How do I install an R package from the source tarball on windows?

The forecast package for R has been updated to version 2.12, but there are currently only windows binarys for 2.11 available on CRAN.
How do I install an R package from the source on Windows?
I know this is an old question but it came up first in my Google search for this same question, even though I knew the answer I just wanted something to copy and paste. Which makes it worth improving the answer for future reference. So here is what works for me:
Install rtools, then:
install.packages(path_to_file, repos = NULL, type="source")
Two answers that may help you avoid the hassle of installing Rtools.
Use http://win-builder.r-project.org/ to build a binary version, download it, and install (using install.packages(...,repos=NULL))
If the package has no binary component (i.e. no src directory with C, C++, or Fortran code that needs to be compiled during installation (not true for forecast, but possibly useful some other time) then simply specifying type="source" within the install.packages call (whether from a repository or a local copy of the source tarball (.tar.gz file)) will install the source package, even on Windows.
Start by reviewing the section on Windows packages in the R Installation and Administration manual, then carefully follow the instructions from The Windows toolset appendix.
I know it's usually bad form to mainly provide links in an answer, but these are links to the canonical references on this topic. I simply link to them rather than summarize their contents, since they should be accurate for the most current R release.
I'm not sure if this is the best way, but I found the following method to work (based in part on the answers above):
1) Download the package .tar
2) Move the package to the directory with your user R libraries (e.g., in my case it was "C:/Users/yourUserName/Documents/R/win-library/3.3")
3) Within Rstudio (or elsewhere, probably), run the command... install.packages("packageName.tar", repos=NULL, type="source")
That worked for me at least. Hope it's helpful!
Download the package *.tar.gz.
make sure you have Rtools installed.
Make sure the R and Rtools paths are added in the environment varialble.
Open a command prompt. Type R CMD INSTALL packagename.tar.gz.
it will work i hope.
To install a package from a .tar.gz file, follow these steps:
Launch R to have the R command prompt
Type: install.packages(<path_to_tar.gz_file>, repos = NULL)
or launch directly:
R CMD INSTALL <path_to_.tar.gz_file>
You need to have R installed but you don't need RTools

Resources