'Install R packages through "Jobs" tab in Rstudio
In Rstudio, I usually install R
packages using the console by install.packages('pkg-name')
command.
However, when some R
packages are required in an R script, Rstudio opens a pop-up and asks if I want to install those packages. If I click on "Install", it starts installing those packages inside the "Jobs" tab. This is particularly useful for me because my internet is slow and while a large package is being installed I can continue my works on the console tab. I want to know if there is any way to always install packages through this "Jobs" tab, without using the console.
Solution 1:[1]
There's an R package job
which can be used to run any r code directly from a script or console. To install a package as a Rstudio job:
# install.packages("job")
job::job({
install.packages("pkg_name")
})
Also {job} provides Rstudio Addins to easily run selected code as a job. see here for more examples.
Solution 2:[2]
You can create a script, let's call it temp.R
and include the install.packages
command in it. Something like :
install.packages('dplyr', repos = "http://cran.us.r-project.org")
install.packages('tidyr', repos = "http://cran.us.r-project.org")
You can click on Start Local Job
and point to the location of the script and adjust any other setting that you want.
Now click on Start
and use R/RStudio while the script finishes in the background.
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 | shafee |
Solution 2 | Ronak Shah |