Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling the cat command

Tags:

r

cat

Suppose I have the following function:

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

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

Reason behind this question

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

like image 977
csgillespie Avatar asked Mar 15 '11 10:03

csgillespie


People also ask

What is cat command in CMD?

cat command ( short for concatenate) is one of the powerful command to create single or multiple files, view contents of the file, concatenate multiple files, copy the content to other files, and print output to terminal or file.

How do I get my cat command back?

txt, the cat command using the > operator WILL overwrite it. To get back to the command line and create the text file we use CTRL + D. If we wanted to append or add more text to these files we would use cat >> FILENAME and input the text we want to use.

How do I turn off cat command?

In order to stop/exit/quit cat command, you can simply press key q, you should return to the prompt.

How do I stop a cat in Linux?

To exit the prompt and write the changes to the file, hold the Ctrl key and press d.


2 Answers

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()
like image 106
juba Avatar answered Oct 19 '22 23:10

juba


This should work?

oldcat = cat
cat = function( ..., file="", sep=" ", fill=F, labels=NULL, append=F ) {}
f()
cat = oldcat

Just replace cat with an empty function, and then set it back on completion

like image 29
tim_yates Avatar answered Oct 20 '22 01:10

tim_yates