glanceworks this way because a broom package defines a method for cropping data frames here . If you want to include this entire .R file (along with the utility col_namefrom here ), you can use my code to do the same:
myglance_df <- wrap_rowwise_df(wrap_rowwise_df_(myglance))
mtcars %>%
group_by(am) %>%
do(model = lm(mpg ~ wt, .)) %>%
myglance_df(model)
, : .
glance.mylm <- function(x, ...) {
s <- summary(x)
ret <- with(s, data.frame(r2=adj.r.squared, a=coefficients[1], b=coefficients[2]))
ret
}
mtcars %>%
group_by(am) %>%
do(model = lm(mpg ~ wt, .)) %>%
mutate(model = list(structure(model, class = c("mylm", class(model))))) %>%
glance(model)
, myglance .
mtcars %>%
group_by(am) %>%
do(myglance(lm(mpg ~ wt, .)))