【问题标题】:Install a github package alongside a CRAN package with the same name?在同名的 CRAN 包旁边安装一个 github 包?
【发布时间】:2017-09-19 00:32:33
【问题描述】:

是否有任何合理的方法可以将 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"))

这返回了这个错误:

curl::curl_fetch_disk(url, x$path, handle = handle) 中的错误:
SSL CA 证书有问题(路径?访问权限?)

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

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

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

从 URL 下载 GitHub repo tidyverse/ggplot2@sf https://api.github.com/repos/tidyverse/ggplot2/zipball/sf 安装 ggplot2 安装 1 个包:摘要警告 utils::install.packages(pkgs, repos = repos, type = type, 依赖 = 依赖项,:'lib = "C:/Program Files/R/R-3.3.3/library"' 不可写 utils::install.packages 中的错误(pkgs,repos = repos, type = type, dependencies = dependencies, : 无法安装 包

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

【问题讨论】:

  • install.packageslibrary 时都可以设置库位置,这是你想要的吗?
  • 哦,我明白了 - 所以如果我有我的默认库本地用于 CRAN ggplot 安装,那么要在 github 上安装 ggplot2 sf 分支,我会做这样的事情:devtools::install_github("tidyverse/ggplot2", ref = "sf", lib="./R/gh_libs") 像这样加载它:library(ggplot2, lib.loc = "./R/gh_libs")?我理解的对吗?
  • 是的,我在另一个包上尝试过,并保留了两个版本。可能有更清洁的方法,不确定
  • 查看更新以获得进一步的尝试。

标签: r git github sf


【解决方案1】:

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

激活后,dev_mode 会创建一个新库来存储已安装的包。如果该新库尚不存在,则在激活 dev_mode 时会自动创建此新库。这允许您在沙箱中测试开发包,而不会干扰您已安装的其他包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 2021-04-04
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多