Re: [R-sig-eco] automating ações
Dear Erickson Here is the code: require(spatstat) require(foreign) require(rgeos) require(maptools) options(digits=4) dados.pol<-readShapePoly("area_de_estudo.shp")#lendo o contorno da área de estudo plot(dados.pol) dados.riq<-read.table("test_richness.txt", head=T, sep="\t") sp<-dados.riq$Cod_NC sp<-as.factor(sp) pt_X<-dados.riq$X_UTM pt_X<-as.numeric(pt_X) pt_Y<-dados.riq$Y_UTM pt_Y<-as.numeric(pt_Y) pts_M<-sp W<-as(dados.pol,"owin") ppp_zona<-ppp(pt_X,pt_Y,window=W, marks= pts_M) unitname(ppp_zona)<-"meters" rique<-as.numeric(dados.riq$riqueza) length(rique) dap<-dados.riq$DAP ppp_zona$marks=data.frame(sp=ppp_zona$marks, riqueza=rique,dap=dap) ppp_zona ppp.zona.dap<-ppp_zona ppp_zona.sp<-split(ppp_zona, f="sp") ppp_zona.sp ppp_zona.sp ppp_zona.sp<-lapply(ppp_zona.sp, function(x){x=x; x$marks=x$marks$riqueza; return(x)}) ppp_zona.sp bw.smoothppp(ppp_zona.sp[["Rino_macr"]],hmin=NULL, hmax=NULL, warn=TRUE) plot(Smooth(ppp_zona.sp[["Rino_macr"]],sigma=19.26)) dev.print(jpeg,file="Rino_macr.jpg", bg="transparent", quality=300, width = 1024, height = 768) Cheers, 2015-09-15 14:01 GMT-04:00 Kátia Emidio : > Dear all, > > I´m a beginner in using FOR in order to create a loop in R to automate > ações in it. > > I have a script, attached, and I need to perform it for all species in the > file (test_richness). The package I'm using is the SpatStat. The loop > needs to be created before the "bw.smoothppp" function (line 45), which get > the sigma value, that is used as a parameter for the "plot(Smooth...).. > and the image needs to be automatic generated as a file. > I'll appreciate any help! > Cheers, > > -- > Kátia Emídio da Silva DSc > Eng. Florestal > Manaus/AM > > > > Forestry Engineer > Manaus/AM-Brazil > -- Kátia Emídio da Silva DSc Eng. Florestal Manaus/AM Forestry Engineer Manaus/AM-Brazil [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] automating ações
Katia-- Your attached script didn't come through. as attachments are stripped by the mailing list. However, I can give you 2 generic answers. First, if your vector of species names is called SpList, and your data are in a big SpatialPointsDataFrame spdf for (SP in SpList) { spSP <- as(spdf[spdf$Species==SP,],'ppp') # subset to just that species and return as ppp object temp1 <- bw.smoothppp(spSP,...) temp2 <- nextstep(temp1) tempplot <- plot(...) # probably display or write to a file png(filename=paste(SP,'smootheddensity.png',sep='')) print(tempplot) dev.off() } # bottom for SP in SpList That structure works well for things like hitting gbif, that need to be done sequentially. It can work for your use case, but will be slow, and is considered poor R "style". In general, in R, one should not use for loops, but rather let R vectorize in line via one of the *apply functions or even more powerful tools in plyr or other packages. The "better" R style is to write a small wrapper function DoPP() that takes a species name and spatial object as parameters, performs the steps you want for each species, then returns the graph object. Then, you can use dlply() in the plyr package to apply that function to each species, and return a list of graph objects. I hope that this points you in a useful direction. Tom 2 "If you find that you're spending almost all your time on theory, start turning some attention to practical things; it will improve your theories. If you find that you're spending almost all your time on practice, start turning some attention to theoretical things; it will improve your practice." -- Donald Knuth On Tue, Sep 15, 2015 at 11:01 AM, Kátia Emidio wrote: > Dear all, > > I´m a beginner in using FOR in order to create a loop in R to automate > ações in it. > > I have a script, attached, and I need to perform it for all species in the > file (test_richness). The package I'm using is the SpatStat. The loop > needs to be created before the "bw.smoothppp" function (line 45), which get > the sigma value, that is used as a parameter for the "plot(Smooth...).. > and the image needs to be automatic generated as a file. > I'll appreciate any help! > Cheers, > > -- > Kátia Emídio da Silva DSc > Eng. Florestal > Manaus/AM > > > > Forestry Engineer > Manaus/AM-Brazil > ___ > R-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[R-sig-eco] automating ações
Dear all, I´m a beginner in using FOR in order to create a loop in R to automate ações in it. I have a script, attached, and I need to perform it for all species in the file (test_richness). The package I'm using is the SpatStat. The loop needs to be created before the "bw.smoothppp" function (line 45), which get the sigma value, that is used as a parameter for the "plot(Smooth...).. and the image needs to be automatic generated as a file. I'll appreciate any help! Cheers, -- Kátia Emídio da Silva DSc Eng. Florestal Manaus/AM Forestry Engineer Manaus/AM-Brazil ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology