[R-sig-Geo] spgrass6: execGRASS: make the output of the command an R object.
Roger Bivand
Roger.Bivand at nhh.no
Tue May 21 09:07:09 CEST 2013
On Mon, 20 May 2013, Paulo van Breugel wrote:
> Great, this is really helpful. You are right, and I should have seen from
> the help file, that the semicolon is not one of the supported separators.
> The odd thing is it works when running r.univar from grass directly if I
> use the table flag (-t instead of -g). But now I know I shouldn't.
With GRASS 7:
a <- execGRASS("r.univar", flags = "t", map = "elevation.dem",
separator="; ", intern = TRUE)
works, but:
a <- execGRASS("r.univar", flags = "t", map = "elevation.dem",
separator=";", intern = TRUE)
does not. The problem is that the trailing ";" on the command line to
GRASS is also the shell line terminator, so must be protected by quoting:
a <- execGRASS("r.univar", flags = "t", map = "elevation.dem",
separator="';'", intern = TRUE)
or:
a <- execGRASS("r.univar", flags = "t", map = "elevation.dem",
separator=shQuote(";"), intern = TRUE)
both work.
Roger
>
> Thanks for helping out, much appreciated!
>
> Paulo
>
>
>
>
>
> On Mon, May 20, 2013 at 7:38 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>> On Mon, 20 May 2013, Paulo van Breugel wrote:
>>
>> Hi
>>>
>>> In older version of the execGRASS function of spgrass6, setting the option
>>> intern=TRUE would make the output of the grass command a R object.
>>>
>>> Now, when I run execGRASS with the intern=TRUE, like the statement below,
>>> the output is not written to the R object.
>>>
>>> a <- execGRASS("r.univar", flags="g", map=distmod, separator=";",
>>> intern=TRUE)
>>>
>>
>> With GRASS 6.4.2:
>>
>> a <- execGRASS("r.univar", flags = "g", map = "elevation.dem", intern =
>> TRUE)
>>
>> works as before. Adding the fs= parameter causes the failure. You are
>> using GRASS 7, in which fs= is separator=. In:
>>
>> raster/r.univar/r.univar_main.**c
>>
>> only \\t, tab, space, and comma are defined as such, others seem to be
>> accepted, but ";" is not. I think that the parameter is unused anyway in
>> script-style output, but setting fs=";" certainly causes trouble.
>>
>> Try without that parameter. Your observed difference in behaviour is not
>> intended from the R side, and is caused by odd behaviour and interaction
>> between parameters on the GRASS side in this GRASS module for your
>> parameter settings. Other GRASS modules, and r.univar with different fs=
>> settings, work as expected on Unix platforms, but under Windows, legacy
>> execution is enforced anyway.
>>
>> Hope this clarifies,
>>
>> Roger
>>
>>
>>> The object 'a' is created, but it is empty (character(0)). However, when I
>>> set legacyExec=TRUE (like below), the object 'a' is created with the grass
>>> r.univar output.
>>>
>>> a <- execGRASS("r.univar", flags="g", map=distmod, separator=";",
>>> legacyExec=TRUE, intern=TRUE)
>>>
>>> Is this the intended behaviour (i.e., did I miss something in the help
>>> file)?
>>>
>>> I am running R version 3.0.1 (2013-05-16), on Ubuntu 13.04 64-bit
>>>
>>> Paulo
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________**_________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>>
>>>
>> --
>> Roger Bivand
>> Department of Economics, NHH Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
>>
>>
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list