On Tue, 20 Jan 2009, Agustin Lobo wrote:

Hi!

I have an script in R that mostly controls the
flow of grass commands through system()
I've got stuck at:

for (k in mistat[,1]){
                system("r.mapcalc 'mancha = if(manchas.clmp==k,1,0)'")


is there any way I could pass the value of k to r.mapcalc?
I was thinking on using the shell through system, something like
for (k in mistat[,1]){
                system("set k = @1")
                system("r.mapcalc 'mancha = if(manchas.clmp==$k,1,0)'")

but do not get thru,
(perhaps I'm mixing my memories of the csh and the Bourne shell...)

Please don't cross-post - people may not be subscribed to both lists and this may break threads.

The answer is paste(), or possibly a formatting function:

cmd <- paste("r.mapcalc \'mancha = if(manchas.clmp==", formatC(k, ...),
  ",1,0)\'", sep="")
cmd
cat(cmd, "\n")
system(cmd)

if you need more control of the string going to system(); in my experience, eyeballing cmd is very helpful.

Roger


any help?

Agus



--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [email protected]

_______________________________________________
grass-stats mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-stats

Reply via email to