Monday, February 6, 2012

R and Rserve on Windows

This is easy if your system is 32-bit.  If it is 64 bit you need to make sure you are using 32-bit R because the R serve binary is 32 bit!
  1. Install the windows R binary package (accepting the defaults)
  2. Put the R bin directory on your path (right click computer  Advanced Properties  Environment Variables).  
    • For a 32-bit Windows install you should use a path like this:  C:\Program Files\R\R-2.14.1\bin
    • For a 64-bit Windows install you need to link to the i386 folder: C:\Program Files\R\R-2.14.1\bin\i386
  3. Fire up R from the cmd line (make sure that it is the 32 bit R, even if you are on a 64-bit computer) and execute the command: install.packages("Rserve") -- note to where it installs Rserve.
  4. Copy the binaries Rserve.exe and Rserve_d.exe to your R bin directory referenced aboved.
  5. Fire up a new cmd line and run the command: "R CMD Rserve' and configure the firewall popup to allow rserve to work.
  6. You know if everything is working if you can execute this code inside of irb (depends on rserve/simpler [gem install rserve-simpler]):
    • require 'rserve/simpler/R'
  7. Remember to start rserve from a separate commandline window before running any other code.  Also remember that you only get one connection in windows... so make it count.