Install dependencies of custom package - r

I have developed a local package that depends on others available on CRAN (as an example, pool). Therefore, when I attempt to install the package using the standard
install.packages("/path/to/package",
repos = NULL,
type = "source")
I get an error because the dependencies aren't installed. install.packages has an argument dependencies which by default would try to install those dependencies. However, as stated by the man page (and commented in the linked question below), repos = NULL means the dependencies are ignored.
To get around that, I used package miniCRAN to create a repo containing my package, hoping I could do a repos = c("myRepo", getOption("repos")) to get it to work.
Now I can install my package using
install.packages("package",
repos = c("/path/to/repo", getOptions("repos"),
type = "source")
But only if I've already installed pool. If not, I still get an error because it can't find the dependencies.
So I called miniCRAN::addPackage("pool"), which adds that package and its many dependencies to my repo, and they all appear if I call miniCRAN::pkgAvail().
However, if I attempt to install my package again, I still get a there is no package called 'pool' error.
Interestingly, if I try to install pool itself from the repo, it works.
install.packages("pool",
repos = "/path/to/repo",
type = "source")
install.packages("package",
repos = "/path/to/repo",
type = "source")
Obviously, however, this kind of beats the point of adding pool to the repo: I might just as well have installed it from CRAN.
So what's going on here, and is this really the only way to install local packages and their CRAN dependencies?

Figured it out.
The problem was a misunderstanding on my part regarding roxygen, which I've been using for my documentation. I assumed it handled the Imports: section of the DESCRIPTION file, which it doesn't ((1), (2)). So while the NAMESPACE file has all the necessary importFrom(pool, ...) calls, pool wasn't actually on my DESCRIPTION.
After fixing that oversight, using remote::install_local("path/to/pkg") (or devtools::install()) ((3)) worked: it installed my package and pulled its dependencies from CRAN.

Related

install dependencies from CRAN for a package installed from source

I want to give a beta version of my package to a coworker for testing purposes.
I build the package and put the .zip file on the Network Folder.
The Problem is, how to tell R that it should install the package from the ZipFile but its dependencies from CRAN?
install.packages("path\\to\\zipfile.zip", source = TRUE, repos = NULL)
Because repos = null disables the dependency resultion. If under stand the documentation correctly:
dependencies
logical indicating whether to also install uninstalled packages which these packages depend on/link to/import/suggest (and so on recursively). Not used if repos = NULL. Can also be a character vector, a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").
I would like to give the coworker a short snippet of code to install for himself without him having to interact further with the installation.
As the Imports or dependencies might change in later development, i would prefer not to hardcode them.
I found devtools::install() which satisfies this requirement. Although it needs devtools.

Why R cannot find dependencies that are in the same local folder as the primary package?

Downloaded packages (in form of .tar.gz) to /tmp. I have read, write, and execute permissions to all packages. I try installing some packages (e.g. mapview), but R gives me an error
> install.packages("mapview.xyz.tar.gz", repos = NULL, dependencies = TRUE, type = "source")
ERROR: dependencies .... not available
All the dependencies listed in the ERROR message are present in the same folder as mapview package. Unclear why R cannot find those additional packages. Suggestions?
Adam's observation is right. Not being able to set repos = NULL when dependencies is set caused the problem. Ultimate solution was to use a different function. Following worked for me:
library(devtools)
install_local(...) # added parameters that were relevant for my situation

Loading dependencies from package-internal packrat library

I am building an R package with packrat. The package is fully tested and installation from the locally saved source file by
install.packages("myPackage.tar.gz", repos = NULL, type = "source")
works if all dependencies (specified in the Imports: field) are installed on the local machine.
However, I would like to install that package on another server where dependencies are not installed. When I try to do this, I get the error
"ERROR: dependencies ‘survey’, ‘dplyr’ are not available for package 'myPackage'"
I also tried to install the packrat bundle which I created by calling
packrat::bundle(project = 'pathtomypackageproject', file = 'myPackage.tar.gz',
include.lib = TRUE)
but I get the same error.
I think the problem is that, upon installing 'myPackage', R searches the first element of .libPaths(), doesn't find anything and since "repos = NULL" is specified, has nowhere to install the packages from so the error is thrown.
A solution I'm still trying to avoid is to transfer a repository containing all dependencies to the server and pointing to the repository when installing the package. Ideally, I only have to transfer myPackage.tar.gz.
My question is if there is some way to point to the internal packrat library, where all dependencies can be found, and import the namespaces from there.
If you have included the list of packages to be imported in DESCRIPTION File, then you just need to do this while installation of your package:
install.packages("myPackage",dependencies=TRUE)

Error When Installing Packages with Dependencies from Local Repo

I have an error when installing packages offline when they have dependencies. This is very similar to this question. I have followed the instructions there to do the offline install.
So I have installed all the CRAN packages to a directory and created the PACKAGES file also.
But there seems to be a subtle bug with the process outlined in that answer
I can install a package from the local repo on Linux with no problem using the command below i.e. not specifiying the repo:
install.packages("/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", lib="/usr/lib64/R/library")
However, if I want to pick up the dependencies I need to point it towards the repo and its PACKAGES file using e.g.
install.packages("/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", lib="/usr/lib64/R/library", repos="file:///software/r_packages/")
But if I do this I get the error:
Warning message:
package ‘/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz’ is not available (for R version 3.2.3)
I've tested and confirmed it is reading the PACKAGES file because if I put a typo into the entry for ZillowR in PACKAGES I get an error indicating it can't parse the entry correctly.
What should work for you here is the following:
install.packages(pkgs = "ZillowR", type = "source",
lib = "/usr/lib64/R/library",
contriburl = "file:///software/r_packages/")
The arguments to install.packages() can be pretty overwhelming and all of the defaults are configured to work with packages installed from CRAN (or another remote repository). To unpack what is going on here, consider the following code to install ZillowR from CRAN:
install.packages(pkgs = "ZillowR")
This is setting lots of defaults, so you're actually calling:
install.packages(pkgs = "ZillowR", lib = .libPaths()[1],
repos = getOption("repos"),
contriburl = contrib.url(repos, type),
type = getOption("pkgType"))
The two key defaults are calling some global options, which on my install are set to:
> getOption("repos")
CRAN CRANextra
"https://cloud.r-project.org" "http://www.stats.ox.ac.uk/pub/RWin"
> getOption("pkgType")
[1] "both"
You need to (potentially) overcome these defaults into order to do a local install and the key one to overcome is the value of contriburl (which inherits from repos. Knowing that, your intuition appears (rightly) to have been to follow the instructions for installing a local source package, such as:
install.packages(pkgs = "/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", repos = NULL, type = "source")
But the behavior of install.packages() is totally different there because the pkgs argument is expecting the filename of a source tarball (when repos and thus contriburl is NULL).
With a local CRAN-like repo, you actually want to set pkgs to the package name and to set contriburl to the local repo path. As a reference here's the relevant section of the docs for contriburl:
contriburl URL(s) of the contrib sections of the repositories. Use this argument if your repository mirror is incomplete, e.g., because you burned only the ‘contrib’ section on a CD, or only have binary packages. Overrides argument repos. Incompatible with type = "both".
The last sentence shows why you (may) need to set type = "source".

installing an archived package

The package is available on this website.
http://cran.r-project.org/src/contrib/Archive/rlandscape/
When I use:
install.packages("rlandscape",
repos = "http://cran.r-project.org/src/contrib/Archive/rlandscape/",
type="source")
I get the following error:
package 'rlandscape' is not available (for R version 3.1.2)
I have tried older versions too but no luck..
The devtools package has a function that can install archived versions. Try:
library("devtools")
install_version("rlandscape",version="1.0",
repos="http://cran.r-project.org")
(You should be able to use repos=getOption("repos")["CRAN"] instead, but it looks like your repos option is slightly messed up, i.e. the URL is missing the http://.)
(The repos argument is necessary to work around what I think is a glitch in install_version, i.e. it assumes that repos is a length-1 character vector.)
This should, I think, also automatically install appropriate dependencies -- although it's a bit of a catch-22 if they are in the CRANextra repository for Windows, since that has to be suppressed in order to get install_version to work ...
It may also be the case that install_version automatically assumes that you want the package and all dependencies installed as source (not binary) installations, in which case you will need to have compilation tools installed. The rlandscape package doesn't actually have any compiled code included, but its dependencies do ...
This is an old (archived) package that is no longer supported. If you really need it, you can install it using R CMD INSTALL but you need also to install all its dependencies manually.
Installing your desired package gave me the following:
>R CMD INSTALL ~/Downloads/rlandscape_1.0.tar.gz
* installing to library ‘/Users/mohamedahmed/Rlibs’
ERROR: dependencies ‘spatstat’, ‘deldir’, ‘gWidgets’, ‘gWidgetsRGtk2’ are not available for package ‘rlandscape’
* removing ‘/Users/mohamedahmed/Rlibs/rlandscape’
I am not sure all dependencies are still available on CRAN, but it seems to be challenging task.

Resources