How to hide or disable in-function printed message

后端 未结 3 1902
情深已故
情深已故 2020-12-01 08:04

Suppose I have a function such as:

ff <- function(x) {
  cat(x, \"\\n\")
  x^2}

And run it by:

y <- ff(5)
# 5 
y
# [1         


        
3条回答
  •  天命终不由人
    2020-12-01 08:33

    You can use capture.output with invisible

    > invisible(capture.output(y <- ff(2)))
    > y
    [1] 4
    

    or sink

    > sink("file")
    > y <- ff(2)
    > sink()
    > y
    [1] 4
    

提交回复
热议问题