Hi All,
I've been having a little trouble using R2HTML and a loop, but can't
figure
out where the problem lies, any hints gratefully received.
My code at the minute, (Which does work) is in the following:
library(R2HTML)
HTMLStart(outdir
file.path("C://Example_work","R_projects","Dynamic_creative"),filename
"RMDC_mockup",Title="Mock up for RMDC")
summary(z.out.1)
summary(s.out.1)
hist(s.out.1$qi$ev)
HTMLplot()
.
.
.
summary(z.out.3)
summary(s.out.3)
hist(s.out.3$qi$ev)
HTMLplot()
HTMLStop()
This seemed a rather long winded way of doing things to me and a simple for
loop should handle this, as later i want it to be dynamic for a number of
groups so my new code is(not working):
library(R2HTML)
HTMLStart(outdir
file.path("C://Example_work","R_projects","Dynamic_creative"),filename
"RMDC_mockup",Title="Mock up for RMDC")
for(group in 1:3){
paste("summary(z.out.", group, sep = "")
paste("summary(s.out.", group, sep = "")
paste("s.out.",group,"$qi$ev", sep = "")
HTMLplot()
}
HTMLStop()
Which returns the error
Error in dev.print(device = png, file = AbsGraphFileName, width = Width, :
no device to print from
Can anyone offer some advise here?
Mike
[[alternative HTML version deleted]]
?eval Carlos J. Gil Bellosta http://www.datanalytics.com
Michael Pearmain <mpearmain <at> google.com> writes:> > Hi All, > I've been having a little trouble using R2HTML and a loop, but can't figure > out where the problem lies, any hints gratefully received. >..> library(R2HTML) > HTMLStart(outdir > file.path("C://Example_work","R_projects","Dynamic_creative"),filename > "RMDC_mockup",Title="Mock up for RMDC") > > for(group in 1:3){ > paste("summary(z.out.", group, sep = "") > paste("summary(s.out.", group, sep = "") > paste("s.out.",group,"$qi$ev", sep = "") > HTMLplot() > } > HTMLStop()Check documentation on HTMLInsertGraph, and don't forget to change the filename in the loop, otherwise you always see the last file. Dieter
On Wed, Dec 31, 2008 at 6:12 AM, Michael Pearmain <mpearmain at google.com> wrote:> summary(z.out.1) > summary(s.out.1) > hist(s.out.1$qi$ev)... > This seemed a rather long winded way of doing things to me and a simple for > loop should handle this, as later i want it to be dynamic for a number of > groups so my new code is(not working):...> for(group in 1:3){ > paste("summary(z.out.", group, sep = "") > paste("summary(s.out.", group, sep = "") > paste("s.out.",group,"$qi$ev", sep = "")This just constructs strings. You actually want to call "summary" on the value of the variable z.out.1 etc., so constructing the string "z.out.1" or "summary(z.out.1" [sic] doesn't help. To call summary on the value of the variables, you can use: summary( get(paste("z.out",group,sep="")) ) ... But in general, if you're not doing real meta-programming, the presence of a "get" or even worse an "eval" in your code generally indicates that you're not organizing your data appropriately. Why not have z.out be a *list* of values, so you can just write for (group in 1:3) { summary(z.out[[group]]); ...} Hope this helps, -s