Install a github package alongside a CRAN package with the same name? - r

Is there any reasonable way to install a CRAN package alongside a github package of the same name?
Specifically, I am after the geom_sf() geom in the sf branch in the ggplot2 github page: https://github.com/tidyverse/ggplot2/tree/sf. So I can install the sf branch like this:
devtools::install_github("tidyverse/ggplot2", ref = "sf")
And the CRAN version like this:
install.packages("ggplot2")
However, the sf branch is behind ggplot2 in other useful features so I don't want to completely revert. So I am wondering what the best approach is here. Can I install both but somehow call one package ggplot2_sf? Basically I want to be able to use geom_sf with the all the functionality of ggplot2 that is currently on CRAN.
I had thought that maybe the best solution was to fork the ggplot2 repo, merged the master and sf branches then install that. But I am wondering if there is a better way?
Update
So it turns out that you need to specify the lib directory using withr (see here). I tried this:
withr::with_libpaths(new = "./R/gh_libs/", install_github("tidyverse/ggplot2", ref = "sf"))
This returned this error:
Error in curl::curl_fetch_disk(url, x$path, handle = handle) :
Problem with the SSL CA cert (path? access rights?)
So I can set the SSL certification to zero like this:
httr::set_config( httr::config( ssl_verifypeer = 0L ) )
withr::with_libpaths(new = "./R/gh_libs/", install_github("tidyverse/ggplot2", ref = "sf"))
But then this doesn't install this in the directory I am after:
Downloading GitHub repo tidyverse/ggplot2#sf from URL
https://api.github.com/repos/tidyverse/ggplot2/zipball/sf Installing
ggplot2 Installing 1 package: digest Warning in
utils::install.packages(pkgs, repos = repos, type = type, dependencies
= dependencies, : 'lib = "C:/Program Files/R/R-3.3.3/library"' is not writable Error in utils::install.packages(pkgs, repos = repos,
type = type, dependencies = dependencies, : unable to install
packages
Any other ideas of what I might be doing wrong?

You can use devtools::dev_mode() for this. From the man page:
When activated, dev_mode creates a new library for storing installed packages. This new library is automatically created when dev_mode is activated if it does not already exist. This allows you to test development packages in a sandbox, without interfering with the other packages you have installed.

Related

Install dependencies of custom package

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.

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".

Install an R package directly from a URL for the package source

I would like to install a package directly from a URL for the package source. I want to do this to make it easy for people to test a pre-release version of the package which should not be widely (or permanently) available. This is a similar question but it is different because it only describes how to install from local files not general URLs.
For the sake of this question I will use a link to the boot package source. Reading ?install.packages particularly the description of the pkgs argument suggests:
install.packages(
"http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",
repos = NULL, type = "source"
)
However this fails with:
Warning in install.packages :
installation of package
‘http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz’
had non-zero exit status
Suggesting that the URL is being interpreted as the package name, not its location.
We can work around this with the following two step procedure:
download.file(
"http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",
"boot"
)
install.packages("boot", repos = NULL, type = "source")
But I would prefer to do this with a single call to install.packages only; and since install.packages is capable of downloading files anyway I feel this should be possible.
install.packages now works with http URLs (not https yet) as of 3.1.1. This works for me:
install.packages("http://www.lepem.ufc.br/jaa/colorout_1.1-0.tar.gz", repos=NULL)
Edit: As of R 3.2.0, https is builtin via libcurl. This should work now:
install.packages("https://github.com/hadley/devtools/archive/v1.7.0.tar.gz",
repos=NULL, method="libcurl")
Edit: As of R 3.2.2, https should work with default options assuming libcurl support was compiled in.
Edit 2016-04-20: There may be some issues downloading packages hosted on S3, but method='wget' seems to work for those for now.
See ?install_url in the devtools package.
Why not set up the directory in which you store the source package as a repository?
Here is an example (though you'd likely want to substitute type="source" for the type="win.binary" in the code at that link).
If the url is a github repository, try: install_github()
e.g.
library(devtools)
install_github("DeveloperName/PackageName")
# e.g. install_github("cran/seoR")

‘RGoogleTrends’

I am trying to install the package ‘RGoogleTrends’ in R but it says package ‘RGoogleTrends’ is not available (for R version 2.15.2). Any help in this regard will be highly appreciated.
Whilst it may not be available via install.package('RGoogleTrends', repos = "http://www.omegahat.org/R", type = "source"), you can download the package tar file http://www.omegahat.org/RGoogleTrends/RGoogleTrends_0.2-1.tar.gz and install from
the downloaded file, something like
install.packages("~/Downloads/RGoogleTrends_0.2-1.tar.gz", repos = NULL, type = "source")
replacing the path with the path on your system.
Note that RGoogleTrends imports the packages
RCurl, RSQLite, DBI
You may need to separately install these packages (with repos set to an appropriate non NULL value)

Resources