R stuff

R (R Development Core Team, 2010) is an open-source statistical environment, and according to me the ``way to go'' for statistical computing in natural resources and ecological related problems. Indeed my opinion on the goodness of R is subjective, but you could review some little-bit less subjective comments on Salas (2008), if you wish.

  1. installing R2
    First include a mirror in the file /etc/apt/sources.list, as follows

    \framebox{
\texttt{
\textcolor{red}{\bf sudo gedit /etc/apt/sources.list}
}
}
    and in that file add

    \framebox{
\texttt{
\textcolor{red}{\bf deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu gutsy/}
}
}

    then, before of updating this, type at the terminal the following
    \framebox{
\texttt{
\textcolor{red}{\bf gpg -keyserver subkeys.pgp.net -recv-key E2A11821}
}
}

    \framebox{
\texttt{
\textcolor{red}{\bf gpg -a -export E2A11821 \vert sudo apt-key add -}
}
}

    now, we can do \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get update}
}
}

    \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get install g77}
}
} , and now to install R

    at the terminal type \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get install r-base r-base-core r-base-dev r-recommended}
}
}

  2. installing R packages from a ftp mirror
    First, I would recommend to install a Fortran compiler, as follows \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get install gfortran*}
}
} .

    Then, we need to star R or emacs, using sudo. At the terminal type \framebox{
\texttt{
\textcolor{red}{\bf sudo R}
}
} , or call emacs in the terminal using sudo, as follows \framebox{
\texttt{
\textcolor{red}{\bf sudo emacs}
}
}

    then, we proceed to install the packages. For example \framebox{
\texttt{
\textcolor{red}{\bf install.packages(''nlme'')}
}
}
    or multiple packages \framebox{
\texttt{
\textcolor{red}{\bf install.packages(c(''plotrix'', ''Hmisc'',''xtable''))}
}
}

    You can also try the following when the above do not work (here using the Hmisc as example) but directly from the terminal (nor in R) \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get install r-cran-Hmisc}
}
}

  3. Updating R packages
    \framebox{
\texttt{
\textcolor{red}{\bf update.packages()}
}
}

  4. installing R packages from a local file To install packages for R under Linux/Unix, download a .tar.gz file to /tmp, login is root, and run a command such as follows
    \framebox{
\texttt{
\textcolor{red}{\bf R CMD INSTALL /path monash\_1.0.1.tar.gz}
}
}

    where ``/path'' represents the directory where the tar.gz file is, or better inclusive can be just save that file in any folder, and open a terminal in that folder, then ``path'' is not needed in the previous syntax.

  5. list of all currently installed R packages
    \framebox{
\texttt{
\textcolor{red}{\bf rownames(installed.packages())}
}
}

  6. list of all loaded R packages in a session
    \framebox{
\texttt{
\textcolor{red}{\bf search()}
}
}

  7. How to work in R within Emacs
    The only thing that we need, is to install ESS in ubuntu, typing at the terminal
    \framebox{
\texttt{
\textcolor{red}{\bf sudo apt-get install ess}
}
}
    then, just open an .R file in Emacs and all the R options will appear.

    You can start an R session, without opening an .r file in Emacs, by opening Emacs, and then press M-x R

    You parse parts of an R source file by the following commands
    ess-eval-line (C-c C-j)
    ess-eval-line-and-go (C-c M-j)
    ess-eval-funtion (C-c C-f)
    ess-eval-function-and-go (C-c M-f)
    ess-eval-region (C-c C-r)
    ess-eval-region-and-go (C-c M-r)
    ess-eval-buffer (C-c C-b)
    ess-eval-buffer-and-go (C-c M-b)
    (all the commands start with C-c, you do an -and-go by using the metakey).
    

  8. install Rkward
    This is a nice GUI editor for R, the installation for ubuntu that worked the best for me was to download the .deb file from the CRAN website.

Webmaster: Christian E. Salas Eljatib, E-mail: christian.salas@yale.edu