25

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().

Math
  • 2,269
  • 2
  • 18
  • 22

1 Answers1

26
myFunc <- function(x){
  invisible(x*2)
}

> myFunc(4)
> y <-myFunc(4)
> y
[1] 8
> 
jdharrison
  • 29,243
  • 4
  • 71
  • 87