Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a function return silently

Tags:

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

like image 384
Math Avatar asked Jun 09 '14 14:06

Math


People also ask

How do you hide the output of a function?

We can make the output should not appear. By using invisible() function we can suppress the output.

Why does R return null?

NULL represents the null object in R. NULL is used mainly to represent the lists with zero length, and is often returned by expressions and functions whose value is undefined. as. null ignores its argument and returns the value NULL .

What does invisible mean in R?

The invisible() function in R Programming Language is used to make the printing statements invisible which means the printing statements will not appear.

What does an R function return?

Answer: R returns the last output of a function automatically. We therefore do not need to use the return explicitly. However, using the return command is often considered as good practice, since it makes the R code easier to read and understand.


1 Answers

myFunc <- function(x){   invisible(x*2) }  > myFunc(4) > y <-myFunc(4) > y [1] 8 >  
like image 128
jdharrison Avatar answered Sep 24 '22 12:09

jdharrison