How do you locate R's directory for rpy2?

Asked 3 months ago, Updated 3 months ago, 9 views

Run Environment: anaconda3-jupyter notebook
Primary Library: rpy23.7

I have a question about a library called rpy2 for using R in python. I succeeded in using R using rpy2 in python environment.
One question is, as the title states, how does rpy2 identify R's directory?For example, if I move the directory location of R, will rpy2 not work?
Also, is there a way to display the PATH to the directory of R referenced by rpy2?

Actually, when I installed R itself, I used the official R and anaconda-navigator to install both R under conda environment before.Then, when I tried to install a new library of R (hereinafter referred to as X) under conda environment and use rpy2 under python environment, I found an error saying that X was not found.
So I drag-and-drop X from the Conda environment directory to the directory containing the library of R from the R formula, and it worked.
In other words, rpy2 was referring to the R that was installed from the R formula.

python r jupyter-notebook

2022-09-30 13:52

1 Answers

I don't actually use R or Python, so I just looked it up a little bit, but
Typically, you use the environment variable PATH to specify where to install the command.

Using R from Python

Access R from Python via rpy2.
I needed to set the environment variable, but I don't know which one is actually needed.
It's not particularly harmful, so I think you can set it up for now.

  • Add a directory containing R.dll to the PATH variable
  • Add working space directory for R by adding new R_HOME variable
  • Add username by adding new R_USER variable

Setting and checking environment variables is very common, so please check it yourself or refer to the following posts.(Although the language is different, the application should work in terms of "how to set environment variables in Windows")

How to specify the php that Ravel uses

2022-09-30 13:52

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.