r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
507 stars 139 forks source link

"inserting non-tracking CDR in tracking cell" in `eval_quo()` with strict write barrier #1584

Open krlmlr opened 1 year ago

krlmlr commented 1 year ago

Setting a data frame column in a data frame named df or nrow gives an interesting error message with R built with --enable-strict-barrier . This doesn't happen with a data frame named dim or x, or when evaluating with eval() . Is this triggered by the data frame object having the same name as a function (but not a primitive)?

new_df <- function() {
  data.frame(n = 0)
}

df <- new_df()
df[[1]] <- 1
df
#>   n
#> 1 1

library(rlang)

df <- new_df()
eval_tidy(quo(df[[1]] <- 1))
#> Error in df[[1]] <- 1: inserting non-tracking CDR in tracking cell

nrow <- new_df()
eval_tidy(quo(nrow[[1]] <- 1))
#> Error in nrow[[1]] <- 1: inserting non-tracking CDR in tracking cell

dim <- new_df()
eval_tidy(quo(dim[[1]] <- 1))

x <- new_df()
full_code <- rlang::quo(x[[1]] <- 1)
rlang::eval_tidy(full_code)

Created on 2023-03-04 with reprex v2.0.2