A R update method proposed by Dr. Jeffrey S. Evans, University of Wyoming. Here is the method background and details:
Updating R to a new version can be difficult so, I thought that R users out there would find these R version management and configuration approaches useful. There is an R package “installr” that allows one, at the command line, to check the current R version and optionally: 1) download the new version, 2) launch the install, 3) move installed libraries to the new R install, 4) update libraries and 5) uninstall the previous R version. I also attached an “Rprofile.site” R GUI configuration file that will set the path for the R library and changes some other settings.
Following is the code that will install and require the “installr” package and run the “updateR” function with the appropriate flags. To run in Windows, right click the R icon and select "Run as administrator". This script will automatically: 1) check and download the current version of R, 2) execute the install, 3) move current packages to new install, 4) delete old packages, 5) update packages. Copy and paste the following highlighted code block and then answer the queries at the R commandline.
# set a CRAN mirror and library path
.Library.site <- file.path(chartr("\\", "/", R.home()), "library")
.libPaths(file.path(chartr("\\", "/", R.home()), "library"))
local({r <- getOption("repos")
options(repos=r)})
# If not installed, adds installr library and runs updateR function
if(!require(installr)) {
require(installr)
}
updateR(install_R = TRUE, copy_packages = TRUE, keep_old_packages = FALSE,
update_packages = TRUE, quit_R = FALSE, keep_install_file = FALSE)
In the R install wizard choose:
Go with install defaults until...
Under "select components", uncheck 32-bit core files NEXT>
Under "startup options" select: Yes (customize startup) NEXT>
Under "Display Mode" select: SDI (separate windows) NEXT>
Then go with defaults.
You can then uninstall the previous R version(s), with this command, by choosing the previous version in the popup-box, or just specifying the version.
uninstall.R() for interactive window or uninstall.R("3.1.2") to uninstall a specific version.
The “Rprofile.site” R GUI configuration file configures the R GUI:
1) sets the default library path, so that it does not default to your windows users directory (as long as packages are installed with R running as administrator);
2) sets a few options so numbers are never displayed as scientific notation and strings are not automatically coerced into factors and;
3) adds two useful functions “ls.functions” and “unfactor”. The “ls.functions” will list all the functions, associated with the specified package, in the R namespace and the “unfactor” function will coerce factors in a data.frame into a character class.
#### example to list all available functions in the MASS package ####
require(MASS)
ls.functions(MASS)
#### coerce factor to character ####
( x <- data.frame( y=as.factor(c("1","3","5")),
x=as.factor(c("yes","no","perhaps"))) )
str(x)
# Coerce single column
class(unfactor(x)$y)
# Coerce entire data.frame
x <- unfactor(x)
str(x)