Can the print() command in R be quieted?

后端 未结 5 2050
故里飘歌
故里飘歌 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条回答
  •  萌比男神i
    2021-02-14 05:29

    I know that I might be resurrecting this post but someone else might find it as I did. I was interested in the same behaviour in one of my functions and I just came across "invisibility":

    It has the same use of return() but it just don't print the value returned:

    invisible(variable)
    

    Thus, for the example given by @ayman:

    print.and.return2 <- function() {
      message("foo")
      invisible("bar")
    }
    

提交回复
热议问题