如何安装多个包?

时间:2015-03-13 20:29:57

标签: r packages

如何在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")

为什么赢得多个包的行?

3 个答案:

答案 0 :(得分:63)

小学:通过c(...)形成一个向量:

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

这样你就有一个长度为>的第一个参数1。

就我个人而言,我更喜欢littler中的install.r,所以我会(在Unix命令行中):

  install.r EIAdata gdata ggmap ggplot2    # rest omitted again

请注意,参数数量没有限制。对于我来说,使用四个包来写这个比你的例子中的20个更容易。

答案 1 :(得分:7)

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")


install.lib<-load.lib[!load.lib %in% installed.packages()]
for(lib in install.lib) install.packages(lib,dependencies=TRUE)
sapply(load.lib,require,character=TRUE)

答案 2 :(得分:4)

这是数据科学包的甜蜜套件

如果你使用的是外语,你还需要注意确保你没有使用有时在文本编辑器中创建的不同风格的引号。

$ 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.

  

警告讯息:   包'editR','rga','rcdimple','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 app / console
  • - &GT;帮助 - &gt; Html帮助
  • 参考 - &gt;封装

  • 打开RStudio
  • - &GT;帮助 - &gt; R帮助
  • 帮助区域
  • - &GT;参考 - &gt;封装