Search code examples
rreturn

Make a function return silently


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


Solution

  • myFunc <- function(x){
      invisible(x*2)
    }
    
    > myFunc(4)
    > y <-myFunc(4)
    > y
    [1] 8
    >