nt-williams / lmtp

:package: Non-parametric Causal Effects Based on Modified Treatment Policies :crystal_ball:
http://www.beyondtheate.com
GNU Affero General Public License v3.0
55 stars 16 forks source link

Fix error with assigning null to under shift dataframes #136

Open jakewilliami opened 1 month ago

jakewilliami commented 1 month ago

Hi Nick,

I was getting some errors with lmtp_{sdr, tmle, sub} when the input data is a tbl_df/tbl:

Error in `[[<-`(`*tmp*`, trt_var, value = NULL) : 
  Can't assign column with `trt_var`.
✖ Subscript `trt_var` must be a location, not a character `NA`.

Not sure if what I have suggested is the best fix for this, but it's one that worked for me. You could also assert the type of the input data is data.frame.

Example to replicate the error:

library(lmtp)
library(tibble)
A <- "trt"
Y <- paste0("Y.", 1:6)
C <- paste0("C.", 0:5)
W <- c("W1", "W2")
lmtp_{sdr, tmle, sub}(sim_point_surv |> tibble(), A, Y, W, cens = C, folds = 2,
                      shift = static_binary_on, outcome_type = "survival")

To illustrate root of error:

rdf <- data.frame()
rdf[[as.character(NA)]] <- NULL  # This is fine; it will do nothing

tdf <- tibble()
tdf[[as.character(NA)]] <- NULL  # This will error as lmtp does
nt-williams commented 1 month ago

Hey @jakewilliami , thanks for bringing this up! Could you open up an issue?

jakewilliami commented 1 month ago

137 🙂