<br><br><div><span class="gmail_quote">On 28/02/2008, <b class="gmail_sendername">Roger Bivand</b> &lt;<a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> <br> <br> Glynn Clements wrote:<br> &gt;<br> &gt;<br> &gt; Rainer M Krug wrote:<br> &gt;<br> &gt;&gt; Sorry for crossposting, but I think this can be of interest for GRASS and<br> &gt;&gt; R<br> &gt;&gt; users.<br> &gt;&gt;<br>
 &gt;&gt; I am planning to write a package to make the use of GRASS from R easier.<br> &gt;&gt; The<br> &gt;&gt; idea is to wrap the system call to execute the GRASS command into an R<br> &gt;&gt; command of the same name.<br>
 &gt;&gt; e.g:<br> &gt;&gt; r.to.vect &lt;- function(..., intern=TRUE, ignore.stderr=FALSE)<br> &gt;&gt;&nbsp;&nbsp; {<br> &gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; comm &lt;- paste( &quot;r.to.vect &quot;, ..., sep=&quot;&quot; )<br> &gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; print(comm)<br>
 &gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; system( comm, intern=intern, ignore.stderr=ignore.stderr )<br> &gt;&gt;&nbsp;&nbsp; }<br> &gt;&gt;<br> &gt;&gt; My questions are:<br> &gt;&gt;<br> &gt;&gt; 1) Is this a good way of doing it, or is giving a named list to the<br>
 &gt;&gt; function<br> &gt;&gt; more usefull?<br> &gt;<br> &gt; If R provides a way to pass individual arguments (argc/argv), use that<br> &gt; instead of contructing a shell command as a string. Otherwise, you are<br> &gt; likely to run into problems with shell metacharacters in argument<br>
 &gt; values.<br> &gt;<br> <br>&gt; (Replying in Nabble because Rainer&#39;s posting has been swallowed by<br> &gt; threading everywhere else)<br> &gt;<br> &gt; This is the key sympton, seen recently in a similar interface to SAGA,<br>
 &gt; where the package author carelessly converted all &quot;/&quot; to &quot;\&quot; (it is only<br> &gt; on Windows), thus destroying a valid r.mapcalc-like operation.<br> &gt;<br> &gt; It is made worse by differences between Unixen and Windows in handling<br>
 &gt; stdout and stderr, and by differences between CygWin and MSYS in what the<br> &gt; GRASS commands are called in system() - MSYS wants an *.exe.</blockquote><div><br>R has a mechanism to detect the OS and, and that could be used to deal with &quot;/&quot; or &quot;\&quot; issues as well as other differences (one thing I haven&#39;t considered yet as) . <br>
</div>One way of dealing with the different OS concerning stderr and stdout would be using the command system() in R as it already adresses these issues (as far as I know) and I managed to write usable wrappers around a few of the grass commands, including r.mapcalc. But especially r.mapcalc required manual tweaking...<br>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&gt;<br> &gt;&gt; 2) Is there a way to obtain easily all commands from GRASS and the<br>
 &gt;&gt; parameters possible and required?<br> &gt;<br> &gt; You can obtain a list of commands by enumerating the $GISBASE/bin and<br> &gt; $GISBASE/scripts directories. Nearly all commands support the<br> &gt; --interface-description switch, which outputs details of all of the<br>
 &gt; options in XML. There are several other switches which output the same<br> &gt; information in different formats; see the g.parser manpage for<br> &gt; details.<br> <br>&gt; ---<br> &gt; Actually, the interface problem for R is almost exactly the same as for<br>
 &gt; all the other front ends - think of R as a CLI-UI. Using XML in R to set<br> &gt; up commands going from R to GRASS might not be impossible, where there<br> &gt; would be only one command - do_GRASS(), taking the GRASS command as its<br>
 &gt; required argument, and relying on the GRASS GUI to put up a dialogue. If<br> &gt; there were further arguments, then they would be used in the context of<br> &gt; the requested command.</blockquote><div><br>That sounds like a good approach and as a starting point - as ultimately I would like to be able to call e.g. r.in.bin() from R instead of do_GRASS(&quot;r.in.bin&quot;, ...). I am using R a lot at the moment to write ecological simulation models, and to use the commands directly makes the programs much more readable as emacs highlights the commands. I will look into xml parsers under R to geth the information out of the grass command.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> &gt;<br> &gt; I haven&#39;t been following the GUI discussion, so wonder whether the<br>
 &gt; --interface-description output is cached anywhere? If not, do_GRASS()<br> &gt; would retrieve that first, and then try to insert given arguments, using<br> &gt; platform specific &quot;glue&quot; to move forward. Has the (excellent, by the way)<br>
 &gt; progress on GUI provided a way of passing a &quot;bubble&quot; (say in XML) to GRASS<br> &gt; commands, to avoid having to step around shell metacharacters? The same<br> &gt; for error handling? It feels as though g.parser will help a lot.</blockquote>
<div><br>If the grass commands are created automatically and included&nbsp; into a package (in addition to the flexible do_GRASS()), this would not be that relevant, as the creation of the code only happens once (either at coding time of the package or at compilation time - that would make the system much more flexible as only GRASS commands / scripts installed be available).<br>
</div><br>Rainer<br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> &gt;<br> &gt; Roger<br> <br>&gt; --<br> &gt; Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;<br>
 <br>&gt; _______________________________________________<br> &gt; grass-dev mailing list<br> <br>&gt; <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br> <br>&gt; <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>
 &gt;<br> &gt;<br> <br> --<br> View this message in context: <a href="http://www.nabble.com/Plan-to-build-Package-to-use-GRASS-from-R-tp15712877p15731306.html">http://www.nabble.com/Plan-to-build-Package-to-use-GRASS-from-R-tp15712877p15731306.html</a><br>
 Sent from the Grass - Dev mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br> <br> _______________________________________________<br> grass-dev mailing list<br> <br><a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
 <br><a href="http://lists.osgeo.org/mailman/listinfo/grass-dev">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br> </blockquote></div><br><br clear="all"><br>-- <br><br>-- <br>Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)<br>
<br>Plant Conservation Unit Department of Botany<br>University of Cape Town<br>Rondebosch 7701<br>South Africa