r - 如何从 github 下载(不安装)包
问题描述
无论如何从github下载压缩包而不安装它?
例如运行:
devtools::install_github("tidyverse/tidyr")
一次下载和安装。有什么相当于
download.packages("tidyr", destdir = "path")
对于 github 包?
解决方案
如果您想下载 GitHub 存储库(在本例中为tidyr
包),您可以使用download.file
并通过右键单击复制 GitHub“克隆或下载”按钮中的链接。
download.file(url = "https://github.com/tidyverse/tidyr/archive/master.zip",
destfile = "tidyr.zip")
如果你想要一个函数来做到这一点,一个可能的解决方案可能是(它将下载到当前工作目录):
download_git <- function(repo_name, repo_url, install = FALSE){
url_git <- paste0(file.path(repo, "archive", "master"), ".zip")
download.file(url = url_git,
destfile = paste0(repo_name, "-master.zip"))
if(install) {
unzip(zipfile = paste0(repo_name, "-master.zip"))
devtools::install(paste0(repo_name,"-master"))
}
}
你这里是一个如何使用它的例子(带有安装选项):
download_git(repo_name = "tidyr",
repo_url = "https://github.com/tidyverse/tidyr",
install = TRUE)
推荐阅读
- spring-boot - 使用 RestTemplate POST 方法仅使用查询参数发布请求
- typescript - Typescript 有时不接受 Redux 容器传递的 props
- javascript - HTML AJAX 实时更新 PHP 变量,使用 ajax 计数动画
- postgresql - Postgres 批量插入不同的模式
- python - 如何在熊猫上将一列年份与一列月份字符串连接起来以创建一个新的日期时间列
- .net - vb.net 拆分字符串组
- python - 将上下文传递给 django 管理索引页面
- java - 在表单期间临时保存数据
- intellij-idea - 通过 Intellij 在码头服务器中配置自定义上下文路径战争
- python - 删除数组中的连续元素