Issue
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] 25
My question is how to disable or hide the 5
printed from cat(x, "\n")
such as:
y <- ff(5)
y
# [1] 25
Solution
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
Answered By - romants Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.