![](/img/trans.png)
[英]How to keep using R version 2.x and download packages automatically with install.packages() by package name?
[英]How to download and install package automatically if required in R?
如果 RStudio 中未安裝此軟件包,如何自動從 GitHub 下載並安裝它?
install.packages("remotes")
remotes::install_github("davidsjoberg/ggsankey")
library(ggsankey)
使用pacman
包中的p_load_gh()
pacman::p_load_gh("davidsjoberg/ggsankey")
這將檢查ggsankey
是否已安裝,如果沒有,它將安裝它然后加載包。
加載 ggsankey 或者如果未安裝加載遙控器,或者如果未安裝則安裝它,然后使用它來安裝和加載 ggsankey。 如果您希望查看警告消息,請忽略 quiet quietly=TRUE
。 這些說明不依賴於 RStudio,應該更通用。
請注意,這會安裝軟件包,但不會安裝外部程序,例如 R 本身和 Windows Rtools。 對於帶有 C/C++ 代碼的包,Windows 上需要后者。 此外,如果用戶使用的是舊版本的 R,則任何包依賴項可能僅在 CRAN 上以源代碼形式提供,從而增加了他們在 Windows 上需要 Rtools 的可能性。 因此,說明應指定使用最新版本的 R 並在 Windows Rtools 上安裝該版本。 這兩個都很容易安裝,因為它們有自動安裝程序。
if (!require("ggsankey", quietly = TRUE)) {
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
remotes::install_github("davidsjoberg/ggsankey",
dependencies = TRUE, upgrade = TRUE, quiet = TRUE)
library("ggsankey")
}
也就是說,自動安裝軟件似乎很危險。 建議您只向他們提供有關安裝軟件和加載它的說明,說明如何首先在 Windows 上安裝最新版本的 R 和 Rtools。
# From within R install ggsankey R package.
# Only needs to be done once.
install.packages("remotes")
remotes::install_github("davidsjoberg/ggsankey",
dependencies = TRUE, upgrade = TRUE, quiet = TRUE)
# load ggsankey - needs to be done in every new R session using it
library(ggsankey)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.