editing R script for a toolbox

2384
6
Jump to solution
05-31-2017 01:58 AM
AnnieO_Donnell
New Contributor II

When adding an R script into a toolbox, how do you edit this? I can only delete and re-add which means I have to set up the input and output parameters each time, very time consuming, can’t debug or develop scripts this way.

0 Kudos
1 Solution

Accepted Solutions
MarjeanPobuda
Occasional Contributor

Hi Annie,

If you are referring to creating a custom geoprocessing script tool that references an R script instead of a python script, after you create your script tool and specify the desired UI set-up, you can make any needed changes to your script in RStudio. For example, I have wrapped R functionality for a scan statistic tool. As a result, I have an R script that I referenced as my script file when creating my scan statistic tool in ArcGIS. After I customized the UI and ran the tool several times, I decided to make some revisions to my original R script. I can keep ArcGIS open, and simply open the script I reference in the tool in RStudio. I am then able to make changes to my script in RStudio, save, and rerun the tool in ArcGIS. This is without needing to close any of the programs. I can continue to do this as many times as I like and even use the print() function to output messages in the tool message window to help give me feedback as I revise my script. 

Additionally, we have created a web course on the specifics of how to create script tools using the R-ArcGIS bridge and one of the sections covers updating script tools. 

https://www.esri.com/training/catalog/58b5e578b89b7e000d8bfffd/integrating-r-scripts-into-arcgis-geo... 

I hope this helps! 

View solution in original post

6 Replies
DanPatterson_Retired
MVP Emeritus

I didn't think you could add an R script directly to a toolbox.  Do you have a reference to that procedure?  I can't find anything directly linked

0 Kudos
AnnieO_Donnell
New Contributor II
DanPatterson_Retired
MVP Emeritus

show your parameters for the tool that you created as in the example images in that link.  IT seems to be like a regular tool, where you define your input parameters rather than hardcoding as per usual.

0 Kudos
AnnieO_Donnell
New Contributor II

What do you mean by "hardcoding as per usual"? Do you use python in ArcGIS? If so how do you edit/debug your python scripts in ArcGIS?

0 Kudos
DanPatterson_Retired
MVP Emeritus

the toolbox section in the link you posted, how did you set up the parameters.

For python code, the arcpy module allows you to get parameters (ie arcpy.GetParameterAsText) and the toolbox allows the parameter inputs to be selected when the tool is run, rather than hardcoded in the script. That is what I am referring to.  As for editing python scripts... I use several IDEs but I don't use r enough.  The continuum anaconda distribution of python also has Rstudio but it isn't included in the esri version, but I use Spyder from it for python.  The image is for python 3.6 and r, but I can't remember of esri's package included studio or not

Addendum

Forgot... Notepad++ has an plugin for both python and r check the Npp2R plugin might be useful if you already have Npp installed.  I know some people use Npp as their python ide

0 Kudos
MarjeanPobuda
Occasional Contributor

Hi Annie,

If you are referring to creating a custom geoprocessing script tool that references an R script instead of a python script, after you create your script tool and specify the desired UI set-up, you can make any needed changes to your script in RStudio. For example, I have wrapped R functionality for a scan statistic tool. As a result, I have an R script that I referenced as my script file when creating my scan statistic tool in ArcGIS. After I customized the UI and ran the tool several times, I decided to make some revisions to my original R script. I can keep ArcGIS open, and simply open the script I reference in the tool in RStudio. I am then able to make changes to my script in RStudio, save, and rerun the tool in ArcGIS. This is without needing to close any of the programs. I can continue to do this as many times as I like and even use the print() function to output messages in the tool message window to help give me feedback as I revise my script. 

Additionally, we have created a web course on the specifics of how to create script tools using the R-ArcGIS bridge and one of the sections covers updating script tools. 

https://www.esri.com/training/catalog/58b5e578b89b7e000d8bfffd/integrating-r-scripts-into-arcgis-geo... 

I hope this helps!