6

I have a 3rd party python geoprocessing script that requires rpy2, and thus also . What is the best way to get these working together?

Using R with ArcGIS Desktop says the most useful option for using R with ArcGIS is via the Geospatial Modelling Environment but as near as I can tell GME doesn't use rpy2. The script I'd like to use is not that large, but I didn't write it and don't want to port it to a different module. I don't understand the workings well enough to be confident I could do so without making a mistake.

3

The script should work if you have R and rpy2 installed properly. First install R, then rpy2, and be sure that you update your PATH with the rpy2 location.

See: http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html#installation

Depending how explicit the third-party script is in importing the rpy2 module you may need to set the RHOME path thusly:

from rpy_options import set_options
set_options(RHOME='C:\\Program Files\\R\\R-2.13.1\\')
  • Could you elaborate more on how you managed to install rpy2? Getting errors during installation. – R.K. Sep 16 '12 at 3:47
2

Installing rpy2 in windows can be rather complex. Here are the instructions that worked for me:

1. Install R
------------
http://cran.r-project.org/bin/windows/base/


2. Install Rtools
-----------------
http://cran.r-project.org/bin/windows/Rtools/


3. Define environmental variables
---------------------------------
Control Panel | Advanced tab | Environmental Variables

define the following: RHOME, R_HOME, R_USER

examples
~~~~~~~~ 
RHOME: C:\Program Files\R\R-2.13.1
R_HOME: C:\Program Files\R\R-2.13.1
R_USER: C:\Users\username\Documents


4. Append path to R (and Rtools) executable(s) to PATH
------------------------------------------------------
Control Panel | Advanced tab | Environmental Variables

example paths: C:\Program Files\R\R-2.13.1\bin\i386; C:\Rtools\bin


5. Build rpy2
-------------
1. Download and execute the binary executable 

or 

2. Download the source and build:

In the rpy2 folder...

python setup.py build --force -c mingw32
python setup.py install

Adapted from https://bitbucket.org/lgautier/rpy2/pull-request/3/added-some-win32-install-instructions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.