[R] more errors (behavior)

ivo welch ivowel at gmail.com
Sun Oct 24 21:55:12 CEST 2010


quick programming question.  I am not making enough errors in my
programs, so I want to trigger a few more.  ;-)

[1] undefined variable behavior:

> d=data.frame( x=rnorm(1:10), y=rnorm(1:10))
> z
Error: object 'z' not found
> d$z
NULL

is this consistent?  I thought that z is the same as .GlobalEnv$z, but
apparently it is not.  something here is smart enough to trigger an
error.   I like this error behavior.   is it possible to set an R
global option that triggers the same 'not found' error when an
undefined element of a list or data frame is accessed?

[just trying to check all my function arguments, and right now, I
think I need to include for each argument
'stopifnot(is.null(argument))'.  This clutters the code.]


[2] is it possible to turn off recycling for vector operations?  (I
may have asked this at some point already, but I can't find the
answer.)

> a=c(2,3)
> b=c(4,5,6,7)
> a+b
[1]  6  8  8 10

when I really want recycling, I would rather do it explicitly with rep.


regards,

/iaw
----
Ivo Welch (ivo.welch at brown.edu, ivo.welch at gmail.com)



More information about the R-help mailing list