<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;">
On Thu, 28 Feb 2008, Rainer M Krug wrote:<br> <br> <br>&gt; On 28/02/2008, Roger Bivand &lt;<a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a>&gt; wrote:<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; Glynn Clements wrote:<br>
 &gt;&gt;&gt;<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Rainer M Krug wrote:<br> &gt;&gt;&gt;<br> &gt;&gt;&gt;&gt; Sorry for crossposting, but I think this can be of interest for GRASS<br> &gt;&gt; and<br> &gt;&gt;&gt;&gt; R<br> &gt;&gt;&gt;&gt; users.<br>
 &gt;&gt;&gt;&gt;<br> &gt;&gt;&gt;&gt; I am planning to write a package to make the use of GRASS from R<br> &gt;&gt; easier.<br> &gt;&gt;&gt;&gt; The<br> &gt;&gt;&gt;&gt; idea is to wrap the system call to execute the GRASS command into an R<br>
 &gt;&gt;&gt;&gt; command of the same name.<br> &gt;&gt;&gt;&gt; e.g:<br> &gt;&gt;&gt;&gt; r.to.vect &lt;- function(..., intern=TRUE, ignore.stderr=FALSE)<br> &gt;&gt;&gt;&gt;&nbsp;&nbsp; {<br> &gt;&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; comm &lt;- paste( &quot;r.to.vect &quot;, ..., sep=&quot;&quot; )<br>
 &gt;&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; print(comm)<br> &gt;&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; system( comm, intern=intern, ignore.stderr=ignore.stderr )<br> &gt;&gt;&gt;&gt;&nbsp;&nbsp; }<br> &gt;&gt;&gt;&gt;<br> &gt;&gt;&gt;&gt; My questions are:<br> &gt;&gt;&gt;&gt;<br>
 &gt;&gt;&gt;&gt; 1) Is this a good way of doing it, or is giving a named list to the<br> &gt;&gt;&gt;&gt; function<br> &gt;&gt;&gt;&gt; more usefull?<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; If R provides a way to pass individual arguments (argc/argv), use that<br>
 &gt;&gt;&gt; instead of contructing a shell command as a string. Otherwise, you are<br> &gt;&gt;&gt; likely to run into problems with shell metacharacters in argument<br> &gt;&gt;&gt; values.<br> &gt;&gt;&gt;<br> &gt;&gt;<br>
 &gt;&gt;&gt; (Replying in Nabble because Rainer&#39;s posting has been swallowed by<br> &gt;&gt;&gt; threading everywhere else)<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; This is the key sympton, seen recently in a similar interface to SAGA,<br>
 &gt;&gt;&gt; where the package author carelessly converted all &quot;/&quot; to &quot;\&quot; (it is only<br> &gt;&gt;&gt; on Windows), thus destroying a valid r.mapcalc-like operation.<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; It is made worse by differences between Unixen and Windows in handling<br>
 &gt;&gt;&gt; stdout and stderr, and by differences between CygWin and MSYS in what<br> &gt;&gt; the<br> &gt;&gt;&gt; GRASS commands are called in system() - MSYS wants an *.exe.<br> &gt;<br> &gt;<br> &gt; R has a mechanism to detect the OS and, and that could be used to deal with<br>
 &gt; &quot;/&quot; or &quot;\&quot; issues as well as other differences (one thing I haven&#39;t<br> &gt; considered yet as) .<br> &gt; One way of dealing with the different OS concerning stderr and stdout would<br> &gt; be using the command system() in R as it already adresses these issues (as<br>
 &gt; far as I know) and I managed to write usable wrappers around a few of the<br> &gt; grass commands, including r.mapcalc. But especially r.mapcalc required<br> &gt; manual tweaking...<br> <br> <br>It is precisely manual tweaking that gets broken ...</blockquote>
<div>&nbsp;</div>That&#39;s why I would like to avoid it...<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;<br> &gt;&gt;&gt;&gt; 2) Is there a way to obtain easily all commands from GRASS and the<br>
 &gt;&gt;&gt;&gt; parameters possible and required?<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; You can obtain a list of commands by enumerating the $GISBASE/bin and<br> &gt;&gt;&gt; $GISBASE/scripts directories. Nearly all commands support the<br>
 &gt;&gt;&gt; --interface-description switch, which outputs details of all of the<br> &gt;&gt;&gt; options in XML. There are several other switches which output the same<br> &gt;&gt;&gt; information in different formats; see the g.parser manpage for<br>
 &gt;&gt;&gt; details.<br> &gt;&gt;<br> &gt;&gt;&gt; ---<br> &gt;&gt;&gt; Actually, the interface problem for R is almost exactly the same as for<br> &gt;&gt;&gt; all the other front ends - think of R as a CLI-UI. Using XML in R to set<br>
 &gt;&gt;&gt; up commands going from R to GRASS might not be impossible, where there<br> &gt;&gt;&gt; would be only one command - do_GRASS(), taking the GRASS command as its<br> &gt;&gt;&gt; required argument, and relying on the GRASS GUI to put up a dialogue. If<br>
 &gt;&gt;&gt; there were further arguments, then they would be used in the context of<br> &gt;&gt;&gt; the requested command.<br> &gt;<br> &gt;<br> &gt; That sounds like a good approach and as a starting point - as ultimately I<br>
 &gt; would like to be able to call e.g. r.in.bin() from R instead of do_GRASS(&quot;<br> &gt; r.in.bin&quot;, ...). I am using R a lot at the moment to write ecological<br> &gt; simulation models, and to use the commands directly makes the programs much<br>
 &gt; more readable as emacs highlights the commands. I will look into xml parsers<br> &gt; under R to geth the information out of the grass command.<br> <br> <br>The workhorse has to be a do_GRASS() talking to GRASS in a standardised<br>
 way (mirroring g.parser?). Whether you then generate aliases for it taking<br> the names of the first argument is a detail, but not a trivial one. You</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 will certainly need a NAMESPACE in R, and do_GRASS() will be several<br> orders of magnitude easier to debug. </blockquote><div><br>I agree completely. But for readability, I would still like to have these wrappsers. But One could leave them for a later stage and to get do_GRASS() working.<br>
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The GRASS command names are not</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 guaranteed to be unique seen from the R side - load a contributed package<br> into the R workspace with its own g.list(), say, and which one will you<br> get?</blockquote><div>&nbsp;<br>Isn&#39;t that a general problem with using packages? There are several packages which overwrite other functions in other packages and they give a warning message when loading. But it would be nice to avoid these conflicts - one could introduce these wrappers as g.list.GRASS().<br>
As an emacs user, I would actually prefer using do.GRASS() instead of do_GRASS() - but that is a minor point. As far as I know, there are no conventions in R concerning this?<br><br>Rainer<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 Roger<br> <br><br> &gt;<br> &gt;<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; I haven&#39;t been following the GUI discussion, so wonder whether the<br> &gt;&gt;&gt; --interface-description output is cached anywhere? If not, do_GRASS()<br>
 &gt;&gt;&gt; would retrieve that first, and then try to insert given arguments, using<br> &gt;&gt;&gt; platform specific &quot;glue&quot; to move forward. Has the (excellent, by the<br> &gt;&gt; way)<br> &gt;&gt;&gt; progress on GUI provided a way of passing a &quot;bubble&quot; (say in XML) to<br>
 &gt;&gt; GRASS<br> &gt;&gt;&gt; commands, to avoid having to step around shell metacharacters? The same<br> &gt;&gt;&gt; for error handling? It feels as though g.parser will help a lot.<br> &gt;<br> &gt;<br> &gt; If the grass commands are created automatically and included&nbsp;&nbsp;into a package<br>
 &gt; (in addition to the flexible do_GRASS()), this would not be that relevant,<br> &gt; as the creation of the code only happens once (either at coding time of the<br> &gt; package or at compilation time - that would make the system much more<br>
 &gt; flexible as only GRASS commands / scripts installed be available).<br> &gt;<br> &gt; Rainer<br> &gt;<br> &gt;&gt;<br> &gt;&gt;&gt; Roger<br> &gt;&gt;<br> &gt;&gt;&gt; --<br> &gt;&gt;&gt; Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;<br>
 &gt;&gt;<br> &gt;&gt;&gt; _______________________________________________<br> &gt;&gt;&gt; grass-dev mailing list<br> &gt;&gt;<br> &gt;&gt;&gt; <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
 &gt;&gt;<br> &gt;&gt;&gt; <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br> &gt;&gt;&gt;<br> &gt;&gt;&gt;<br> &gt;&gt;<br> &gt;&gt; --<br> &gt;&gt; View this message in context:<br>
 &gt;&gt; <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> &gt;&gt; Sent from the Grass - Dev mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br>
 &gt;&gt;<br> &gt;&gt; _______________________________________________<br> &gt;&gt; grass-dev mailing list<br> &gt;&gt;<br> &gt;&gt; <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br> &gt;&gt;<br>
 &gt;&gt; <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br> &gt;&gt;<br> &gt;<br> &gt;<br> &gt;<br> &gt;<br> <br> --<br> <br>Roger Bivand<br> Economic Geography Section, Department of Economics, Norwegian School of<br>
 Economics and Business Administration, Helleveien 30, N-5045 Bergen,<br> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43<br> e-mail: <a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a><br> <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