I can get tikzDevice
to work with your code by adding dev.off()
to the end of the code block. For example:
cat("
\\documentclass{article}
\\begin{document}
<<dev = 'tikz'>>=
library(ggplot2)
d = data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c = c(7, 8, 9))
ggplot(d, aes(a, b, color = c)) + geom_point()
dev.off()
@
\\end{document}
", "test_works.Rtex")
knit("test_works.Rtex")
works fine.
I have also noticed that if calling knit()
through an active R session on the (original) code, I am left with an active tikz device ...
cat("
\\documentclass{article}
\\begin{document}
<<dev = 'tikz'>>=
library(ggplot2)
d = data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c = c(7, 8, 9))
ggplot(d, aes(a, b, color = c)) + geom_point()
@
\\end{document}
", file = "test_fails.Rtex")
knit("test_fails.Rtex")
dev.list()