Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 6, 2024
1 parent 9670e55 commit e6391a8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: marginaleffects
Title: Predictions, Comparisons, Slopes, Marginal Means, and Hypothesis Tests
Version: 0.24.0.3
Version: 0.24.0.4
Authors@R:
c(person(given = "Vincent",
family = "Arel-Bundock",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Development

* Version 0.24.0 accidentally removed the "contrast" column from the output object in calls with only one focal predictor. This column is reinstated.
* Reinstate some attributes lost with `marginaleffects_lean` but necessary for printing.
* More informative warning for `lme4` and `glmmTMB` models with `re.form=NULL`

Bugs:
Expand Down
15 changes: 7 additions & 8 deletions R/comparisons.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,16 @@ comparisons <- function(model,
get_marginaleffects_attributes(newdata, include_regex = "^newdata.*class|explicit|matrix|levels"))

# Global option for lean return object
lean = getOption("marginaleffects_lean", default = FALSE)
lean <- getOption("marginaleffects_lean", default = FALSE)

# Only add (potentially large) attributes if lean is FALSE
# extra attributes needed for print method, even with lean return object
attr(out, "conf_level") <- conf_level
attr(out, "by") <- by
attr(out, "lean") <- lean
attr(out, "vcov.type") <- vcov.type
if (isTRUE(lean)) {
for (a in setdiff(names(attributes(out)), c("names", "row.names", "class"))) attr(out, a) = NULL
## extra attributes needed for print method, even with lean return object
attr(out, "conf_level") <- conf_level
attr(out, "by") <- by
attr(out, "lean") <- TRUE
for (a in setdiff(names(attributes(out)), c("names", "row.names", "class"))) attr(out, a) <- NULL
} else {
# other attributes
attr(out, "newdata") <- newdata
Expand All @@ -573,8 +574,6 @@ comparisons <- function(model,
attr(out, "comparison_label") <- comparison_label
attr(out, "hypothesis_by") <- hyp_by
attr(out, "transform_label") <- transform_label
attr(out, "conf_level") <- conf_level
attr(out, "by") <- by

if (inherits(model, "brmsfit")) {
insight::check_if_installed("brms")
Expand Down
39 changes: 22 additions & 17 deletions R/predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,30 +543,35 @@ predictions <- function(model,
out <- set_marginaleffects_attributes(out, attr_cache = newdata_attr_cache)

# Global option for lean return object
lean = getOption("marginaleffects_lean", default = FALSE)

# Only add (potentially large) attributes if lean isn't TRUE
lean <- getOption("marginaleffects_lean", default = FALSE)

# Only add (potentially large) attributes if lean is FALSE
# extra attributes needed for print method, even with lean return object
attr(out, "conf_level") <- conf_level
attr(out, "by") <- by
attr(out, "lean") <- lean
attr(out, "vcov.type") <- vcov.type
if (isTRUE(lean)) {
for (a in setdiff(aa, c("names", "row.names", "class"))) attr(mfx, a) = NULL
attr(out, "lean") <- TRUE
for (a in setdiff(names(attributes(out)), c("names", "row.names", "class"))) {
attr(out, a) <- NULL
}
} else {
# other attributes
attr(out, "model") <- model
attr(out, "type") <- type_string
attr(out, "newdata") <- newdata
attr(out, "call") <- call_attr
attr(out, "type") <- type
attr(out, "model_type") <- class(model)[1]
attr(out, "vcov.type") <- get_vcov_label(vcov)
attr(out, "model") <- model
attr(out, "variables") <- predictors
attr(out, "jacobian") <- J
attr(out, "vcov") <- V
attr(out, "newdata") <- newdata
attr(out, "vcov") <- vcov
attr(out, "vcov.type") <- vcov.type
attr(out, "weights") <- marginaleffects_wts_internal
attr(out, "conf_level") <- conf_level
attr(out, "by") <- by
attr(out, "call") <- call_attr
attr(out, "hypothesis_by") <- hyp_by
attr(out, "transform_label") <- names(transform)[1]
attr(out, "comparison") <- comparison
attr(out, "transform") <- transform[[1]]
# save newdata for use in recall()
attr(out, "newdata") <- newdata
attr(out, "comparison_label") <- comparison_label
attr(out, "hypothesis_by") <- hyp_by
attr(out, "transform_label") <- transform_label

if (inherits(model, "brmsfit")) {
insight::check_if_installed("brms")
Expand Down

0 comments on commit e6391a8

Please sign in to comment.