Bug 15115 - call() does not duplicate its arguments
call() does not duplicate its arguments
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Low-level
R 2.15.1 patched
All All
: P5 normal
Assigned To: Duncan Murdoch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-24 22:49 UTC by Duncan Murdoch
Modified: 2012-11-25 01:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Duncan Murdoch 2012-11-24 22:49:29 UTC
I have a fix for this bug, and will commit it soon:  I'm posting this so that the NEWS item can refer to the description below.

Building an expression in code doesn't always work in 2.15.2 or the current R-patched or R-devel:

a <- as.name("abc")
f <- call("==", a, 1L)
for (i in 2:5) {
   f <- call("+", f, call("==", a, i))
   print(f)
}

Running this in R-patched prints

(abc == 1L) + (abc == 2L)
(abc == 1L) + (abc == 3L) + (abc == 3L)
(abc == 1L) + (abc == 4L) + (abc == 4L) + (abc == 4L)
(abc == 1L) + (abc == 5L) + (abc == 5L) + (abc == 5L) + (abc ==
     5L)

Notice that in the successive terms which were constructed as call("==", 
a, i) it appears that i is being evaluated at the wrong time, i.e. at 
the time of printing, rather than when the assignment was made.  
However, I this is a NAMED bug; this variant does what I 
wanted:

a <- as.name("abc")
f <- call("==", a, 1L)
for (i in 2:5) {
   x <- i
   f <- call("+", f, call("==", a, i))
   print(f)
}

By assigning x <- i, that will bump the NAMED value, and then I get this 
output as expected:

(abc == 1L) + (abc == 2L)
(abc == 1L) + (abc == 2L) + (abc == 3L)
(abc == 1L) + (abc == 2L) + (abc == 3L) + (abc == 4L)
(abc == 1L) + (abc == 2L) + (abc == 3L) + (abc == 4L) + (abc ==
     5L)