I have a python script that has kindly been developed by one of our architects here. I would like to execute it in R using the Reticulate package. The script acts like an API to one of our systems. I call it on my machine providing it with a number and it spits out a JSON file for me.
I can see from looking at the documentation that it is possible to run the script using py_run_file(file). I am able to use this to run the script but it fails when I add arguments saying it does not know where the file is. It all works perfectly via the command prompt and the file can be found when i don't include the arguments.
I am aware I could just wrap the cmd prompt in R to execute the script via python but was wondering if its possible to just submit the command to Reticulate and get back the results. Below is a pseudo-code example
library(reticulate)
file = 'C:/Users/foo/Documents/util/account_number.py -n 9998877'
py_run_file(file)
Error in py_run_file_impl(file, local, convert) : Unable to open file 'C:/Users/foo/Documents/util/account_number.py -n 9998877' (does it exist?)
Thank you very much for your help
I have found the answer here
So i source the python script in R and have access to all its functions my environment. Applying that to my own problem above
library(reticulate)
file = 'C:/Users/foo/Documents/util/account_number.py'
source_python(file)
search_account('9998877')
I hope other people find this useful
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With