使用rpy.robjects时,出现了一条消息。“无法确定r home:[winerror 2]系统找不到指定的文件。
我正在使用RPY2 API在Python中实现一个简单的功能。
在VSCODE中,我设法打印一个置信区间,计算Z-Statistation调用使用PIC所示的功能创建的函数。但是在打印值之前,我会收到消息“无法确定r home:[winerror 2]系统找不到指定的文件”。同一消息出现在jupyter中,但根本不允许我打印任何内容,当调用rpy2函数时,它会获得错误的“转换'rpy2py'未针对类型'< class'class'rpy2.rinterface.sexpcluse.sexplusion'&gt定义的错误“ rpy2py”。 ’'”。
还只是导入软件包本身“导入rpy22.Robjects”会重新检索相同的消息。仅导入rpy2什么都不会出现。
我试图将rscript.exe和r.exe路径添加到系统变量中,但它们不起作用,但它们都不起作用(不确定我是否正确地做到了),试图重新安装R,无效。
关于如何解决这个问题的任何线索?
I'm implementing a simple function in python with the rpy2 API.
In VScode I manage to print a confidence interval, calculating Z-statistic calling the function created with the robjects as seen in the pic. But before the printed value I get the message "Unable to determine R home: [WinError 2] The system could not find the specified file". The same message appears in Jupyter but doesn't allow me to print anything at all, when calling a rpy2 function it get the error "Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>'".
Also just importing the package itself "import rpy2.robjects" retrives the same message. Import rpy2 alone doesn't show up anything.
I tried to add Rscript.exe and R.exe path to system variables but didn't work, neither of them (not sure if I did it properly), tried to reinstall R, didn't work.
Any clue on how to solve this?
Image of the function being used and it's output in VSCode
The output for the same function as before but in jupyter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误的原因是Windows R已更改其注册表结构,并使当前
rpy2
's r安装路径检测过时。我已经推了a pr 解决这个问题,但是与此同时,您的解决方案是您的解决方案是SETR_HOME
环境变量。这是您可以做的事情:
只要您在导入任何
os.environ ...
行之前,在导入任何rpy2
模块之前,您就应该很好。附带说明,您还可以设置
os.environ [“ r_libs_user”]
使用每个用户库路径。The cause of the error is that Windows R has changed its registry structure and it made the current
rpy2
's R install path detection obsolete. I've pushed a PR to address this issue, but for the meantime your solution is to setR_HOME
environmental variable.Here is what you could do:
As long as you run the
os.environ...
line before importing anyrpy2
module, you should be good to go.On a side note, you can also set
os.environ["R_LIBS_USER"]
to use per-user library path.