Make a function return silently
13,004
myFunc <- function(x){
invisible(x*2)
}
> myFunc(4)
> y <-myFunc(4)
> y
[1] 8
>
Related videos on Youtube
Author by
Math
Updated on September 15, 2022Comments
-
Math over 1 year
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 usemyfunction()
.-
jdharrison almost 10 yearsUse
invisible
-
Math almost 10 yearsI just had the wrong keywords, thank you !
-
jdharrison almost 10 yearsNo problem happy to help
-
Joshua Ulrich almost 10 yearsYou would have found
invisible
had you looked at the See Also section of?return
. The See Also section is a great resource, especially when you're not sure of the correct keyword. -
rawr almost 10 yearsor you could have looked at the barplot source code,
barplot.default
-
Math almost 10 years@JoshuaUlrich I know that, but I checked and did not see it. And I know why, it's hidden behind
debug
-
jbaums almost 10 years
-
-
jdharrison almost 10 yearsMostly likely a duplicate
-
Math almost 10 yearsI would say it is usefull to keep this question for the keywork
silent
(instead of invisible). If you do not agree, I can delete it. -
jdharrison almost 10 yearsIt shouldn't be deleted the question is can a duplicate be found that has already addressed the question.
-
David F almost 6 yearsI found it by searching 'silent', not 'invisible'