Automagic settings for Windows

Laurent Gautier avatarLaurent Gautier created an issue

Paul listed the steps on the mailing-list:

1) Add the path to R.dll to my PATH variable (I went to the 32-bit directory) 2) Add an environment variable R_HOME (C:\Program Files\R\R-2.12.1 for me) 3) Add an environment variable R_USER (simply my username in Windows).

Modifications to rpy/init.py could help make a default work if those variables are not set (the rule being: if the variable is defined use it's value, use a default-that-just-works otherwise).

Comments (9)

  1. Brad Reisfeld

    I outlined some install tips in the file INSTALL_WINDOWS. These tips include the user actions needed to make rpy2 fully functional.

    I am not sure how this enhancement could be made automatic in the init file. How do we decide on an appropriate value for R_USER? If the user has more than one installation of R, how do we choose R_HOME and set the PATH appropriately?

    Is it okay to use a sensible value for R_USER and simply use the first instance of R that is found in the filesystem for R_HOME and PATH?

    Ideas?

  2. Laurent Gautier
    • changed status to open

    The instructions in the file look very much like possible default values to me.

    The purpose of the default value would be to use something sensible (and the latest instance of R would be a possible such value). Should users enter more complex situations (several versions of R and choose which one to use), there is still be possibility to set the variable.

    May be a practical example will make this clearer. The R executable does not need those variables to run properly and uses default values, yet if they are set they will be taken into consideration. Rpy2 merely start an embedded R engine (embedded in Python).

    If R_USER should be your user name:

    import os
    
    R_USER = os.getenv("R_USER")
    if R_USER is None:
        import win32api
        R_USER = win32api.GetUserName()
    

    In other words, the simple cases should be simple on a user standpoint. Even if we can't make the complex cases simpler for now, this would already be an improvement... or so I think (I am not using rpy2 with Windows after all). May be others could comment ?

    Now this was the easy part. Now those information should be ready before R starts, and R behaviour at startup varies across platforms: http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html

    This is an example of why Windows support is lagging behind (one would need to work in it)

  3. Brad Reisfeld

    Perhaps a script to could be written that is not part of rpy2 per se, that sets up all of the appropriate R-related environmental variables, registry entries, etc. I don't know enough about Python's distribution tools yet, but I presume that this script could be called during the invocation of 'python setup.py install'.

    Thoughts?

  4. Brad Reisfeld

    I agree that the R-related values should be checked at runtime; however, I think that they should be SET at install time. I don't really like the idea of having the init.py trying to change environmental variables every time I import rpy2.

    Also, I didn't really mean that the script should not be part of rpy2; I just meant that I don't know if it needs to be deeply coupled to the system. I am attaching a first shot at a script to check and set the R-related variables on win32. It is not yet well tested; I hope to do more testing shortly. In principle, this functionality could be part of setup.py as a postinstall step. I am also attaching a file that gives an idea as to what that might look like. This updated setup.py has not been tested at all.

  5. Laurent Gautier

    Environment variables can defined at the system level (default for anyone on the system), user level (default for the user), or process level.

    At the level of the program, here Python-using-rpy2, if the variables are not defined at the system or user level they are defined according to default generated from rules (e.g., the R_USER is the username the session is running under).

    I'd like to point out that this is the way R is operating on Linux for example: a wrapper shell script will define variables local to the session.

    On the other hand, I'd think that modifying the registry when installing rpy2 in a way that will potentially influence the way R is running is (much) less clean.

  6. Anton Sedov

    I think there is an error in set_Rvars, because reg_vars = self._get_reg_vars() called with out one argument, which is needed def _get_reg_vars(self, hive, key=R_KEY):

  7. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.