安装 github 包和同名的 CRAN 包?

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

是否有任何合理的方法来安装 CRAN 包和同名的 github 包?

具体来说,我在 ggplot2 github 页面的 sf 分支中的 geom_sf() geom 之后:https://github.com/tidyverse/ggplot2/tree/sf。所以我可以像这样安装 sf 分支:

devtools::install_github("tidyverse/ggplot2", ref = "sf")

CRAN 版本是这样的:

install.packages("ggplot2")

但是,sf 分支在其他有用功能方面落后于 ggplot2,所以我不想完全还原。所以我想知道最好的方法是什么。我可以同时安装两者但以某种方式调用一个包 ggplot2_sf 吗?基本上我希望能够将 geom_sf 与当前在 CRAN 上的 ggplot2 的所有功能一起使用。

我认为也许最好的解决方案是分叉 ggplot2 存储库,合并 master 和 sf 分支然后安装它。但是我想知道有没有更好的方法?

更新

原来需要使用withr指定lib目录(见here)。我试过这个:

withr::with_libpaths(new = "./R/gh_libs/", install_github("tidyverse/ggplot2", ref = "sf"))

这返回了这个错误:

Error in curl::curl_fetch_disk(url, x$path, handle = handle) :
Problem with the SSL CA cert (path? access rights?)

所以我可以像这样将 SSL 认证设置为零:

httr::set_config( httr::config( ssl_verifypeer = 0L ) )
withr::with_libpaths(new = "./R/gh_libs/", install_github("tidyverse/ggplot2", ref = "sf"))

但是这并没有将其安装在我之后的目录中:

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

关于我可能做错了什么的任何其他想法?

您可以为此使用 devtools::dev_mode()。来自手册页:

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.