<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic R- ArcGIS Tool Help in R-ArcGIS Questions</title>
    <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881926#M301</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if anyone could help me with some R- script I got from a client, and I want to integrate it to my Model Builder. I have installed R-ArcGIS bridge &amp;nbsp;and all required packages, and tested the script as standalone tool with hard-coded parameters and it works fine. The problem I have is how to create variables for the input and output parameters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get a chance, will you spend few hour to assist with the attached R script. I tried to use the in_params &amp;amp; out_params for inputs and outputs respectively, but no luck except the path to the folder.&lt;/P&gt;
&lt;P&gt;Here is what I need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inputs:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; Path to folder (which replace the hardcoded &amp;nbsp;setwd(“path”) )&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; n :&amp;nbsp; &amp;nbsp;number of random sites&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; m : contingency random sites&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dbf ( xyzx.dbf) to read the dbf file from the Shapefile, which means the Shapefile within the input folder&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;shape ( the Shapefile name)&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;prjfilename ( the projection name, which will be based on the input Shapefile)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outputs:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;shape( the output Shapefile name)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 17:22:41 GMT</pubDate>
    <dc:creator>DanielAbera</dc:creator>
    <dc:date>2024-06-28T17:22:41Z</dc:date>
    <item>
      <title>R- ArcGIS Tool Help</title>
      <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881926#M301</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if anyone could help me with some R- script I got from a client, and I want to integrate it to my Model Builder. I have installed R-ArcGIS bridge &amp;nbsp;and all required packages, and tested the script as standalone tool with hard-coded parameters and it works fine. The problem I have is how to create variables for the input and output parameters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get a chance, will you spend few hour to assist with the attached R script. I tried to use the in_params &amp;amp; out_params for inputs and outputs respectively, but no luck except the path to the folder.&lt;/P&gt;
&lt;P&gt;Here is what I need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inputs:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; Path to folder (which replace the hardcoded &amp;nbsp;setwd(“path”) )&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; n :&amp;nbsp; &amp;nbsp;number of random sites&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; m : contingency random sites&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dbf ( xyzx.dbf) to read the dbf file from the Shapefile, which means the Shapefile within the input folder&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;shape ( the Shapefile name)&lt;/LI&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;prjfilename ( the projection name, which will be based on the input Shapefile)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outputs:&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="text-indent: -.25in;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;shape( the output Shapefile name)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 17:22:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881926#M301</guid>
      <dc:creator>DanielAbera</dc:creator>
      <dc:date>2024-06-28T17:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: R- ArcGIS Tool Help</title>
      <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881927#M302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daniel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you built the corresponding Geoprocessing tool already? That's the first step -- select the data types and variables for each of the inputs and outputs you'd like to use in the tool. This process is the same as it would be with a Python script tool. In those parameters, you can define the workspace, n and m values, and the output shapefile. If you are restricting this tool to just use Shapefiles, you can just pass around a reference to the Shapefile input, the .dbf and .prj files are part of the format. So I'd pass in just the Shapefile name, then if you need for example, the path to the DBF, you can run something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;CODE&gt;&lt;SPAN class=""&gt;shape.root &amp;lt;- tools&lt;/SPAN&gt;&lt;SPAN class=""&gt;::&lt;/SPAN&gt;&lt;SPAN class=""&gt;file_path_sans_ext&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;input.shapefile&lt;/SPAN&gt;&lt;SPAN class=""&gt;) # extract name without .shp
shape.dbf &amp;lt;- paste(shape.root, '.dbf', sep='')
&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN class=""&gt;shape.prj &amp;lt;- paste(shape.root, '.prj', sep='')

&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That way, your tool will have less inputs required. Once you've created your GP script with the necessary inputs and outputs, you can pass them directly to R as shown in this vignette &lt;A class="link-titled" href="https://r-arcgis.github.io/assets/arcgisbinding-vignette.html" title="https://r-arcgis.github.io/assets/arcgisbinding-vignette.html" rel="nofollow noopener noreferrer" target="_blank"&gt;Using the R-ArcGIS Bridge: the arcgisbinding Package&lt;/A&gt;, under the "&lt;EM&gt;Wrapping R Tool Functionality" &lt;/EM&gt;section. Assign each one to a parameter, and the bridge will convert it to an appropriate type -- you only really have two things from the R side, paths as strings (shape and working directory) and integers. If you need further examples of how to build something like this, I recommend looking at the sample tools provided here:&lt;BR /&gt;&amp;nbsp; &lt;A class="link-titled" href="https://github.com/R-ArcGIS/r-sample-tools" title="https://github.com/R-ArcGIS/r-sample-tools" rel="nofollow noopener noreferrer" target="_blank"&gt;GitHub - R-ArcGIS/r-sample-tools: Sample tools illustrating R usage in geoprocessing scripts&lt;/A&gt;&amp;nbsp;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you examine those tools, you'll see the parameters they set up, and how they are pulled in on the R side in the R scripts. As is the case with Python scripts, building fully generic tools from scripts does take a little bit of work, but I think its a worthwhile investment in your skillset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Shaun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 11:08:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881927#M302</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2021-12-12T11:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: R- ArcGIS Tool Help</title>
      <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881928#M303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank shaun for the reply. But I think I figure that out. This is how I did it. Even though it is messy, it is working !!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tool_exec &amp;lt;- function(in_params, out_params)&lt;BR /&gt;{&lt;BR /&gt; # load the required packages&lt;BR /&gt; cat(paste0("\n", "Loading packages...", "\n"))&lt;BR /&gt; library(arcgisbinding)&lt;BR /&gt; arc.check_product()&lt;/P&gt;&lt;P&gt;# read input and output parameters&lt;BR /&gt;folder_path=in_params[[1]]# folder path&lt;BR /&gt;shp_name=in_params[[2]] # input shapefile name&lt;BR /&gt;n=as.integer(in_params[[3]])# write in how many random sites you want selected&lt;BR /&gt;m=as.integer(in_params[[4]])#write in how many "contingency" random sites&lt;BR /&gt;out_shp=in_params[[5]] # output shapefile name&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;setwd(folder_path)# shapefile path&lt;/P&gt;&lt;P&gt;extension &amp;lt;- ".dbf"&lt;/P&gt;&lt;P&gt;dbfFile = paste (shp_name,extension,sep="")# concatnate&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;library(spsurvey)&lt;BR /&gt;att &amp;lt;- read.dbf(dbfFile) # write in the name of your &lt;BR /&gt; # random point shapefile and add the file&lt;BR /&gt; # extension .dbf&lt;BR /&gt;att$stratum &amp;lt;- rep("Study", nrow(att)) &lt;BR /&gt;dsgn &amp;lt;- list("Study"=list(panel=c(Base=n),&lt;BR /&gt; seltype='Equal',&lt;BR /&gt; over=m))&lt;BR /&gt;set.seed(3216530) # Do not need to change. But if you keep it constant&lt;BR /&gt; #it will allow you to redo the sample and get the same sites.&lt;BR /&gt;sites &amp;lt;- grts(design=dsgn,&lt;BR /&gt; DesignID='watershed',&lt;BR /&gt; SiteBegin=1, # default so can leave out&lt;BR /&gt; type.frame='finite',&lt;BR /&gt; src.frame='shapefile', # default so can leave out&lt;BR /&gt; in.shape=shp_name,&lt;BR /&gt; att.frame=att,&lt;BR /&gt; stratum='stratum',&lt;BR /&gt; mdcaty='MDCATY', &lt;BR /&gt; shapefile=TRUE,&lt;BR /&gt; out.shape=out_shp, #Name your output shape file&lt;BR /&gt; prjfilename=shp_name) #Copy same name as in.shape&lt;BR /&gt;#Done! Go and open the new point shapefile in ArcGIS.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; cat(paste0("\n", "Done.", "\n"))&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;load_pkgs &amp;lt;- function(pkgs) {&lt;/P&gt;&lt;P&gt;new_pkgs = pkgs[(pkgs %in% installed.packages()[ ,'Package'])]&lt;BR /&gt; if (length(new_pkgs) &amp;gt; 0) install.packages(new_pkgs)&lt;BR /&gt; invisible(lapply(pkgs, function(x)&lt;BR /&gt; suppressMessages(library(x, character.only = TRUE)))&lt;BR /&gt; )&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2019 20:00:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881928#M303</guid>
      <dc:creator>DanielAbera</dc:creator>
      <dc:date>2019-08-07T20:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: R- ArcGIS Tool Help</title>
      <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881929#M304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks good! Note that the random seed might be something you want to expose as a parameter as well, if you want each iteration to be randomized. As is (hard-coded seed), this will always produce the same output for the same input.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2019 20:35:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881929#M304</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2019-08-07T20:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: R- ArcGIS Tool Help</title>
      <link>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881930#M305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good point. Thanks Shaun !!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:53:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/r-arcgis-questions/r-arcgis-tool-help/m-p/881930#M305</guid>
      <dc:creator>DanielAbera</dc:creator>
      <dc:date>2019-08-08T15:53:16Z</dc:date>
    </item>
  </channel>
</rss>

