I have a library (in this case ggplot2) installed at the system level. I want to install ggplot2 and all it's dependencies to a new directory which is specify in the R_LIBS_USER variable. When I run install.packages('ggplot2', dependencies=TRUE)
it seems to make a copy of ggplot2 directory but none of the other other dependencies. Is there any way to make sure that the other packages that ggplot2 depends on makes it to the directory that I specified in R_LIBS_USER?
Asked
Active
Viewed 387 times
-1

jamesatha
- 7,280
- 14
- 37
- 54
-
`install.packages` has a `lib` parameter .... did you try that? If you want the second of two or more locations on your current directories then I will post the code for that as a possible answer. – IRTFM Jul 13 '16 at 22:46
-
I did try that but that didn't work either. The lib parameter, when unspecified, defaults to the first element in .libPaths() which was the directory I passed for R_LIBS_USER – jamesatha Jul 13 '16 at 22:52
-
You are saying that the dependencies at put into a location that is not on .libPaths()? Hard to believe. Are you an RStudio user? – IRTFM Jul 13 '16 at 22:54
-
I am using command-line R. The other dependencies were already installed system wide and are there somewhere else in my .libPaths(). I just don't get why the dependencies are not copied over in the same way that ggplot2 is. I want that to apply to everything – jamesatha Jul 13 '16 at 22:56
-
So you want code to make unnecessary copies of packages that are already "visible" to R? Once you install ggplot2, Then there is a packageDescription function that lets you read its dependencies. – IRTFM Jul 13 '16 at 22:59
-
Yes, I would like a copy of everything. In this case ggplot2 was already installed system-wide (with it's dependencies). I just don't understand why it doesn't copy everything it needs to the R_LIBS_USER directory. – jamesatha Jul 13 '16 at 23:04
-
The help page only promises that _uninstalled_ packages will be fetched. As to "why" that's a Q for the developers, most of whom are not reading SO questions. The latter part of my answer addresses the "how" question. You have not addressed what you actually mean by a "dependency". I included the "Imports" since I suspect that's what you meant. – IRTFM Jul 13 '16 at 23:07
1 Answers
0
Perhaps this ... under the assumption that your $R_LIBS_USER environment variable has been puahed to a second position in the search paths somehow by another location. (Check with .libPaths()
)
install.packages('ggplot2', lib= .libPaths[2], dependencies=TRUE)
Or:
install.packages('ggplot2', lib= Sys.getenv(("R_LIBS_USER"), dependencies=TRUE)
Comments suggest that the problem is that imported packages are already in libraries that R is searching... so won't be unnecessarily installed. There are no packages in the Depends entry for the DESCRIPTION
file, but there are packages named in the Imports
section. To read dependencies from an installed package:
packageDescription("ggplot2", fields = c("Depends","Imports") )
#-----------
Depends: R (>= 3.1)
Imports: digest, grid, gtable (>= 0.1.1), MASS, plyr (>=
1.7.1), reshape2, scales (>= 0.3.0), stats
-- File: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/ggplot2/Meta/package.rds
-- Fields read: Depends, Imports
> str( packageDescription("ggplot2", fields = c("Depends","Imports") ) )
List of 2
$ Depends: chr "R (>= 3.1)"
$ Imports: chr "digest, grid, gtable (>= 0.1.1), MASS, plyr (>= 1.7.1),\nreshape2, scales (>= 0.3.0), stats"
- attr(*, "class")= chr "packageDescription"
- attr(*, "fields")= chr [1:2] "Depends" "Imports"
- attr(*, "file")= chr "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/ggplot2/Meta/package.rds"
The downvote suggests that someone doesn't like having these facts pointed out but ... facts are facts.

IRTFM
- 258,963
- 21
- 364
- 487