Skip to content

augment error with na.action = na.exclude in glm #1270

@gavinsimpson

Description

@gavinsimpson

The problem

augment throws an error for a GLM fitted with glm() where there are NAs in the data when data is supplied and na.action = na.exclude, contrary to the documented behaviour.

Reproducible example

# from ?glm
library("broom")
clotting <- data.frame(
    u = c(5,10,15,20,30,40,60,80,100),
    lot1 = c(118,58,42,35,27,25,21,19,18),
    lot2 = c(69,35,26,21,18,16,13,12,12))
# make one value of `u` and `lot1` missing
take <- withr::with_seed(2, sample(nrow(clotting), 2))
clotting[take[1], "u"] <- NA
clotting[take[2], "lot1"] <- NA
# fit GLM
m <- glm(lot1 ~ log(u), data = clotting, family = Gamma, na.action = na.exclude)
# na.action has worked
identical(length(fitted(m)), nrow(clotting))
#> [1] TRUE
# augment fails
augment(m, data = clotting)
#> Error in `$<-`:
#> ! Assigned data `unname(predict(x, newdata, type = type.predict))` must
#>   be compatible with existing data.
#> ✖ Existing data has 9 rows.
#> ✖ Assigned data has 7 rows.
#> ℹ Only vectors of size 1 are recycled.
#> Caused by error in `vectbl_recycle_rhs_rows()`:
#> ! Can't recycle input of size 7 to size 9.

Created on 2026-04-14 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.3 (2026-03-11)
#>  os       macOS Tahoe 26.3
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  C.UTF-8
#>  ctype    C.UTF-8
#>  tz       Europe/Copenhagen
#>  date     2026-04-14
#>  pandoc   3.9.0.2 @ /opt/homebrew/bin/ (via rmarkdown)
#>  quarto   1.9.36 @ /Applications/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  backports     1.5.0   2024-05-23 [1] CRAN (R 4.5.0)
#>  broom       * 1.0.12  2026-01-27 [1] CRAN (R 4.5.2)
#>  cli           3.6.5   2025-04-23 [1] CRAN (R 4.5.0)
#>  digest        0.6.39  2025-11-19 [1] CRAN (R 4.5.2)
#>  dplyr         1.2.0   2026-02-03 [1] CRAN (R 4.5.2)
#>  evaluate      1.0.5   2025-08-27 [1] CRAN (R 4.5.0)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.5.0)
#>  fs            2.0.1   2026-03-24 [1] CRAN (R 4.5.2)
#>  generics      0.1.4   2025-05-09 [1] CRAN (R 4.5.0)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.5.0)
#>  htmltools     0.5.9   2025-12-04 [1] CRAN (R 4.5.2)
#>  knitr         1.51    2025-12-20 [1] CRAN (R 4.5.2)
#>  lifecycle     1.0.5   2026-01-08 [1] CRAN (R 4.5.2)
#>  magrittr      2.0.4   2025-09-12 [1] CRAN (R 4.5.0)
#>  otel          0.2.0   2025-08-29 [1] CRAN (R 4.5.0)
#>  pillar        1.11.1  2025-09-17 [1] CRAN (R 4.5.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.5.0)
#>  purrr         1.2.1   2026-01-09 [1] CRAN (R 4.5.2)
#>  R6            2.6.1   2025-02-15 [1] CRAN (R 4.5.0)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.5.0)
#>  rlang         1.1.7   2026-01-09 [1] CRAN (R 4.5.2)
#>  rmarkdown     2.30    2025-09-28 [1] CRAN (R 4.5.0)
#>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.5.0)
#>  tibble        3.3.1   2026-01-11 [1] CRAN (R 4.5.2)
#>  tidyr         1.3.2   2025-12-19 [1] CRAN (R 4.5.2)
#>  tidyselect    1.2.1   2024-03-11 [1] CRAN (R 4.5.0)
#>  vctrs         0.7.2   2026-03-21 [1] CRAN (R 4.5.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.5.0)
#>  xfun          0.57    2026-03-20 [1] CRAN (R 4.5.2)
#>  yaml          2.3.12  2025-12-10 [1] CRAN (R 4.5.2)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions