Montag, 9. August 2010

Installing RApache on Mac OS X Snow Leopard

Hi Folks,
for a research project I needed to install RApache on my Mac OS X 10.6.4 (Snow Leopard) machine.

It did take some time, a lot of beeping in the video documentary, a lot of recompiles…

Here is the way to do it:

1. Install Gnu Fortran on your Mac

You need to install Gnu Fortran on your Mac, because you have to build R on your Mac to run RApache.

Fortunately, there is a nicely Mac-style installer available at
http://gcc.gnu.org/wiki/GFortranBinaries#MacOS

Go ahead and install it.

2. Install libapreq on your Mac

libapreq2 is a library for your Apache 2 installation. Download libapreq2-2.12 (or newer) here and install it via Terminal:

tar xzvf libapreq2-2.12.tar.gz
cd libapreq2-2.12
./configure 
make
sudo make install

3. Build R

Go to your favorite CRAN-mirror (Georg-August Universität Göttingen) and download the source for R, e.g. R-2.11.1.tar.gz (section source code for all platforms). Now build R. Watch out for the configure option --enable-R-shlib!

tar xzvf R-2.11.1.tar.gz

cd R-2.11.1
./configure --enable-R-shlib
make
sudo make install

4. Install RApache

Download RApache from http://biostat.mc.vanderbilt.edu/rapache/downloads.html
Install RApache with the special configure option with-apache2-apxs!

tar xzvf rapache-1.1.9.tar.gz
cd rapache-1.1.9
./configure --with-apache2-apxs=/usr/sbin/apxs
sudo make
sudo make install

5. Reconfigure your Apache

Go to your Apache configuration file:

cd /private/etc/apache2/
sudo pico httpd.conf

(if you have TextMate installed, just use sudo mate httpd.conf)

now add the line after the other LoadModule entries in the httpd.conf file

LoadModule R_module           libexec/apache2/mod_R.so

Add the following line for debugging just below

ROutputErrors

as well as (put this somewhere at the end of the conf-file:

# Prints out a nice report about R running within Apache
<Location /RApacheInfo>
    SetHandler r-info
</Location>

Save httpd.conf.
Restart Apache (open up Systempreferences, select Sharing and uncheck and check Websharing).
Now you should be able to go to

http://yourcomputer/RApacheInfo
(you find the name of your computer in System preferences -> Sharing if you click on websharing: if websharing is running, it shows you a link to your computer - use the second link)

to get a nice info about RApache running on your system.

Have fun!

Update 8/11/2011
After that you have to reinstall R from CRAN again, because your regular R install will be broken. Hmmmm, I hope this gives all you RApache-Macheads enough headstart to come up with a cleaner solution.

Mittwoch, 25. Februar 2009

Absolutely great resource

A very nice resource which helped me a lot in kickstarting my Sweave efforts is Learning to Sweave in APA Style by clementi on scribd. This is a down to earth tutorial containing a lot of good tips! See for yourself:

Learning to Sweave in APA Style

Dienstag, 6. Januar 2009

Combining R and LaTeX with Sweave

Today I did some experiments to learn how to combine R and LaTeX to create reproducible research reports. Here are my first results:

First Demo



And this is the source code:

firstDemo.Rnw

Very nice stuff for a first 60 minute session. I will come back with more examples over the next few weeks.

Freitag, 5. Dezember 2008

Some of my other R-resources

I am running this blog as a kind of learning journal, so I can look up some of the solutions I come up when I run into problems on my way to R-mastery. I have some other R-related resources which may be of interest to other R-fellas.

A much more structured resource than this blog is the REPF-wiki, where I try to provide information about using R in educational (and other social) sciences: REPF-wiki (only available in German right now).

I am also collecting R-releated links on the web using del.icio.us: you can see them in the right side column of this blog at the top.

Freitag, 28. November 2008

First and easy steps with R and Sweave

What really sold me to the idea of using Sweave and therefore (re)learning LaTeX was the idea of Reproducible Research. Charlie Geyer has put together some examples how to mix and match R and LaTeX with Sweave. Today's goal therefore is to run his examples and to see, what problems I run into :)

Allright, if you all go to the example section of Charlie's Reproducible Research Page, you will find three examples. Let's start with the first one.

To start, I created a folder ReproducibleResearch, copied my Sweave.sty file into it and created a project within Textmate by dragging the folder onto the Textmate icon in my dock. Then I created a document foo.Rnw, copied the contents of the first example into it and saved it (if you have the R, SWeave and LaTeX bundles installed, TextMate should be recognizing this *.Rnw document as a Sweave document.

Feeling lucky, I just pressed cmd-R to run this code in R.

…drumroll…

It just worked. Wow! A TextMate "Sweave, Typeset & View" window just showed me "An (sic!) Sweave Demo" by Charles J. Geyer! Complete with LaTeX typesetting, R output and even graphics. That's what I want, so this is a great start! Many kudos to Charles.

Now, let's analyse the code to see what we can rip off this example.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amscd}
\usepackage[tableposition=top]{caption}
\usepackage{ifthen}
\usepackage[utf8]{inputenc}

\begin{document}

\title{An Sweave Demo}
\author{Charles J. Geyer}
\maketitle


All right, so this is just plain LaTeX. It is a document of class article, it uses some packages, it begins the document and defines a title. Doesn't look pretty in code, but hey, this is LaTeX - you better get used to this ;)

This is a demo for using the \verb@Sweave@ command in R. To
get started make a regular \LaTeX\ file (like this one) but
give it the suffix \verb@.Rnw@ instead of \verb@.tex@ and then
turn it into a \LaTeX\ file (\verb@foo.tex@) with the (unix) command
\begin{verbatim}
R CMD Sweave foo.Rnw
\end{verbatim}
So you can do
\begin{verbatim}
latex foo
xdvi foo
\end{verbatim}
and so forth.


Now there is some text - all this \verb@sometext@ gives you a code-like text formating within normal text. \begin{verbatim} starts a code block, \end{verbatim} stops it. Pretty standard LaTeX stuff.

A few lines later it gets more interesting:

<>=
2 + 2
@


Alright, so this is a code chunk, which will be run and the output of R will be written. Very nice! Try it out and alter the 2 + 2 to something else and sweave the file again. I typed in 2 * 1024 - 35 and the result has been 2013. Easy enough.



In the next post I will digg deeper into creating graphs and doing more complex analysis reports with Sweave. For tonight, I am happy with the first results.

Freitag, 21. November 2008

Setting up Textmate to use R



After becoming frustrated using the StatET plugin for Eclipse on my Mac (sometimes the R console would start and sometimes not), I decided to use Textmate instead. Textmate allows you to install extra bundles which are plug-ins to add some new functionality to TextMate. There are two bundles relevant for R developers:
- R bundle (here)
- Latex bundle (here)
- Sweave bundle (here)

If you are running Leopard (Mac OS 10.5), the subversion client should be installed (otherwise, do so - you can find more info about this on the TextMate help pages).

To install the two bundles, invoke the following terminal spells:

mkdir -p /Library/Application\ Support/TextMate/Bundles
cd /Library/Application\ Support/TextMate/Bundles
svn co http://svn.textmate.org/trunk/Bundles/R.tmbundle
svn co http://svn.textmate.org/trunk/Bundles/Latex.tmbundle
svn co http://svn.textmate.org/trunk/Bundles/SWeave.tmbundle


Start up TextMate and now you have support for R and Sweave in TextMate (this assumes that you already have installed a copy of Latex - get the MacTeX-2008 distribution here).

Chances are that if you want to "Sweave, Typeset and View" R will choke because it does not find the necessary Sweave LaTeX style file (sweave.sty) file. If this is the case, just put a copy of sweave.sty into your working directory and everything will work wonderfully (yes, I know that this should be fixable by setting up the right search path somewhere, so if you have run into this problem and fixed it better than me, please send some enlightening commentaries!).