[R] awkward behavior with densityplot function

John Sanabria john.sanabria at ece.uprm.edu
Wed Aug 27 01:07:45 CEST 2008


Hi,

I have the following script:
---- t.R ---
grafica <- function() {
   v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',')
   x <- as.ts(v$active)
   bitmap(file="output.png")
   densityplot(~x,col='blue',main='Density Plot')
   dev.off()
}
grafica()
---- t.R ---

When I "sourced" it from R prompt, it quietly runs. However the 
"output.png" generated contains any visible data. I said that, because 
the file is created and it has 2062 bytes.
--- execution ---
 > library(lattice)
 > source(file="t.R")
 >
--- execution ---

Now, if I sequentially run the lines above in the R prompt, the 
"output.png" file contains a graphical representation of the data.
--- execution 2 ----
 > v <- read.csv('preprocessed/komolongma.ece.uprm.edu.active',sep=',')
 > x <- as.ts(v$active)
 > bitmap(file="output.png")
 > densityplot(~x,col='blue',main='Density Plot')
 > dev.off()
---- execution 2 ---

What is wrong with the densityplot function that produces any output 
when is invoked from a script?
Someone has a script invoking the densityplot function?

Thanks a lot for your help.



More information about the R-help mailing list