boshek
boshek

Reputation: 4416

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

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?

Upvotes: 2

Views: 710

Answers (1)

jsta
jsta

Reputation: 3403

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.

Upvotes: 1

Related Questions