On 12-04-19 3:11 PM, harry mamaysky wrote:
I am new to R, and I have been running into the following situation
when I mistype a variable name in some code:

list1<- list( a=1, b=2 )
list2<- list( a=1 )
list2$b<- list1$c
list2
$a
[1] 1

I would think at the point where I am trying to reference a field
called "c" -- that does not exist -- in list1, there would be an error
flagged.

Not intending to be snarky, but you should read the documentation, which does describe this.

Instead, list1$c returns value NULL, and the assignment "list2$b<-
NULL" does not return any error, but also does not create a field
called "b" in list2.

Is there a way to have R flag the reference to field  "c" in list1 as an error?

No there isn't. You get a bit more support if you index by number: list1[[3]] will give an error (though assigning into list2[[2]] will make list2 bigger).

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.

Reply via email to