[Rd] Intermittent crashes with inset `[<-` command

Brian Montgomery bmontgomery @end|ng |rom y@hoo@com
Tue Feb 26 05:18:19 CET 2019


The following code crashes after about 300 iterations on my x86_64-w64-mingw32 machine on R 3.5.2 --vanilla.  
Others have duplicated this (see https://github.com/tidyverse/magrittr/issues/190 if necessary), but I don't know how machine/OS-dependent it may be.  
If it doesn't crash for you, please try increasing the length of the x vector.

Substituting the commented-out line for the one below it works correctly (prints out 1:1000 and ends normally) every time.

x <- 1:200000
y <- rep(letters[1:5], length(x) / 5L)
for (i in 1:1000) {
  # x[y == 'a'] <- x[y == 'b']
  x <- `[<-`(x, y == 'a', x[y == 'b'])
  cat(i, '')
}
cat('\n')

The point of using this syntax is to make it work better with pipes, but the errors occur without pipes or magrittr.

Thank you for your help!



More information about the R-devel mailing list