1

I want to use rpy2 through one of my Anaconda environments. I installed it by opening the terminal for that environment and running conda install -c r rpy2 as per these instructions. I also ran pip install rpy2 just to make sure, but got back

Requirement already satisfied: rpy2 in c:\users\rcardoso\.conda\envs\smartwatt\lib\site-packages (2.9.4)
Requirement already satisfied: six in c:\users\rcardoso\.conda\envs\smartwatt\lib\site-packages (from rpy2) (1.14.0)
Requirement already satisfied: jinja2 in c:\users\rcardoso\.conda\envs\smartwatt\lib\site-packages (from rpy2) (2.11.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\rcardoso\.conda\envs\smartwatt\lib\site-packages (from jinja2->rpy2) (1.1.1)

I want rpy2 to use my current R installation, which was not done through Anaconda and already has a number of packages installed. I tried to follow the instructions on this post for setting up the system variables. The relevant system variables ended up looking like this:

System variables

However, when I run

for row in rpy2.situation.iter_info():
    print(row)

in my Spyder iPython console, as per rpy2 documentation, it seems it's not picking up the R_HOME and R_USER environment variables, as it's returning:

Python version:
3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 22:22:21) [MSC v.1916 64 bit (AMD64)]
Looking for R's HOME:
    Environment variable R_HOME: None
    Calling `R RHOME`: C:\Users\rcardoso\.conda\envs\Smartwatt\lib\R
    InstallPath in the registry: C:\Program Files\R\R-3.6.3
R version:
    In the PATH: 
    Used to build rpy2: 3-6.0--76424
Additional directories to load R packages from:
None

What should I do so that I am able to use my current R installation (not the one which was apparently installed along with rpy2) and packages? I haven't been able to find consistent information on how to correctly install rpy2 in Windows 10 through Anaconda for my specific situation.

RicardoC
  • 109
  • 1
  • 2
  • 9

1 Answers1

0

It seems anaconda is not using your defined system variables.

From the post you have mentioned (this post), have you try setting the environments directly at your script?

import os
os.environ['R_HOME'] = r"C:\Program Files\R\R-3.6.3"
os.environ['R_USER'] = r"C:\Users\rcardoso\.conda\envs\Smartwatt\Lib\site-packages\rpy2"

There is another solution you can try: defining environment variables directly in the conda environment. Check first answer of this.