Freshen up - Update your R version and packages from within R Studio!
Samantha Bell
Veterinary Data Analysis | Dashboards & Reporting | LVT | E-commerce | Bioinformatics
Is it time for an update? If you can't remember the last time you updated R, the answer is most likely, "yes". Noticing code that works on your machine but not for a teammate? Updating all of the users in your group with the latest version of R and your chosen packages can help avoid errors and keep everyone working smoothly together.
Getting a fancy, newfangled version of R
Ok, the fancy part may be debatable, but when we need the latest and greatest version of R there is a simple way to access it through R studio (no need to worry about installing from command line).
The package installR will do the heavy lifting for you, including cleaning up old versions of R. Just run the following from your R studio console:
install.packages("installr")
library(installr)
updateR()
(This is made for Windows users, but the full tutorial and other install options such as updateR for Mac can be found in this nice article from Perth.
Get your packages out of the dark ages
Not sure which packages might be out of date? Dreading re-installing each package one at a time? Fear not! This handy snippet of code will check your library and update all of your packages with one click of your enter button!
This is a nice way to get a full update because it can be done even if your version of R was not updated recently, whereas update.packages(checkbuilt = TRUE) will overlook certain situations in which the package was compiled after the latest R upgrade.
Keep in mind two things:
领英推荐
1) If you work over VPN at times, you may have separate R "library" folders that need updating on each station you work from. You can check this by running:
.libPaths()
2) This can take some time if you have many packages downloaded. Keep in mind how much time it usually takes to install or load a package, then consider how many packages are in your library folder. (if crunched for time, run update.packages(checkbuilt = TRUE) )
To update your primary library folder:
myLib <- .libPaths()[1]
install.packages(
? ? lib ?= myLib,
? ? pkgs = as.data.frame(installed.packages(myLib), stringsAsFactors=FALSE)$Package,
? ? type = 'source'
)
To update all of your library folders:
for(i in .libPaths()){
myLib <- i
install.packages(
? ? lib ?= myLib,
? ? pkgs = as.data.frame(installed.packages(myLib), stringsAsFactors=FALSE)$Package,
? ? type = 'source'
)
}
Restart R Studio and you should be ready to go!
Happy Programming!