This code works in R very well
library(ggplot2);
tbl <- data.frame( name = c ("AAA", "BBB"), qty = c(100, 150) );
p <- ggplot(data = tbl ) + geom_bar(stat='identity', aes(x =name, y = qty));
png(file='sample.png', bg ='transparent', width = 300, height = 300 );
p;
dev.off();
But if I evaluate this code from C++ like this:
std::string code =""
"library(ggplot2);"
"tbl <- data.frame( name = c ("AAA", "BBB"), qty = c(100, 150) );"
"p <- ggplot(data = tbl ) + geom_bar(stat='identity', aes(x =name, y = qty));"
"png(file='sample.png', bg ='transparent', width = 300, height = 300 );"
"p;"
"dev.off();"
myR.parseEval( code );
The png-file is not created.
I investigated this problem and found that problem depended with ggplot2. For example simple code:
std::string code =""
"png(file='sample.png', bg ='transparent', width = 300, height = 300 );"
"plot( 1:20 );"
"dev.off();"
works well. Also file created if I use grid.circle() from "grid" packages. ggsave() function works good too.
Why ggplot can't create file through graphic device?