I have built an R package, i.e. I have the mypackage.tar.gz file. This package depends on several other packages, all downloadable and installable from any CRAN mirror.
Now I want to install this package on a system where the dependencies are not yet installed, and I would like that the dependencies will be downloaded and installed automatically when I install my package.
I tried:
install.packages("mypackage.tar.gz",type="source",dependencies=TRUE,repos="http://a.cran.mirror")
but it searches for mypackage.tar.gz
on the mirror (and obviously it does not find), while if I set repos=NULL
it correctly tries to install the local package file (as documented), but obviously it does not find the dependencies packages.
So my question is: is there a way to perform a 'mixed' installation (local package with online dependencies) or the only way to do is to manually install all the dependencies?
Here, I'm using
untar()
withdevtools::install()
and passing in a directory to which the source tarball has been extracted.If you want to install from multiple repos, you can provide a list of them. For example, to use both Bioconductor and CRAN, you could run:
NOTE: I can't figure out how to directly pass the tarball to
install()
, but this solution works in the meantime and leaves no clutter because we extract to a temp directory. It seemsinstall_local()
should be able to take a tarball, but I am getting an error when attempting to do so.If you already have installed your local package, you should be able to use a couple functions in tools to install the dependencies from CRAN:
Note: You can pass args (like
repos
) throughinstallFoundDepends
toinstall.packages
.You can also use the
Depends
element from thepkgDepends
output to pass directly toinstall.packages
:UPDATE: Apparently it is not possible to install a local package with
dependencies=FALSE
. This seems odd, since you can do that for a remote package from a repository. The reason (looking at the source code) is thatif(is.null(repos) & missing(contriburl))
, installation is handled via system calls toR CMD INSTALL
, which has no dependency-related arguments.I personally use RStudio which tells you which dependencies are missing. Then I copy the string in the arguments of the following small script to change the 'strange' symbols in classical " (xclip is copying to clipboard [it is like pbcopy on macOS]).
Then I simply use
install.packages(c(ctrl_v__what_to_install))
and R starts to install all the dependencies.NB: remember that the two
‘
written in the above script are different and the first time you copy this script, I advise to copy again the original quotation marks characters.You could use
install
from the devtools package. Just runinstall("<directory of your package>", dependencies = TRUE)
. Its help states: