On Jul 20, 2014, at 6:30 AM, Duncan Murdoch wrote:

> On 17/07/2014, 10:00 PM, Dario Strbenac wrote:
>> The example in the question was not inside a user function.
> 
> The explanations you were given were slightly inaccurate.  The usual
> rule is that results returned at the top level are printed unless they
> are marked as invisible.  (There are a few cases where "top level" is
> faked, e.g. in example code, and in Sweave.)
> 
> When you do something like
> 
> if(test) { a; b; c }
> 
> you have an expression that returns NULL invisibly if the test is FALSE,
> and returns the value of the block (i.e. c) visibly if it is TRUE.  It
> is the value of the if that is printed.
> 
> There is no difference in the handling of a, b and c:  each is an
> expression that returns the value of the corresponding variable without
> marking it as invisible.  But none of them are top-level expressions, so
> none of them print.

I'm not sure what that last one was intended to mean but it seemed to imply 
that nothing would be printed if those expressions had values (even if the 
interpreter were able to find values in one of hte enclosing environments). 
That would not be what I expected. I think of curved-braces as a function and 
the results of the last evaluation would be expected to be returned:

> test <- TRUE
> a=2;b=3;c=4
> if(test){a;b;c}
[1] 4

If one of them had no value, an error would be thrown.

> rm(b)
> if(test){a;b;c}
Error: object 'b' not found

-- 

David Winsemius
Alameda, CA, USA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to