Today i was confronted with a bug in my code due to a dataframe subset operation. I would like to know if the problem i found is a bug or if i am violating R semantics.
I am running a RHEL x86_64 with an R 2.15.2-61015 (Trick or Treat). I am using the subset operation from the base package.
The following code should be reproducible and it was run on a clean R console initiated for the purpose of this test.
>teste <-data.frame(teste0=c(1,2,3),teste1=c(3,4,5))
>teste0<-1
>teste1<-1
>subset(teste,teste[,"teste0"]==1 & teste[,"teste1"]==1)
[1] teste0 teste1
<0 rows> (or 0-length row.names)
>subset(teste,teste[,"teste0"]==teste0 & teste[,"teste1"]==teste1)
teste0 teste1
1 1 3
2 2 4
3 3 5
However, if i run the logical code outside the subset operation:
>teste[,"teste0"]==teste0 & teste[,"teste1"]==teste1
[1] FALSE FALSE FALSE
I would expect that both subset operations would yield an empty dataframe. However, the second one returns the complete dataframe. Is this a bug or am I missing something about R environments and namespaces ?
Thank you for your help, Miguel