Thomas Friedrichsmeier
2020-May-23 11:19 UTC
[Rd] Surpising behavior when using an active binding as loop index in R 4.0.0
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 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: Digitale Signatur von OpenPGP URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20200523/8f3f891d/attachment.sig>
Thomas Friedrichsmeier
2020-May-23 12:07 UTC
[Rd] Surpising behavior when using an active binding as loop index in R 4.0.0
Possibly just a symptom of the earlier behavior, but I'll amend my example, below, with an even more disturbing observation: Am Sat, 23 May 2020 13:19:24 +0200 schrieb Thomas Friedrichsmeier via R-devel <r-devel at r-project.org>: [...]> 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] 4ls() # Error in ls() : # Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL' Regards Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: Digitale Signatur von OpenPGP URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20200523/b67df0e4/attachment.sig>
Deepayan Sarkar
2020-May-24 04:50 UTC
[Rd] Surpising behavior when using an active binding as loop index in R 4.0.0
A shorter reproducible example: example(makeActiveBinding) for (fred in 1:3) { 0 } ls() Both problems go away if you first do compiler::enableJIT(2) So looks like a bug in compiling the for loop. -Deepayan On Sat, May 23, 2020 at 5:45 PM Thomas Friedrichsmeier via R-devel <r-devel at r-project.org> wrote:> > Possibly just a symptom of the earlier behavior, but I'll amend my > example, below, with an even more disturbing observation: > > Am Sat, 23 May 2020 13:19:24 +0200 > schrieb Thomas Friedrichsmeier via R-devel <r-devel at r-project.org>: > [...] > > 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 > > ls() > # Error in ls() : > # Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL' > > Regards > Thomas > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Reasonably Related Threads
- Surpising behavior when using an active binding as loop index in R 4.0.0
- Surpising behavior when using an active binding as loop index in R 4.0.0
- Rd parser throws error for user macros invoked with empty argument
- Read a text file into R with .Call()
- Rd parser throws error for user macros invoked with empty argument