Search code examples
pythonrsystemarcpy

Passing Arcpy environment variable to R from R script


I am working with an R script and am trying to pass an environment variable from Python into a variable that I can work with in R.

I have written a very simple python script which gets the variable I am looking for - when run as a standalone Python script it prints the path fine. Here is the very simple Python script saved as pathgetter.py:

import arcpy
print(arcpy.env.scratchFolder)

I then call this Python script in my R script with the following line:

tmp <- system("python -c 'C:/coa/script_tool/pathgetter.py'", intern=TRUE)

However, the variable that is stored in R is character(0). I would like the tmp variable in R to contain the path that is printed in the Python script. Does anyone have any suggestions for changes?


Solution

  • For me, this worked:

    tmp <- system('python C:/coa/script_tool/pathgetter.py', intern=TRUE)