[R-sig-Geo] Problem with execGRASS and r.mapcalculator

Rainer M Krug r.m.krug at gmail.com
Fri Jan 28 14:38:22 CET 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

when using r.mapcalculator via execGRASS, a problem arises if in the
formula are no spaces, as the formula is then not enclosed in \". This
leads to a syntax eror, as in the second example. Would it be a problem
to enclose *all* strings given in \"? This would solve the problem.

See example below.

In addidion (example 3), a cut off error message is printed in R, but no
error raised in R itself - would there be a possibility, to evaluate if
an error occurred in GRASS? I remember a discussion about that, but I
don't seem to recall the outcome.

Cheers,

Rainer


# ERROR #####################################
> doGRASS(cmd="r.mapcalculator", parameter=list(amap="MASK",
bmap="MASK", formula="round(A + B)", outfile="test"), flags="overwrite")
[1] "r.mapcalculator --overwrite amap=MASK bmap=MASK formula=\"round(A +
B)\" outfile=test"

> execGRASS(cmd="r.mapcalculator", parameter=list(amap="MASK",
bmap="MASK", formula="round(A+B)", outfile="test"), flags="overwrite")
sh: Syntax error: "(" unexpected

# WORKING #####################################
> doGRASS(cmd="r.mapcalculator", parameter=list(amap="MASK",
bmap="MASK", formula="round(A+B)", outfile="test"), flags="overwrite")
[1] "r.mapcalculator --overwrite amap=MASK bmap=MASK formula=round(A+B)
outfile=test"

> execGRASS(cmd="r.mapcalculator", parameter=list(amap="MASK",
bmap="MASK", formula="round(A + B)", outfile="test"), flags="overwrite")
r.mapcalc "test" = "(round( "MASK" + "MASK" ))"

Done.
######################################

# example 2 #####################################
> execGRASS(cmd="r.mapcalculator", parameter=list(amap="MASK",
bmap="MASK", formula="round(A + B", outfile="test"), flags="overwrite")
r.mapcalc "test" = "(round( "MASK" + "MASK" )"
syntax error, unexpected $end, expecting ')'
Parse error
RROR: Calculating test. Try expert mode.
>

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer at krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1Cxs4ACgkQoYgNqgF2egqltACfSr15AScq4KYEi+VeurxietNG
g0oAn09CoVlvvHw2z3PeIOWb29DryZ5k
=XDGI
-----END PGP SIGNATURE-----



More information about the R-sig-Geo mailing list