2

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?

Community
  • 1
  • 1
boshek
  • 4,100
  • 1
  • 31
  • 55
  • you can set the library location when you `install.packages` and also when you `library`, is that what you want? – rawr Apr 21 '17 at 21:56
  • Oh I see - so if I have my default library local for the CRAN ggplot installation then to install the ggplot2 sf branch on github I'd do something like this: `devtools::install_github("tidyverse/ggplot2", ref = "sf", lib="./R/gh_libs")` the load it like this: `library(ggplot2, lib.loc = "./R/gh_libs")`? Am I understanding that right? – boshek Apr 21 '17 at 22:17
  • yep, I tried that on another package and kept both versions. there might be a cleaner way, not sure – rawr Apr 21 '17 at 23:16
  • See update for further attempts at this. – boshek Apr 24 '17 at 16:03

1 Answers1

1

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.

jsta
  • 3,216
  • 25
  • 35