Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid console message form package function

Tags:

r

I'm using a package function (corenv, from seewave) which create a "please wait..." message in console. As I call it iteratively, that message is very annoying. So, I need a way for:

  • From my code, to temporarily ban the console messages

OR

  • To access the function code and take off the message line

The following is not my real code, but a very simple one showing the problem

require(seewave)
a = seq(0, (2*pi), by=0.01) #simple, unreal example
for (i in sequence(100)){
  x = sin(a*i/3) #simple, unreal example
  y = sin(a*i/2) #simple, unreal example
  corenv(x,y,10,plot=FALSE)
}

A very simple question, but I haven't found any solution. I'll aprecciate any help

like image 777
user2410924 Avatar asked Apr 07 '26 19:04

user2410924


1 Answers

You could use sink to capture the output, e.g.

sink("tmp.txt")
z = corenv(x,y,10,plot=FALSE)
sink()

You can also wrap it in a function, e.g.

## unlink deletes the temporary file
## on.exit ensures the sink is closed even if 
## corenv raises an error.
corenv(..., verbose=FALSE) {
  if(verbose) {
    sink("tmp.txt")
    on.exit(sink(); unlink("tmp.txt"))
  }
  seewave::corenv(...)
}
like image 151
csgillespie Avatar answered Apr 09 '26 11:04

csgillespie