On 03/11/2010 2:05 PM, ivo welch wrote:
quick programming questions. I want to "turn on" more errors. there
are two traps I occasionally fall into.
* I wonder why R thinks that a variable is always defined in a data frame.
> is.defined(d)
[1] FALSE
> d= data.frame( x=1:5, y=1:5 )
> is.defined(d$z)
[1] TRUE
> is.defined(nonexisting$garbage)
[1] TRUE
this is a bit unfortunate for me, because subsequent errors become
less clear. right now, I need to do '(is.defined(d) and
!is.null(d$z))' to check that my function inputs are valid. It would
be nicer if one could just write "if (is.defined(d$z)".
* is there a way to turn off automatic recycling? I would rather get
an error than unexpected recycling. I can force recycling with rep()
when I need to.
Where did you find the is.defined() function? It's not part of R. The
R function to do that is exists().
Duncan Murdoch
______________________________________________
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.