0

I have a script and in that script I am running a command form a package: proteinToGenome() from the ensembldb package.

I run the command iteratively using a for () {} structure, and upon each iteration it will return RED output that is more of "progress" messages that output regardless of the success/failure of the command, not warning messages:

Checking CDS and protein sequence lengths ... 1/1 OK

Fetching CDS for 1 proteins ... 1 found

or:

Fetching CDS for 1 proteins ... 1 found

Checking CDS and protein sequence lengths ... 0/0 OK

How do I suppress these messages? Other questions I found do not seem to apply to these and their solutions do not seem to stop these. I have tried all the solutions presented in:

Suppress output of a function

I have tired:

capture.output(for (x in length(DF)) { 
        OutputDF <- function(DF[x])
})

and:

sink(for (x in length(DF)) { 
        OutputDF <- function(DF[x])
})

also tried:

hush=function(code){
  sink("NUL") # use /dev/null in UNIX
  tmp = code
  sink()
  return(tmp)
}
hush(for (x in length(DF)) { 
        OutputDF <- function(DF[x])
})

also, the reason I use for and not lapply() is because I check whether or not the OutputDF is empty, and take action accordingly using an if(){}else{} command within the for(){} loop

Sky Scraper
  • 148
  • 1
  • 10

1 Answers1

1

How about:

suppressMessages(proteinToGenome(...))

Where the arguments you are using in the model replace ...

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • No, that also didnt work :/ – Sky Scraper Jan 24 '22 at 18:19
  • 1
    @SkyScraper - looks like those are all printed with `message()` so using `suppressMessages()` wrapped around the call to `proteinToGenome()` should work. I updated the answer. – DaveArmstrong Jan 24 '22 at 18:36
  • Thanks so much! So there are 3 different kinds of output? Messages, error messages, and output messages? Is taht right? or are there more technical terms? @DaveArmstrong – Sky Scraper Jan 25 '22 at 17:53
  • 1
    I think of them by how you trigger them. There is a `message()` function, a `warning()` function and then a `stop()` function (which throws an error). You can use `suppressMessages()` and `suppressWarnings()` to stop those kinds of output. You can also print output with `print()` or `cat()` which are would likely be suppressed in the ways you tried in your original post. – DaveArmstrong Jan 25 '22 at 19:14
  • so print output acts in a similar fashion as warnings but messages are unique? Sorry, Ive never written scripts with message() or warning() >-<" I usually use print to output any information I want the script to inform me about... – Sky Scraper Jan 25 '22 at 19:27