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

Tierney, Luke |uke-t|erney @end|ng |rom u|ow@@edu
Wed Feb 27 21:42:05 CET 2019


On Tue, 26 Feb 2019, Brian Montgomery via R-devel wrote:

> 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.

Calling replacement functions this way is a Really Bad Idea. Some
assume they are being called properly and will end up mutating data
they should not when called this way.

Best,

luke

>
> Thank you for your help!
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


More information about the R-devel mailing list