如何安装多个软件包?

我如何在 R 中安装多个软件包?

我试了下面的代码:

install.packages("EIAdata", "gdata", "ggmap", "ggplot2","gridExtra","ISOweek","kobe","lubridate","maps","MASS","memisc","pander","plyr","psych","Quandl","quantmod","reshape2","rgeos","Rgnuplot","RODBC","scales","sp","sqldf","stockPortfolio","stringi","stringr","XLConnect", "xlsReadWrite","zipcode")

这个代码是有效的:

install.packages("ggplot2")

为什么有多个软件包的线路不起作用?

91153 次浏览

初等: 通过 c(...)形成一个向量:

 install.packages(c("EIAdata", "gdata", "ggmap", "ggplot2")) # rest omitted

因此,的第一个参数的长度大于1。

就个人而言,我更喜欢 小一点中的 install.r,所以我会这样做(在 Unix 命令行中) :

  install.r EIAdata gdata ggmap ggplot2    # rest omitted again

注意,参数的数量没有限制。对我来说,用四个包编写这个代码比用你的示例中的20个包编写这个代码要容易得多。

# Here we have a list of packages we want to install


load.lib<-c("EIAdata", "gdata", "ggmap","ggplot2","gridExtra","ISOweek",
"Kobe","lubridate","maps","MASS","memisc","pander","plyr","psych",
"Quandl","quantmod","reshape2","rgeos","Rgnuplot","RODBC","scales",
"sp","sqldf","stockPortfolio","stringi","stringr","XLConnect",
"xlsReadWrite","zipcode")


# Then we select only the packages that aren't currently installed.


install.lib <- load.lib[!load.lib %in% installed.packages()


# And finally we install the missing packages, including their dependency.
for(lib in install.lib) install.packages(lib,dependencies=TRUE)
# After the installation process completes, we load all packages.
sapply(load.lib,require,character=TRUE)

下面是数据科学软件包的 很棒的套房

您还需要注意,以确保您没有使用不同样式的引号,这些引号有时是在文本编辑器中创建的,如果您使用的是外语。

$ R

> install.packages(c("remotes","readxl","googlesheets","haven", "readr", "rio", "Hmisc", "sqldf", "jsonlite", "XML", "httr", "quantmod", "tidyquant", "rvest", "dplyr", "purrr", "reshape2", "tidyr", "magrittr", "validate", "testthat", "data.table", "stringr", "lubridate", "zoo", "editR", "knitr", "officer", "listviewer", "DT", "ggplot2", "ggiraph", "dygraphs", "googleVis", "metricsgraphics", "RColorBrewer", "sf", "leaflet", "ggmap", "tmap", "tmaptools", "mapsapi", "tidycensus", "glue", "rga", "RSiteCatalyst", "roxygen2", "shiny", "flexdashboard", "openxlsx", "gmodels", "janitor", "car", "rcdimple", "foreach", "scales", "plotly", "highcharter", "profvis", "tidytext", "diffobj", "Prophet", "feather", "fst", "googleAuthR", "cloudyR"))

如果您正在从 CLI R 安装,则会显示 --- Please select a CRAN mirror for use in this session ---,几秒钟后,将弹出一个 GUI,并显示一个全局下载镜像列表。

如果您正在使用 R 的最新版本,您可能会得到一个警告,即某些较旧的包不适用于您的 R 版本,您可以选择忽略、查找较新的包或使用较旧的 R 版本。

警告信息: 软件包‘ edit R’、‘ rga’、‘ rcdiple’、‘ Prophet’、‘ CloudyR’不可用(针对 R 3.4.2版本)

Tgz 压缩文件将被下载到类似 /private/var/folders/2k/p756_j5x0x5fqplwrq74j1sh0000gn/T/RtmpMTzQQ5/downloaded_packages的地方

位于 /Users/tymac/Library/R/3.4/library/Library/Frameworks/R.framework/Versions/3.4/Resources/library中的实际包。

您可以通过其他几种方式查看包。

  • 打开 R 应用程序/控制台
  • —— > 帮助—— > HTML 帮助
  • 参考资料-> 软件包

或者

  • 打开 RStudio
  • —— > 帮助—— > R 帮助
  • 帮助区域
  • - > 参考-> 软件包