I am trying to use R in combination with Python with rpy2. More specifically, I am trying to use some code written by someone else that uses rpy2. I think the code that uses rpy2 is:
import rpy2.robjects as robjects
integrated_result = 0
r1=robjects.r
r1.source("integrate_result.R")
integrated_result = r1.integrate_result(filename_list = mask)
"integrate_result.R" starts with "library(BayesFactor)" and contains one function called "integrate_result". When I try to run it, I get the following error:
R[write to console]: Error in library(BayesFactor) : there is no package called 'BayesFactor'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\rpy2\rinterface_lib\memorymanagement.py", line 51, in rmemory
yield pt
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\rpy2\rinterface.py", line 680, in __call__
raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error in library(BayesFactor) : there is no package called 'BayesFactor'
When I use R itself the package is installed. I have also tried to install it using rpy2 by using the following:
>>> import rpy2.robjects.packages as r
>>> utils = r.importr("utils")
>>> package_name = "BayesFactor"
>>> utils.install_packages(package_name)
R[write to console]: Installing package into 'C:/Users/XYZ/Documents/R/win-library/3.6'
(as 'lib' is unspecified)
--- Please select a CRAN mirror for use in this session ---
R[write to console]: trying URL 'https://mirror.dogado.de/cran/bin/windows/contrib/3.6/BayesFactor_0.9.12-4.2.zip'
R[write to console]: Content type 'application/zip'
R[write to console]: length 5099855 bytes (4.9 MB)
R[write to console]: downloaded 4.9 MB
package 'BayesFactor' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\XYZ\AppData\Local\Temp\RtmpqiHnHK\downloaded_packages
<rpy2.rinterface_lib.sexp.NULLType object at 0x00000153A91A5F88> [RTYPES.NILSXP]
Here is the output of rpy2.situation:
python -m rpy2.situation
rpy2 version:
3.4.3
Python version:
3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
Looking for R's HOME:
Environment variable R_HOME: None
InstallPath in the registry: C:\Program Files\R\R-3.6.3
Environment variable R_USER: None
Environment variable R_LIBS_USER: None
R version:
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
In the PATH:
Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
'sh' is not recognized as an internal or external command,
operable program or batch file.
Warning: Unable to get R compilation flags.
Does anyone have any ideas?