Hi,

I stumbled upon a surprising behavior when using an active binding as a
loop index variable in R 4.0.0. In contrast, the behavior observed in R
3.6.1 is in line with my expectations.

Consider the code below:

makeActiveBinding("i", 
        function(value) {
                if (missing(value)) {
                        x
        } else {
                print("set")
                x <<- value
        }
        }, globalenv())

i <- 1     # output "set"
print(i)   # output [1] 1

# Surprising behavior starts here:
for(i in 2:3) print(i) # output [1] "set"
                       #        NULL
                       #        NULL

print(i)               # output NULL
print(x)               # output NULL

i <- 4                 # output "set"
print(i)               # ouput [1] 4
print(x)               # ouput [1] 4

Regards
Thomas

Attachment: pgpyKwfk1KgEj.pgp
Description: Digitale Signatur von OpenPGP

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to