Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
R in Action, Second Edition.pdf
Скачиваний:
540
Добавлен:
26.03.2016
Размер:
20.33 Mб
Скачать

appendix G Updating an R installation

As consumers, we take for granted that we can update a piece of software via a Check for Updates option. In chapter 1, I noted that the update.packages() function can be used to download and install the most recent version of a contributed package. Unfortunately, updating the R installation itself can be more complicated.

If you want to update an R installation from version 5.1.0 to 6.1.1, you must get creative. (As I write this, the current version is actually 3.1.1, but I want this book to appear hip and current for years to come.) Two methods are described here: an automated method using the installr package and a manual method that works on all platforms.

G.1 Automated installation (Windows only)

If you’re a Windows user, you can use the installr package to update an R installation. First install the package and load it:

install.packages("installr")

library(installr)

This adds an Update menu to the RGui (see figure G.1).

The menu allows you to install a new version of R, update existing packages, and install other useful software produces (such as RStudio). Currently, the

Figure G.1 Update menu added to Windows RGui by the installr package

555

556

APPENDIX G Updating an R installation

installr package is only available for Windows platforms. For Mac users, or Windows users that don’t want to use installr, updating R is usually a manual process.

G.2 Manual installation (Windows and Mac OS X)

Downloading and installing the latest version of R from CRAN (http://cran.r-project

.org/bin) is relatively straightforward. The complicating factor is that customizations (including previously installed contributed packages) aren’t included in the new installation. In my current setup, I have more than 500 contributed packages installed. I really don’t want to have to write down their names and reinstall them by hand the next time I upgrade my R installation!

There has been much discussion on the web concerning the most elegant and efficient way to update an R installation. The method described here is neither elegant nor efficient, but I find that it works well on both Windows and Mac platforms.

In this approach, you use the installed.packages() function to save a list of packages to a location outside of the R directory tree, and then you use the list with the install.packages() function to download and install the latest contributed packages into the new R installation. Here are the steps:

1If you have a customized Rprofile.site file (see appendix B), save a copy outside of R.

2Launch your current version of R, and issue the following statements

oldip <- installed.packages()[,1]

save(oldip, file="path/installedPackages.Rdata")

where path is a directory outside of R.

3Download and install the newer version of R.

4If you saved a customized version of the Rprofile.site file in step 1, copy it into the new installation.

5Launch the new version of R, and issue the following statements

load("path/installedPackages.Rdata") newip <- installed.packages()[,1] for(i in setdiff(oldip, newip)){

install.packages(i)

}

where path is the location specified in step 2.

6 Delete the old installation (optional).

This approach will install only packages that are available from CRAN. It won’t find packages obtained from other locations. You’ll have to find and download these separately. Luckily, the process displays a list of packages that can’t be installed. During my last installation, globaltest and Biobase couldn’t be found. Because I got them from the Bioconductor site, I was able to install them via this code:

source("http://bioconductor.org/biocLite.R")

biocLite("globaltest")

biocLite("Biobase")

APPENDIX G Updating an R installation

557

Step 6 involves the optional deletion of the old installation. On a Windows machine, more than one version of R can be installed at a time. If desired, uninstall the older version via Start > Control Panel > Uninstall a Program. On Mac platforms, the new version of R will overwrite the older version. To delete any remnants on a Mac, use the Finder to go to the /Library/Frameworks/R.frameworks/versions/ directory, and delete the folder representing the older version.

Clearly, manually updating an existing version of R is more involved than is desirable for such a sophisticated piece of software. I’m hopeful that someday this appendix will simply say “Select the Check for Updates option” to update an R installation.

G.3 Updating an R installation (Linux)

The process of updating an R installation on a Linux platform is quite different from the process used on Windows and Mac OS X machines. Additionally, it varies by Linux distribution (Debian, Red Hat, SUSE, or Ubuntu). See http://cran.r-project.org/ bin/linux for details.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]