private void CloseGraphicsDevice()
{
CommandRequest grpcmd = new CommandRequest();
//09Jun2015 here if(dev.cur()[[1]] == 2) dev.off() means that if device 2 is active then close it.
//that is, only if device number 2 (which is PNG in our case) is set then only try closing the current graphic device.
// graphic device 1 is always default graphic device which cannot be closed. You get error if you do so.
grpcmd.CommandSyntax = "if(dev.cur()[[1]] == 2) dev.off()";//09Jun2015 "dev.off()"; // "graphic.off()"; //
analytics.ExecuteR(grpcmd, false, false);
}