{"action":"created","issue":{"url":"https://api.github.com/repos/tidyverse/broom/issues/287","repository_url":"https://api.github.com/repos/tidyverse/broom","labels_url":"https://api.github.com/repos/tidyverse/broom/issues/287/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/broom/issues/287/comments","events_url":"https://api.github.com/repos/tidyverse/broom/issues/287/events","html_url":"https://github.com/tidyverse/broom/issues/287","id":302311207,"number":287,"title":"augment makes 'OBJECT' columns ","user":{"login":"romainfrancois","id":2625526,"avatar_url":"https://avatars3.githubusercontent.com/u/2625526?v=4","gravatar_id":"","url":"https://api.github.com/users/romainfrancois","html_url":"https://github.com/romainfrancois","followers_url":"https://api.github.com/users/romainfrancois/followers","following_url":"https://api.github.com/users/romainfrancois/following{/other_user}","gists_url":"https://api.github.com/users/romainfrancois/gists{/gist_id}","starred_url":"https://api.github.com/users/romainfrancois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romainfrancois/subscriptions","organizations_url":"https://api.github.com/users/romainfrancois/orgs","repos_url":"https://api.github.com/users/romainfrancois/repos","events_url":"https://api.github.com/users/romainfrancois/events{/privacy}","received_events_url":"https://api.github.com/users/romainfrancois/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-05T14:02:59Z","updated_at":"2018-03-05T15:41:04Z","closed_at":null,"author_association":"NONE","body":"This is what was troubling https://github.com/tidyverse/dplyr/issues/3349\r\n\r\nNot sure this is a broom issue, might be a legacy from `lm`, just passing the 🏀 along. \r\n\r\n``` r\r\nlibrary(broom)\r\nlibrary(purrr)\r\n\r\nobjects <- lm(y~ ., data=freeny) %>% \r\n  augment() %>% \r\n  keep(is.object)\r\n\r\nobjects %>% \r\n  map(class)\r\n#> $y\r\n#> [1] \"numeric\"\r\n#> \r\n#> $.resid\r\n#> [1] \"numeric\"\r\n#> \r\n#> $.cooksd\r\n#> [1] \"numeric\"\r\n#> \r\n#> $.std.resid\r\n#> [1] \"numeric\"\r\n\r\nobjects %>% \r\n  map(attr, \"class\")\r\n#> $y\r\n#> NULL\r\n#> \r\n#> $.resid\r\n#> NULL\r\n#> \r\n#> $.cooksd\r\n#> NULL\r\n#> \r\n#> $.std.resid\r\n#> NULL\r\n```\r\n\r\nCreated on 2018-03-05 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0)."},"comment":{"url":"https://api.github.com/repos/tidyverse/broom/issues/comments/370460183","html_url":"https://github.com/tidyverse/broom/issues/287#issuecomment-370460183","issue_url":"https://api.github.com/repos/tidyverse/broom/issues/287","id":370460183,"user":{"login":"MichaelChirico","id":7606389,"avatar_url":"https://avatars1.githubusercontent.com/u/7606389?v=4","gravatar_id":"","url":"https://api.github.com/users/MichaelChirico","html_url":"https://github.com/MichaelChirico","followers_url":"https://api.github.com/users/MichaelChirico/followers","following_url":"https://api.github.com/users/MichaelChirico/following{/other_user}","gists_url":"https://api.github.com/users/MichaelChirico/gists{/gist_id}","starred_url":"https://api.github.com/users/MichaelChirico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichaelChirico/subscriptions","organizations_url":"https://api.github.com/users/MichaelChirico/orgs","repos_url":"https://api.github.com/users/MichaelChirico/repos","events_url":"https://api.github.com/users/MichaelChirico/events{/privacy}","received_events_url":"https://api.github.com/users/MichaelChirico/received_events","type":"User","site_admin":false},"created_at":"2018-03-05T15:41:04Z","updated_at":"2018-03-05T15:41:04Z","author_association":"NONE","body":"Since I didn't catch all of what was going on from the above, here's what's happening:\r\n\r\n```\r\nis.object(freeny$y)\r\n# [1] TRUE\r\nattr(freeny$y, 'class')\r\n# [1] \"ts\"\r\nclass(freeny$y)\r\n# [1] \"ts\"\r\n\r\n# ts attribute wiped by model.frame\r\nclass(model.frame(y ~ ., data = freeny)$y)\r\n# [1] \"numeric\"\r\nattr(model.frame(y ~ ., data = freeny)$y, 'class')\r\n# NULL\r\n\r\n# but still:\r\nis.object(model.frame(y ~ ., data = freeny)$y)\r\n# [1] TRUE\r\n```\r\n\r\nThis is actually _partially_ documented behavior of `stats::model.frame.default`:\r\n\r\n> Unless `na.action = NULL`, time-series attributes will be removed from the variables found (since they will be wrong if `NA`s are removed).\r\n\r\nAnd lo and behold:\r\n\r\n```\r\nclass(model.frame(y ~ ., data = freeny, na.action = NULL)$y)\r\n# [1] \"ts\"\r\n```\r\n\r\nThe unexpected part is that the attributes have been removed, but `is.object` remains `TRUE`.  This sounds to me like a bug; here is the guilty line:\r\n\r\n```\r\n# before this, class(data$y) is 'ts'\r\ndata <- .External2(C_modelframe, formula, rownames, variables, \r\n    varnames, extras, extranames, subset, na.action)\r\n# now, it's 'numeric'\r\n```\r\n\r\nFor conciseness, we can reproduce this by taking\r\n\r\n```\r\nformula = y ~ lag.quarterly.revenue + price.index + income.level + market.potential\r\nrownames = c(\"1962.25\", \"1962.5\", \"1962.75\", \"1963\", \"1963.25\", \"1963.5\", \"1963.75\", \"1964\", \"1964.25\", \"1964.5\", \"1964.75\", \"1965\", \"1965.25\", \"1965.5\", \"1965.75\", \"1966\", \"1966.25\", \"1966.5\", \"1966.75\", \r\n\"1967\", \"1967.25\", \"1967.5\", \"1967.75\", \"1968\", \"1968.25\", \"1968.5\", \"1968.75\", \"1969\", \"1969.25\", \"1969.5\", \"1969.75\", \"1970\", \"1970.25\", \"1970.5\", \"1970.75\", \"1971\", \"1971.25\", \"1971.5\", \"1971.75\")\r\nvariables = list(structure(c(8.79236, 8.79137, 8.81486, 8.81301, 8.90751, 8.93673, 8.96161, 8.96044, 9.00868, 9.03049, 9.06906, 9.05871, 9.10698, 9.12685, 9.17096, 9.18665, 9.23823, 9.26487, 9.28436, \r\n9.31378, 9.35025, 9.35835, 9.39767, 9.4215, 9.44223, 9.48721, 9.52374, 9.5398, 9.58123, 9.60048, 9.64496, 9.6439, 9.69405, 9.69958, 9.68683, 9.71774, 9.74924, 9.77536, 9.79424), .Tsp = c(1962.25, \r\n1971.75, 4), class = \"ts\"), c(8.79636, 8.79236, 8.79137, 8.81486, 8.81301, 8.90751, 8.93673, 8.96161, 8.96044, 9.00868, 9.03049, 9.06906, 9.05871, 9.10698, 9.12685, 9.17096, 9.18665, 9.23823, \r\n9.26487, 9.28436, 9.31378, 9.35025, 9.35835, 9.39767, 9.4215, 9.44223, 9.48721, 9.52374, 9.5398, 9.58123, 9.60048, 9.64496, 9.6439, 9.69405, 9.69958, 9.68683, 9.71774, 9.74924, 9.77536), c(4.70997, 4.70217, 4.68944, 4.68558, 4.64019, 4.62553, 4.61991, 4.61654, 4.61407, 4.60766, 4.60227, 4.5896, 4.57592, 4.58661, 4.57997, 4.57176, 4.56104, 4.54906, 4.53957, 4.51018, 4.50352, 4.4936, 4.46505, 4.44924, 4.43966, 4.42025, 4.4106, 4.41151, 4.3981, 4.38513, 4.3732, 4.3277, 4.32023, 4.30909, 4.30909, 4.30552, 4.29627, 4.27839, 4.27789), c(5.8211, 5.82558, 5.83112, 5.84046, 5.85036, 5.86464, 5.87769, 5.89763, 5.92574, 5.94232, 5.95365, 5.9612, 5.97805, 6.00377, 6.02829, 6.03475, 6.03906, 6.05046, 6.05563, 6.06093, 6.07103, 6.08018, 6.08858, 6.10199, 6.11207, 6.11596, 6.12129, 6.122, 6.13119, 6.14705, 6.15336, 6.15627, 6.16274, 6.17369, 6.16135, 6.18231, 6.18768, 6.19377, 6.2003), c(12.9699, 12.9733, 12.9774, 12.9806, 12.9831, 12.9854, 12.99, 12.9943, 12.9992, 13.0033, 13.0099, 13.0159, 13.0212, 13.0265, 13.0351, 13.0429, 13.0497, 13.0551, 13.0634, 13.0693, 13.0737, 13.077, 13.0849, 13.0918, 13.095, 13.0984, 13.1089, 13.1169, 13.1222, 13.1266, 13.1356, 13.1415, 13.1444, 13.1459, 13.152, 13.1593, 13.1579, 13.1625, 13.1664))\r\nvarnames = c(\"y\", \"lag.quarterly.revenue\", \"price.index\", \"income.level\", \"market.potential\")\r\nextras = list()\r\nextranames = NULL\r\nsubset = NULL\r\nna.action = 'na.omit'\r\n```\r\n\r\nThen comparing\r\n```\r\nclass(.External2(stats:::C_modelframe, formula, rownames, variables, varnames, extras, extranames, subset, na.action)$y)\r\n# [1] \"numeric\"\r\nclass(.External2(stats:::C_modelframe, formula, rownames, variables, varnames, extras, extranames, subset, NULL)$y)\r\n# [1] \"ts\"\r\n```"}}
{"actor":{"display_login":"MichaelChirico"}}