Reputation: 2436
I would like to write an R function that returns silently, like what I get from the barplot
function for example.
I mean that I can store an output in a variable if I do output = myfunction()
, but this output does not get printed if I just use myfunction()
.
Upvotes: 30
Views: 16786
Reputation: 105
invisible()
can be called at the end of the function to suppress any return value. Only downside is function will return NULL
.
xf <- function() {
3 + 4
invisible()
}
Upvotes: 0
Reputation: 30425
myFunc <- function(x){
invisible(x*2)
}
> myFunc(4)
> y <-myFunc(4)
> y
[1] 8
>
Upvotes: 31