禁用cat命令 [英] Disabling the cat command

查看:79
本文介绍了禁用cat命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有以下功能:

## Just an example
f = function() { 
  for(i in 1:10000)
      cat(i)
  return(1)
}

当我呼叫 f()时,有一种方法可以停止 cat 打印

When I call f() is there a way to stop cat printing to the screen (without altering the function in anyway)?

此问题背后的原因

我的学生上传他们的R文件。然后,我运行脚本并检查它们是否正确。每隔一段时间,学生就会离开 cat 命令。

My students upload their R files. I then run the scripts and check to see if they are correct. Every so often, a student leaves in the cat command. This is especially irritating when it's in a long for loop

推荐答案

在Linux中,您可以使用 sink ()调用 / dev / null (或另一个操作系统上的临时文件,请参见?tempfile ):

On Linux, you can use a sink() call to /dev/null(or to a temporary file on another OS, see ?tempfile) :

sink(file="/dev/null")
f()
sink()

这篇关于禁用cat命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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