Can the print() command in R be quieted?

后端 未结 5 1958
故里飘歌
故里飘歌 2021-02-14 04:58

In R some functions can print information and return values, can the print be silenced?

For example:

print.and.return <- function() {
  print(\"foo\         


        
5条回答
  •  花落未央
    2021-02-14 05:42

    If you absolutely need the side effect of printing in your own functions, why not make it an option?

    print.and.return <- function(..., verbose=TRUE) {
      if (verbose) 
        print("foo")
      return("bar")
    }
    
    
    > print.and.return()
    [1] "foo"
    [1] "bar"
    > print.and.return(verbose=FALSE)
    [1] "bar"
    > 
    

提交回复
热议问题