1. http://darrenjw.wordpress.com/2012/11/10/keeping-r-up-to-date-on-ubuntu-linux/
1 | sudo su |
2 | echo "deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu precise/" >> /etc/apt/sources.list |
3 | apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 |
4 | apt-get update |
5 | apt-get upgrade |
In this entry in a small series of tips for the use of the R statistical analysis and computing tool, we look at how to keep your addon packages up-to-date.
One of the great strengths of R is the many packages available. All the new approaches, as well as some of the best implementations of your old favorites are there. But it can also be a little daunting, and so theCRAN task views are often the best way to get started and download a reasonable “bundle” of packages for your analysis.
First we need a place to store the packages. On Linux (and other Unix-like systems) I use the file
~/.Renviron
to set the R_LIBS
variable to where I want the files:## R environment R_LIBS="~/R"
On Windows, I set the same variable for the user account. Don’t forget to create the directory.
Now your can start R and install the CRAN task view package:
> install.packages("ctv")
Then I have a few things in my
~/.Rprofile
startup file. The previous command probably prompted you for a download mirror which is annoying, so let’s exit R and edit the startup file to contain:## Default CRAN mirror local({r <- cran.uk.r-project.org="" ctv="" getoption="" http:="" libraries="" options="" pre="" quietly="TRUE)" r="" repos="r)})" require="" utils="">Then I define three functions. The first is to install the views I need. I like to try new things, so my list is long. Edit it to suit your needs:install.myviews <- achinelearning="" aturallanguageprocessing="" ayesian="" ctv="" dependencies="c(" epends="" function="" gr="" ighperformancecomputing="" imeseries="" install.views="" lib="Sys.getenv(" luster="" my.views="c(" obust="" ocialsciences="" patial="" pre="" quietly="TRUE)" raphics="" require="" uggests="" ultivariate="" urvival="" views="my.views,">->Try it out! Save the file, start R, and typeinstall.myviews()
at the prompt. If your list is as long as mine, then this may take some time and you may get some warnings and errors. We might add a tip on these later, but the main reason for the errors is probably that you are missing the development files for external libraries (or that R just can’t find it).Now that we have finally got them, we need to make sure they are up-to-date. I add two functions to~/.Rprofile
:update.local <- achinelearning="" ask="FALSE)" aturallanguageprocessing="" ayesian="" ctv="" function="" gr="" ighperformancecomputing="" imeseries="" lib.loc="Sys.getenv(" luster="" my.views="c(" obust="" ocialsciences="" patial="" pre="" quietly="TRUE)" raphics="" require="" ultivariate="" update.myviews="" update.packages="" update.views="" urvival="" views="my.views,">->The first allows me to easily update all my locally installed libraries (not just these installed from views). The second updates my views which is useful when the view definitions change (rarely, but it happens as the recommended packages evolve).Now I can of course update from the R command prompt usingupdate.local()
orupdate.myviews()
. But that is not the main benefit. I can now update directly from the shell command line using commands like:echo "update.local()" > /tmp/r.cmd R CMD BATCH /tmp/r.cmd /tmp/r.outThe beauty of this is that I can add it to my->crontab(5)
and have it run automatically every night or every week as I feel I need it. This way I always have the latest versions installed.
没有评论:
发表评论