R on Windows
Behind the scenes, rmagic assumes that a working version of R
is available on the Windows
PATH. The most recent Windows
installers for R 3.0 do not modify the
variable. This is actually a good thing because it allows you to install
multiple versions of R in whatever 32-bit or 64-bit flavors you'd like,
and they can all co-exist peacefully. That said, to get rmagic
to work you'll have to put one of
them on the
PATH by hand.
The flavor of R you put on the
match the flavor of Python you are targeting. More specifically, if
you're running 32-bit Python, place a 32-bit flavor of R on the path.
The locations of these binaries will probably look something like this:
- 32-bit R:
- 64-bit R:
It's critical to go all the way down to these flavor-specific
directories since it's really
needs be available to rmagic. Why
is that? Read on.
In addition to a working R install, rmagic in
IPython 2.0 uses
the connection between Python and R. Installing
Windows is not quite as simple as it perhaps should be, and Stack
Overflow is littered with questions about failed attempts at using
After culling through several of those posts, I happened upon one that
actually had the right magic beans. The post is a little dated, so
here's a refreshed summary of the simplest path to success today:
- As described above, pick a suitable flavor of R, and put it on the
- Pull down the (unofficial)
rpy2binaries from Christhoph Gohlke's treasure trove. Make sure you pick the right Python version of the binaries to match your Python flavor, including Python version number.
- Install those binaries into whatever Python environment you intend to use. (Did you know you can install binary packages into any Python environment, even those not in the Windows registry? That includes an Anaconda install.)
- Create an environment variable called
R_HOME, and point it to the base R install directory. If your paths look like those above, that would be
"C:\Program Files\R\R-3.0.3"or whatever matches your R version.
- Create an environment variable
R_USER, and set it to your Windows username. This looks to be in line with recent discussion on the R development issues list.
Once you've done all that, open up a fresh command prompt and verify that all your environment changes were correctly set. Then fire up IPython notebook, issue
in a cell, and the rest of the guidance in the IPython documentation should then apply.
Unfortunately, it's not necessarily all roses after that. There are still issues with getting some information back and forth across the R-Python interface in pristine format. Sometimes the output from R commands doesn't completely make it into the notebook and ends up being printed in the command shell window from which the notebook is running. But aside from a few minor inconveniences, it doesn't look like there are any real errors happening.