燮pressing"空设备"在批处理模式右输出 [英] Suppressing "null device" output with R in batch mode

查看:388
本文介绍了燮pressing"空设备"在批处理模式右输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些它调用 - [R脚本策划东西的bash脚本。是这样的:

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

问题是,尽管 - 从,调用 dev.off()打印消息空设备1 。一旦有被做了很多地块,或为更复杂的脚本,情节多个文件,这得是一个真正的麻烦。

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.

有没有一些方法来共进晚餐preSS此消息?

Is there some way to suppress this message?

推荐答案

一个关于R的好处之一是,你可以看到很多功能的源代码:

One of the nice things about R is that you can view the source of many functions:

> dev.off
function (which = dev.cur()) 
{
    if (which == 1) 
        stop("cannot shut down device 1 (the null device)")
    .Internal(dev.off(as.integer(which)))
    dev.cur()
}
<environment: namespace:grDevices>

所以它调用。内部(dev.off(...)),然后返回dev.cur(),我猜想是,如果你有几个有用设备打开,以便你知道哪一个变得活跃起来。你可以使用。内部(dev.off(as.integer(dev.cur())))在你的脚本,甚至是补丁开发。关闭只返回的值dev.cur()如果是别的东西比空设备,以及补丁发送到的维护者R上。

So it calls .Internal(dev.off(...)) and then returns dev.cur(), which I suppose would be useful if you have several devices open so you know which one became active. You could use .Internal(dev.off(as.integer(dev.cur()))) in your script, or even patch dev.off to only return the value of dev.cur() if it is something else than the null device, and send the patch to the maintainers of R.

此外, graphics.off()通话 dev.off()为所有设备不返回任何东西。

Also, graphics.off() calls dev.off() for all devices and doesn't return anything.

这篇关于燮pressing&QUOT;空设备&QUOT;在批处理模式右输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆