I'm having a problem running two successive python scripts in a single R script that calls the reticulate function. When I run them separately, it works perfectly. Am I missing something? Do I need some sort of function that closes the previous py_run before executing the second one? Note that I am working with the ArcGIS 'arcpy' tools.
Here is an example. If I run this in an Rstudio session:
use_python("C:/Python27/ArcGISx6410.7/python.exe", required = T)
import("arcpy")
import("os")
import("glob")
import("re")
import("math")
pythonRun1 = paste0("modelName = ", "'", modelName, "'")
py_run_string(pythonRun1)
py_run_file("C:/GIS/Bathymetry_UdeM/Radial_Linear_Mean_R/Output/Workflow/InterpolateResults.py")
and then this in a second Rstudio session:
use_python("C:/Python27/ArcGISx6410.7/python.exe", required = T)
import("arcpy")
import("arcpy.sa")
import("os")
import("glob")
import("re")
import("math")
pythonRun2 = paste0("modelName = ", "'", modelName, "'")
py_run_string(pythonRun2)
py_run_file("C:/GIS/Bathymetry_UdeM/Radial_Linear_Mean_R/Output/Workflow/FocalMean.py")
it works perfectly. But when I'm trying to successively execute these two code blocks:
use_python("C:/Python27/ArcGISx6410.7/python.exe", required = T)
import("arcpy")
import("os")
import("glob")
import("re")
import("math")
pythonRun1 = paste0("modelName = ", "'", modelName, "'")
py_run_string(pythonRun1)
py_run_file("C:/GIS/Bathymetry_UdeM/Radial_Linear_Mean_R/Output/Workflow/InterpolateResults.py")
#########################################################################################################
use_python("C:/Python27/ArcGISx6410.7/python.exe", required = T)
import("arcpy")
import("arcpy.sa")
import("os")
import("glob")
import("re")
import("math")
pythonRun2 = paste0("modelName = ", "'", modelName, "'")
py_run_string(pythonRun2)
py_run_file("C:/GIS/Bathymetry_UdeM/Radial_Linear_Mean_R/Output/Workflow/FocalMean.py")
I get noData as my final output. The second portion of the script does not callback any error technically speaking, but the code does not execute what it is supposed to.
Does anyone have an idea as to what may cause the difference between these two methods (i.e., separate and successive py_run execution)?
Thanks everyone!