Configuring R
Using html
Help Facility
Linux users of R version 2.10 and later may want to take advantage of the new dynamic
html
rendering of help pages. The
konqueror
browser under
KDE
is efficient to use for this purpose, and can be told to open new help windows as new tabs on the existing
konqueror
invocation. That way you can switch back and forth between help pages for different functions. To set this up with the
chromium-browser
for example, put the following lines in your
~/.Rprofile
file:
options(help_type='html', browser='chromium-browser')
RStudio
is probably a better choice however.
Other R Profile Options
To use the
chromium-browser (sudo apt-get install chromium-browser)
and to specify a nearby
CRAN
repository and take control of where downloaded packages are installed, put the following in
~/.Rprofile
options(help_type='html', browser='chromium-browser', repos='http://cran.rstudio.com', lib='/usr/local/lib/R/site-library')
Note that the
lib
option does not always take, and certain things you run in R can redefine the library path. To be certain of where packages are installed, do something like
install.packages(...., repos='http://cran.rstudio.com', lib='/usr/local/lib/R/site-library')
You may want to put the following code in
~/.Rprofile
so that you can install one or more packages using e.g.
installPac(c('rms','quantreg'))
and likewise so it's easy to update all packages using
updatePac()
installPac <- function(p) install.packages(p, repos='http://cran.rstudio.com', lib='/usr/local/lib/R/site-library')
updatePac <- function(checkBuilt=FALSE, ...) update.packages(repos='http://cran.rstudio.com', instlib='/usr/local/lib/R/site-library', checkBuilt=checkBuilt, ...)
If you run R through RStudio put the following line in
~/.bashrc
so you can invoke it from the command
rstudio
alias rstudio="/usr/lib/rstudio/bin/rdesktop"
Setup for knitr
See
KnitrHowto for commands to put in
~/.Rprofile
to make it easy to get publication-quality
knitr
output (or use the
knitrSet
function in the
Hmisc
package)
Here's an example
.Rprofile - save it to your home directory (in Windows 7 this is your
Documents
directory if at the Windows command prompt, i.e.,
c:\Users\yourname\Documents
, otherwise in Explorer this is your home directory
My Documents
) as ".Rprofile" (the dot "." is required). Or run the following:
setwd('~/')
download.file('http://biostat.mc.vanderbilt.edu/wiki/pub/Main/RConfiguration/Rprofile', '.Rprofile')
Sourcing code from a website.
You can source code from a website using source("url"). However, if the url has the secure thing, https, it won't work. One way to overcome this is to install a package called RCurl which implements curl. Then you can do this:
Setup for Windows users for wget
Note: The version of of
getRs
in
.Rprofile
posted 2015-04-21 does not need
wget
.
sourceHttps <- function(url){
library(RCurl)
eval(expr = parse(text = getURL(url)))}
It is also convenient to use method='wget' (in download.file, url.show, etc.). To do this you must have wget installed. Go
here. Right click on
wget.exe
and save it in your normal Downloads area. Open Windows Explorer, go to Downloads, right click and hit Copy. Go to Computer ... OS (C:) ... Windows ... System32, right click, hit Paste. Approve the use of administrator privileges, then save wget.exe in System32. This will put wget.exe in the system path for use with R.
Setup wget for Macintosh OSX users
Mac OS X 10.10 Yosemite does not come with the command line utility wget installed. The web site
http://coolestguidesontheplanet.com/install-and-configure-wget-on-os-x/ contains instructions for installing wget.
These instructions are for Yosemite, but should work for other recent versions of OS X.
A more manual process is documented at
http://coolestguidesontheplanet.com/install-and-configure-wget-on-os-x/.