You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a request to reopen #937 , with a potential diagnosis and fix.
This bug describes how the .resid column is missing when terms in the formula are function calls of variables, eg. log(var); see here for the diagnosis in that issue.
I agree the problem is in the response function in utilities.R; it attempts to create the response variable by calling model.response on a new version of the data set, created using model.frame(terms(object), data = newdata). The problem with this is that if newdata was created using model.frame in the first place (which it is by default in augment_newdata), it will already have the results from the function calls instead of the data itself, so recreating the function calls fails.
The solution is to check if newdata already has a response (ie, was created from model.frame), and if so, to use that directly, instead of recreating it. If not, then the current code should be run. The below code adds this, wrapping it in a possibly, as if it doesn't have a response associated with it, an error is likely.
See ?model.frame/?get_all_vars (the last paragraph of Details) for a brief explanation of what model.frame does, in contrast with with get_all_vars does. I don't think we can't use get_all_vars instead because it requires the raw data set as a parameter.
response <- function(object, newdata = NULL) {
## if the newdata was created as a model.frame, it will have a response already
## wrap this in possibly, because if not, an error is likely
safe_model.response <- purrr::possibly(model.response, NULL)
resp <- safe_model.response(newdata)
## if not, need to recreate it from the newdata
if(is.null(resp)) {
resp <- model.response(model.frame(terms(object), data = newdata, na.action = na.pass))
}
resp
}
The text was updated successfully, but these errors were encountered:
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
This is a request to reopen #937 , with a potential diagnosis and fix.
This bug describes how the .resid column is missing when terms in the formula are function calls of variables, eg.
log(var)
; see here for the diagnosis in that issue.I agree the problem is in the response function in utilities.R; it attempts to create the response variable by calling
model.response
on a new version of the data set, created usingmodel.frame(terms(object), data = newdata)
. The problem with this is that ifnewdata
was created usingmodel.frame
in the first place (which it is by default inaugment_newdata
), it will already have the results from the function calls instead of the data itself, so recreating the function calls fails.The solution is to check if newdata already has a response (ie, was created from
model.frame
), and if so, to use that directly, instead of recreating it. If not, then the current code should be run. The below code adds this, wrapping it in apossibly
, as if it doesn't have a response associated with it, an error is likely.See ?model.frame/?get_all_vars (the last paragraph of Details) for a brief explanation of what
model.frame
does, in contrast with withget_all_vars
does. I don't think we can't useget_all_vars
instead because it requires the raw data set as a parameter.The text was updated successfully, but these errors were encountered: