'How to install multiple packages?
How would I got about installing multiple packages in R?
I tried the following code:
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")
This code works:
install.packages("ggplot2")
Why won't the line with the multiple packages work?
Solution 1:[1]
Elementary: form a vector via c(...)
:
install.packages(c("EIAdata", "gdata", "ggmap", "ggplot2")) # rest omitted
so that you have one first argument of length > 1.
Personally, I prefer install.r
from littler so I'd do (at the Unix command-line):
install.r EIAdata gdata ggmap ggplot2 # rest omitted again
Note that there is no limit to the number of arguments. It was just easier for me to write this with four packages than the 20-some from your example.
Solution 2:[2]
# 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)
Solution 3:[3]
Here is a sweet ? suite of data science packages?
You will also need to pay attention to make sure you're not using different styled quotation marks that are sometimes created in text editors if you’re using a foreign language.
$ 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"))
If you're installing from CLI R will say --- Please select a CRAN mirror for use in this session ---
and after a couple of seconds a GUI will pop up and show a list of global download mirrors.
If you're using the latest version of R you might get a warning that certain older packages aren't available for your R version which you can choose to ignore, find newer packages or use an older version of R.
Warning message: packages ‘editR’, ‘rga’, ‘rcdimple’, ‘Prophet’, ‘cloudyR’ are not available (for R version 3.4.2)
The compressed .tgz files will be downloaded somewhere like /private/var/folders/2k/p756_j5x0x5fqplwrq74j1sh0000gn/T/RtmpMTzQQ5/downloaded_packages
Actual packages located in /Users/tymac/Library/R/3.4/library
and /Library/Frameworks/R.framework/Versions/3.4/Resources/library
.
You can view packages a couple of other ways.
- Open R app/console
- --> Help --> Html help
- Reference --> Packages
or
- Open RStudio
- --> Help --> R Help
- help area
- --> Reference --> Packages
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David Arenburg |
Solution 2 | Community |
Solution 3 |