I was wondering how to open an R script and interact with it (for example, send strings, integers etc.). Although I have not used it before, subprocess seemed like a reasonable way to do this.
So far, I have
process = subprocess.Popen(['/path/to/Rscript --no-save path/to/script.R'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
This appears to be successful in opening script.R, however in my script I prompt the user to enter an integer and I cannot quite sort out how to do this. I have tried:
process.communicate(input=1)[0]
But I appear to be barking up the wrong tree. The subprocess closes without appearing to receive this input.
EDIT: Rpy is probably not a good alternative at this point, because users of this script will not necessarily have access to that module and its dependencies.
process.communicate(input=1)?