[R] pdf filenames in while loop

Wesley Roberts wroberts at csir.co.za
Wed Aug 20 12:37:45 CEST 2008


Dear R users,

I am a remote sensing researcher currently studying the use of LiDAR data for quantifying tree height, in particular I would like to determine the sample size needed to capture and quantify canopy height variability. To do this I have employed the use of automap(), which automatically calculates variograms including reporting the range of the variogram. The program is easy to use and I have had much success with it. However, I have run into a  slight problem. My analysis consists of 60 independent plots located in our study area and I wish to run the variogram analyses for each plot and then write the resulting plot to a pdf file. Given that I have 60 plots I would like to vary the name of each file based on the plot being processed, see my code below. I have tried a number of different approaches using the paste() command but cant seem to get it to work.

Currently, as.character does not seem to solve the problem

pdf(file="as.character(paste(f.mat[a])).pdf")

alternatively I could write out to JPEG but I would rather not take that approach or I could write all pdf plots to one file but I am not sure how to do this.

Could someone suggest a solution?

I am using R version 2.7.1 (2008-06-23) on Ubuntu 7.10.

Many thanks,
Wesley





library(gstat)
library(automap)

## List of files to be used in the while loop

files <- read.table("files.txt")
f.mat <- as.matrix(files)

## start loop here with a as the control

a=1
while(a <= 60)
{

	d <- read.csv(paste(f.mat[a]), header=TRUE, sep=",")
	coordinates(d) = ~dbl_1+dbl_2
	variogram = autofitVariogram(dbl_5~1,d, model = c("Sph"), fix.values=c(NA,NA,NA), verbose = FALSE)

	print(variogram)
	print(variogram$var_model$psill[1])
	print(variogram$var_model$range[2])
	p <- plot(variogram, main="Semi-variogram (Spherical Model)", sub=paste("Range: ",variogram$var_model$range[2]))
	print(p)

	pdf(file="as.character(paste(f.mat[a])).pdf")
	plot(p, main="Semi-variogram (Spherical Model)", sub=paste("Range: ",variogram$var_model$range[2]))
	dev.off()
	a=a+1

}


Wesley Roberts MSc.
Researcher
Natural Resources and the Environment (Earth Observation)
CSIR
Tel: +27 (31) 242-2353
Fax: +27 (31) 261-1216
http://ffp.csir.co.za/

"To know the road ahead, ask those coming back."
- Chinese proverb

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.



More information about the R-help mailing list