I'm trying to use R to run a Python script. I'm creating an R script that calls my Python script. I need to do this from the command prompt and pass along 3 arguments (latitude, longitude, and year) in integer form. Below is my R script:
args <- commandArgs(trailingOnly = TRUE)
lat_desired = args[1]
lon_desired = args[2]
year_desired = args[3]
system('/home/ "import sys; sys.stdout.write(file(\'python_file\', \'r\').read());"; python python_file lat_desired, lon_desired, year_desired')
My python script reads the lat_desired/lon_desired/year_desired arguments and converts them to integers (shown below):
line4 > lat_desired = int(sys.argv[1])
line5 > lon_desired = int(sys.argv[2])
line6 > year_desired = int(sys.argv[3])
When I run all of this in the command prompt I get this: Error: invalid literal for int() with base 10. Any ideas on how to pass along command line arguments from my R script to my Python script?
sys.argvfrom your python script to see what it's getting.