Skip to content

Bugs with partial name matching during partial replacement (PR#9299)

4 messages · Hin-Tak Leung, Thomas Lumley, Brian Ripley

#
This is a rather interesting, but I don't think it is a bug - it is
just things that "you are not supposed to do"... you are assuming
a certain evaluation order of the 4 "$" operators in
" D$ABC[D$M] = D$V[D$M] " as in:

temp1 <- D$M                 # 2nd and 4th
temp2 <- D$V[temp1]          # 3rd
D$ABC[temp1] = temp2         # 1st

What R did was this:

temp4 <- D$ABC         # make reference, expand to D$ABCD , 1st
temp1 <- D$M           # 2nd, and 4th
temp2 <- D$V[temp1]    # 3rd

temp4[temp1] <- temp2  # oh dear, it looks as if we are
D$ABC <- temp4         # trying to write to a reference,
                        # better make a copy instead

R is doing the 4 $'s roughly from left to right, if you have some ideas 
how R works inside. (I am not saying this behavior is a "good" thing,
but at least it is consistent). Basically it is a very bad habit to 
write code that depends on evaluation order of operators at the same
precendence.

The difference in behavior in the two case is probably due to
coercion, (and also how lazy R does make-a-reference versus "oops, you 
seems to try to write to a reference so I better copy it") but
I'll leave you to think about what order R is doing the combination of
the 4 $'s and coercing between types... Basically writing code that 
depends on evaluation order is a bad idea.

c.f. this bit of C code:

i =0;
++i = ++i + ++i;

what value do you think "i" should be?
amaliy1 at uic.edu wrote:
#
On Mon, 16 Oct 2006, hin-tak.leung at cimr.cam.ac.uk wrote:

            
It was a bug. It has been fixed in R 2.4.0. Unfortunately, since you 
didn't quote the PR# of the original bug in the subject line you have just 
filed a new bug report for it.

 	-thomas
Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle
#
Thomas Lumley wrote:
I am sorry (about both the duplicate report and the comment).

I don't know what happened with the duplication - but as you see
I replied to both r-devel and r-bugs in the same e-mail, and the
one arriving back via r-devel did have the right subject with
the PR#9202 at the end, and the other copy via r-bugs didn't and
got a new one. It seems somewhere during in the round-trip
over-long subject lines get truncated and/or a new-line inserted in
the middle. May worth investigating...

Regards,
Hin-Tak
#
On Tue, 17 Oct 2006, Hin-Tak Leung wrote:

            
We know you need to have the PR# number on the first line of the subject. 
This is why Thomas duplicated it (and I move it to the beginning).

At one time JitterBug had a higher version number than R, and at around 
that time it seemed to be orphaned.  Now R > 2.4.0, and JitterBug is still 
at 1.6.2.