Home Comments Thread
New Thread

2 Comments

giscus-bot giscus-bot 2022-12-17 01:25:10
Guest *Daijiang Li* @ 2017-06-11 02:42:10 originally posted:

Why sometimes people use invisible() (blank argument) at the end of a function? If I do not need to return anything, I can just make sure the last call within the function does not return a result, e.g. assign it to a variable. What is the benefit? Thanks.

@daijiang

yihui yihui 2022-12-17 01:25:10

invisible() is equivalent to invisible(NULL).

An explicit invisible() value at the end of a function will make sure the returned value is invisible. If you rely on other expressions to return an invisible value, you may forget it after you change the function and return a visible value by accident.

Originally posted on 2017-06-11 04:18:53

alanraetz alanraetz 2023-06-26 16:35:29

This explanation is very helpful, thank you. I have been stuck for over a day... as a long-term programmer who is new to R and R markdown, it seems a little ridiculous, but once you explain the mechanism, it makes sense. I was assuming it was some bug in the code, I just couldn't isolate it... I know in R loops are not common, but I wish this 'feature' was mentioned more prominently in the documentation.

Sign in to join the discussion

Sign in with GitHub