if os.path.exists(file_path):
print(file_path)
# Call the R script
robjects.r(f'source("{file_path}")')
my_function = robjects.globalenv['my_function']
# Get the results as a Python object
results = my_function(r_weight)
return results
I was trying to run R script using rpy2, But I run into an issue.
Response:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/first_dose_calculator/views.py", line 34, in add_numbers
robjects.r(f'source("{file_path}")')
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/doss_test/lib/python3.8/site-packages/rpy2/robjects/__init__.py", line 451, in __call__
res = self.eval(p)
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/doss_test/lib/python3.8/site-packages/rpy2/robjects/functions.py", line 201, in __call__
return (super(SignatureTranslatedFunction, self)
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/doss_test/lib/python3.8/site-packages/rpy2/robjects/functions.py", line 124, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/doss_test/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py", line 45, in _
cdata = function(*args, **kwargs)
File "/home/vishnupriyanvs/Desktop/projects/dossing_app/dossing_app/doss_test/lib/python3.8/site-packages/rpy2/rinterface.py", line 810, in __call__
raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error: RStudio not running
I am using rpy2 3.5.1