Re: [Rd] (PR#9202) Re: Bugs with partial name matching

From: Anil Maliyekkel <amaliy1_at_uic.edu>
Date: Wed 06 Sep 2006 - 03:50:30 GMT

On Sep 5, 2006, at 5:54 PM, Thomas Lumley wrote:

> The problem in
>> D = list(ABCD=2:1)
>>  D$ABC[]<-3:4
>> D
> $ABCD
> [1] 3 4
>
> $ABC
> [1] 3 4
>
> is that eval.c:evalseq ends up with a reference to D$ABCD from  
> evaluating D$ABC with partial matching.  Since evalseq doesn't (and  
> shouldn't) increase NAMED on these partially evaluated calls, NAMED  
> is still 1 for D$ABCD.  When evalseq's D$ABC has 3:4 assigned into  
> it the vector is changed directly, since NAMED=1, and both D$ABC  
> and D$ABCD change.

This problem does not appear when the following is done

> D = list(ABCD=2:1)
> D$ABC[]=c(3,4)
> D
$ABCD
[1] 2 1

$ABC
[1] 3 4

Or when this is done:

> D = list(ABCD=2:1)
> D[["ABC"]][]=3:4
> D
$ABCD
[1] 2 1

$ABC
[1] 3 4

But it does appear when the following is done:

> D = list(ABCD=2:1)
> X = 3:4
> D$ABC[]=X
> D

$ABCD
[1] 3 4

$ABC
[1] 3 4

But not when the following is done:
> D = list(ABCD=2:1)
> X = 3:4
> X[1] = 1
> D$ABC[]=X
> D

$ABCD
[1] 2 1

$ABC
[1] 1 4

It appears to be a sequence specific bug for the $ operator, which might explain why it did not occur with my original examples where I had a character data column, but did appear where I had a numeric data column that was a sequence.

Going back to the original partial replacement problem, is there anyway to turn off partial matching, or to selectively apply exact matching when trying to access a single element? I can get the desired single element match using the convoluted syntax D["ABC"] [[1]] and perform partial replacement operations on a new column. However, it would be nice to have single element access operator that does exact matching.

Anil



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Sep 06 13:52:56 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 08 Sep 2006 - 20:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.