tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
957 stars 157 forks source link

Intermittent problem with inset and compound assignment pipe operator #190

Closed bkmontgom closed 5 years ago

bkmontgom commented 5 years ago

Trying this again...I'm still having problems with it. #160 was closed because the error could not be reproduced.

library('magrittr')
x <- 1:200000
y <- rep(letters[1:5], length(x) / 5L)
for (i in 1:100) {
  # x[y == 'a'] <- x[y == 'b']
  x %<>% inset(y == 'a', x[y == 'b'])
  cat(i, '')
}

If you can't reproduce this error, please try increasing the length of x. The larger I make it, the more likely it is to crash R, instead of giving an error first. The error I usually get is

Error in function_list[[k]](value) : 
  incompatible types (from builtin to integer) in subassignment type fix

If the commented-out code is substituted, this works without error or crash.

Zedseayou commented 5 years ago

I can reproduce this error, but I think the issue is specifically with the compound assignment pipe, not inset. At least substituting x <- inset(x, y == 'a', x[y == 'b']) works fine for me (and I would be surprised if it didn't since it is literally a direct alias if you look at the code).

bkmontgom commented 5 years ago

Here is what I got with x <- inset(x, y == 'a', x[y == 'b']) and no compound assignment pipe.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Error in inset(x, y == "a", x[y == "b"]) : 
 incompatible types (from builtin to integer) in subassignment type fix

The next two times R crashed after 50, then 26 times through the loop. I see that the code is a direct alias, so I can't explain this behavior.

Just to be sure, I tried x <- `[<-`(x, y == 'a', x[y == 'b']) and it crashed as well.

Since this code doesn't involve anything from magrittr, I tried removing library('magrittr') and I still got failures.

I'll have to contact the base R folks. Thank you for your help.