[R] Using str() in a function.
gunter.berton at gene.com
Fri Jul 15 19:44:55 CEST 2011
On Fri, Jul 15, 2011 at 10:31 AM, andrewH <ahoerner at rprogress.org> wrote:
> Thanks, everybody, this has been very edifying. One last question:
> It seems that sometimes when a function returns something and you don't
> assign it, it prints to the console, and sometimes it doesn't. I'm not sure
> I understand which is which. My best current theory is that, if the function
> returns NULL, by itself and not as part of some larger object, it does not
> print it, but non-null values are printed. Is that correct?
It depends on whether the function uses invisible() in the return,
If invisible() is not used and the value is not assigned, it's
printed. Otherwise not.cf:
f <- function()NULL
g <- function()invisible(NULL)
f() ## NULL is printed
g() ## nothing printed
z1 <- f() ## nothing printed
z2 <- g() ## nothing printed
z1 ## NULL
> Thanks! Andrew
> View this message in context: http://r.789695.n4.nabble.com/Using-str-in-a-function-tp3655785p3670513.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
-- Maimonides (1135-1204)
Genentech Nonclinical Biostatistics
More information about the R-help