0

Can anyone tell me how to use 'try' command for a block of commands? Right now I'm using try for each command like this:

try(m<-MAplot(genes(cuff),args[1],args[2]))

try(png('MA_plot.png'))

try(m)

try(dev.off ())

try(print("MA_plot"))

EDIT:

try({
disp<-dispersionPlot(genes(cuff))
png('dispersion_plot.png')
disp
dev.off ()
print("dispersion_plot")



genes.scv<-fpkmSCVPlot(genes(cuff))
png('SCV_plot.png')
genes.scv
dev.off ()
print("SCV_plot")



dens<-csDensity(genes(cuff))
png('density_plot.png')
dens
dev.off ()
print("density_plot")

})

With this also I'm not getting plots..

1 Answers1

2

You can simple wrap multiple expressions using {} (curly braces). But remember why are you trying to use try and define your purpose clearly.

options(show.error.messages = FALSE)

To save a plot, 1st you need to create the graphics with png() and then plot the plot (while your code has flipped it hence didn't work)

Updated answer to save multiple plots:

try({
  png('dispersion_plot.png');

  disp<-plot(1:100);
  disp;
  dev.off();
  print("disersion_plot");

  cat('success 1');

  png('SCV_plot.png')

  genes.scv<-plot(100:1000)
  genes.scv
  dev.off ()
  print("SCV_plot")

  cat('success 2');

})
amrrs
  • 5,925
  • 1
  • 14
  • 27