tidyverse / magrittr

Improve the readability of R code with the pipe

Home Page:https://magrittr.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error when invoking pipe with R built using strict barrier

kevinushey opened this issue · comments

I'm seeing an issue when using the new magrittr pipe on a copy of R devel built using --enable-strict-barrier. See reprex:

library(magrittr)
"hello" %>% identity
#> Error in "hello" %>% identity: CAR/CDR/TAG or similar applied to character object

Created on 2020-12-12 by the reprex package (v0.3.0)

Session info
sessionInfo()
#> R Under development (unstable) (2020-12-12 r79621)
#> Platform: x86_64-apple-darwin20.1.0 (64-bit)
#> Running under: macOS Big Sur 10.16
#> 
#> Matrix products: default
#> BLAS:   /usr/local/Cellar/openblas/0.3.12_1/lib/libopenblasp-r0.3.12.dylib
#> LAPACK: /usr/local/Cellar/lapack/3.9.0_1/lib/liblapack.3.9.0.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] magrittr_2.0.1.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.1.0  tools_4.1.0     htmltools_0.5.0 yaml_2.2.1     
#>  [5] stringi_1.5.3   rmarkdown_2.5   highr_0.8       knitr_1.30     
#>  [9] stringr_1.4.0   xfun_0.19       digest_0.6.27   rlang_0.4.9    
#> [13] evaluate_0.14

In the backtrace, I see:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x000000010eb34fbf libR.dylib`Rf_error(format=<unavailable>) at errors.c:946:5 [opt]
    frame #1: 0x000000010ec36aee libR.dylib`CHKCONS(e=0x0000625004039d08) at memory.c:4083:2 [opt]
    frame #2: 0x000000010ec36b6b libR.dylib`CDR(e=0x0000625004039d08) at memory.c:4182:33 [opt]
    frame #3: 0x000000015deb3a09 magrittr.so`pipe_unroll(lhs=0x0000625004039d08, rhs=0x00006250012d2820, env=<unavailable>, kind=<unavailable>, pipe_sym=<unavailable>, p_assign=<unavailable>) at pipe.c:247:17 [opt]
    frame #4: 0x000000015deb3408 magrittr.so`magrittr_pipe(call=<unavailable>, op=<unavailable>, args=<unavailable>, rho=0x00006250012e27e0) at pipe.c:84:16 [opt]
    < ... >

frame #3: 0x000000013e062a09 magrittr.so`pipe_unroll(lhs=0x0000625002416890, rhs=0x00006250024258c8, env=<unavailable>, kind=<unavailable>, pipe_sym=<unavailable>, p_assign=<unavailable>) at pipe.c:247:17 [opt]
   244      out = Rf_cons(rhs, out);
   245      REPROTECT(out, out_pi);
   246
-> 247      SEXP args = CDR(lhs);
   248
   249      if ((kind = parse_pipe_call(lhs, pipe_sym))) {
   250        lhs = CAR(args);
(lldb) expr Rf_PrintValue(lhs)
[1] ""

The attempt to call CDR(lhs) seems to indeed be incorrect, since lhs isn't a call object here. Does the usage of CDR() need to be checked?