[R] vector in filename

Simon Blomberg s.blomberg1 at uq.edu.au
Fri Apr 18 03:28:09 CEST 2008


How about this:

x <- 1
y <- 1
mmax <- 10

my.files <- paste("foo", x:mmax, ".png", sep="")

for (i in my.files) {
	png(filename=i, pointsize=20, width=600, height=600, units="px",
	bg="#eaedd5")
	plot(x, y)
	dev.off()
	x <- x+1
	y <- y+1
}

Normally I would avoid for loops, but I think this application is a
legitimate use.

Cheers,

Simon.

On Fri, 2008-04-18 at 03:05 +0200, [Ricardo Rodriguez] Your XEN ICT Team
wrote:
> Hi,
> 
> I am trying to generate a group of graphics with an iteration. Some 
> thing like this...
> 
> x=1
> y=1
> max=10
> myfiles <- paste("foo", x:max, ".png", sep="")
> while (x =< max)
>     {
>         png(file=myfiles, pointsize = 20, width = 600, height = 600, 
> units = "px", bg="#eaedd5")
>         plot(x,y)
>         dev.off()   
>         x=x+1
>         y=y+1
>     }
> 
> I am getting only one *.png file with the name of the first position in 
> myfiles and the content of the last graphic in the iteration. Please, 
> could you tell me if it is possible to iterate file= in any other way?
> 
> Thanks!
> 
> Ricardo
> 
> 
-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.



More information about the R-help mailing list