Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing "null device" output with R in batch mode

I have a number of bash scripts which invoke R scripts for plotting things. Something like:

#!/bin/bash R --vanilla --slave <<RSCRIPT cat("Plotting $1 to $2\n") input <- read.table("$1") png("$2") plot(as.numeric(input[1,])) dev.off() RSCRIPT 

The problem is that despite --slave, the call to dev.off() prints the message null device 1. Once there are a lot of plots being done, or for more complex scripts which plot to a number of files, this gets to be a real hassle.

Is there some way to suppress this message?

like image 274
blahdiblah Avatar asked Apr 15 '09 07:04

blahdiblah


1 Answers

For no good reason I'm aware of, dev.off(), unlike device related functions like png() returns a value: "the number and name of the new active device." That value is what's being echoed to stdout.

Suppressing it can thus be achieved by just putting it somewhere, i.e.,

garbage <- dev.off() 
like image 121
blahdiblah Avatar answered Sep 20 '22 18:09

blahdiblah