R package lattice won't plot if run using source()

Viewed 6113

I started using the lattice graphic package but I stumbled into a problem. I hope somebody can help me out. I want to plot a histogram using the corresponding function.

Here is the file foo.r:

library("lattice")

data <- data.frame(c(1:2),c(2:3))
colnames(data) <- c("RT", "Type")

pdf("/tmp/baz.pdf")
histogram( ~ RT | factor(Type), data = data)
dev.off()

When I run this code using R --vanilla < foo.r it works all fine.

However, if I use a second file bar.r with

source("bar")

and run R --vanilla < bar.r the code produces an erroneous pdf file. Now I found out that source("bar", echo=TRUE) solves the problem. What is going on here? Is this a bug or am I missing something?

I'm using R version 2.13.1 (2011-07-08) with lattice_0.19-30

2 Answers
Related