Skip to content

Commit

Permalink
wts=NULL is wts=FALSE for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Apr 12, 2024
1 parent 6b2c4d7 commit 4cd2363
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/sanitize_newdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ sanitize_newdata <- function(model, newdata, by, modeldata, wts) {
modeldata <- tmp[["modeldata"]]
newdata_explicit <- tmp[["newdata_explicit"]]
newdata <- clean_newdata(model, newdata)
if (is.null(wts)) wts <- FALSE
newdata <- add_wts_column(newdata = newdata, wts = wts, model = model)
newdata <- set_newdata_attributes(
model = model,
Expand Down
8 changes: 8 additions & 0 deletions inst/tinytest/test-weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ expect_equivalent(p2, p3)
expect_equivalent(p2, p4)


# backward compatibility
p1 <- avg_predictions(mod, wts = "weights", newdata = dat)
p2 <- avg_predictions(mod, wts = NULL, newdata = dat)
p3 <- suppressWarnings(avg_predictions(mod, wts = FALSE, newdata = dat))
expect_equivalent(p2$estimate, p3$estimate)
expect_true(p1$estimate != p2$estimate)


# by supports weights
p1 <- avg_predictions(mod, wts = "weights", newdata = dat)
expect_inherits(p1, "data.frame")
Expand Down

0 comments on commit 4cd2363

Please sign in to comment.