[R-sig-Geo] problem with R in a bash script
massimodisasha
massimodisasha at yahoo.it
Tue Nov 14 18:41:54 CET 2006
Hi,
i'm tryng to write a script to use
R - Grass.
i've found this tutorial :
if i execute the line directly in a bash shell it give me not problem,
but if i try to use the same code in a bash script, i've an error
message.
"with this code there aren't problem":
The code :
======================================================
#
# this line to GRASS
#
er_wind_size=9
wind_size=15
r.neighbors in=elev_meters out=avg size=$er_wind_size method=average
r.neighbors in=elev_meters out=min size=$er_wind_size method=minimum
r.neighbors in=elev_meters out=max size=$er_wind_size method=maximum
r.mapcalc "er = (avg - min)/(max - min) "
r.param.scale in=elev_meters size=$wind_size param=slope out=slope
r.param.scale in=elev_meters size=$wind_size param=profc out=profc
r.param.scale in=elev_meters size=$wind_size param=crosc out=crosc
r.param.scale in=elev_meters size=$wind_size param=minic out=minic
r.param.scale in=elev_meters size=$wind_size param=maxic out=maxic
r.param.scale in=elev_meters size=$wind_size param=longc out=longc
#
#This lines to R
#
require(spgrass6)
require(cluster)
gmeta6 <- gmeta6()
x <- readFLOAT6sp(c
("er","crosc","longc","slope","profc","minic","maxic"))
morph <- data.frame(cbind(x$er, x$crosc, x$longc, x$slope, x$profc, x
$minic, x$maxic))
morph <- data.frame(cbind(x$er, x$crosc, x$longc, x$slope/max(x
$slope), x$profc, x$minic, x$maxic))
names(morph) <- c
("er","crosc","longc","slope_n","profc","minic","maxic")
morph.clara <- clara(morph, k=5, stand=F)
x$morph_class <- morph.clara$clustering
rast.put6(x,"morph", zcol="morph_class")
===================================================
after this,...
i quit R and see the result in Grass
it's all OK !
but if itry to have the same result with a "bash script"
like this :
========================================
echo "enter elevation data"
read elevation
er_wind_size=9
wind_size=15
g.region rast=$elevation -ap
r.neighbors in=$elevation out=avg size=$er_wind_size method=average
r.neighbors in=$elevation out=min size=$er_wind_size method=minimum
r.neighbors in=$elevation out=max size=$er_wind_size method=maximum
r.mapcalc "er = (avg - min)/(max - min) "
r.param.scale in=$elevation size=$wind_size param=slope out=slope
r.param.scale in=$elevation size=$wind_size param=profc out=profc
r.param.scale in=$elevation size=$wind_size param=crosc out=crosc
r.param.scale in=$elevation size=$wind_size param=minic out=minic
r.param.scale in=$elevation size=$wind_size param=maxic out=maxic
r.param.scale in=$elevation size=$wind_size param=longc out=longc
echo "
require(spgrass6)
require(cluster)
gmeta6 <- gmeta6()
x <- readFLOAT6sp(c
("er","crosc","longc","slope","profc","minic","maxic"))
morph <- data.frame(cbind(x$er, x$crosc, x$longc, x$slope, x$profc, x
$minic, x$maxic))
names(morph) <- c
("er","crosc","longc","slope_n","profc","minic","maxic")
morph.clara <- clara(morph, k=5, stand=F)
x$morph_class <- morph.clara$clustering
rast.put6(x,"morph", zcol="morph_class")
" > R_temp
echo 'source("R_temp")' | R --vanilla --slave
g.region rast=morph -ap
d.mon x0 ; d.rast morph
========================
the execution of this script give me this error :
GRASS 6.2.0RC3 (remote):~ > ./morfo.sh
enter elevation data
dtm_20m
Percent complete ... 100%
Percent complete ... 100%
Percent complete ... 100%
100%
100%
100%
100%
100%
100%
100%
Carico il pacchetto richiesto: spgrass6
Carico il pacchetto richiesto: sp
Carico il pacchetto richiesto: maptools
Carico il pacchetto richiesto: foreign
Carico il pacchetto richiesto: rgdal
Geospatial Data Abstraction Library extensions to R successfully loaded
Carico il pacchetto richiesto: cluster
Errore in seq(along = vname) : oggetto "er" non trovato
Esecuzione interrotta
============================================
have you any suggestions about this ?
regards..
Massimo.
More information about the R-sig-Geo
mailing list