Skip to content

partial(lm) prints lm source #707

@dpprdan

Description

@dpprdan

partial(lm) prints this:

lmi <- purrr::partial(lm, data = mtcars)
lmi(mpg ~ wt)
#> 
#> Call:
#> (function (formula, data, subset, weights, na.action, method = "qr", 
#>     model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
#>     contrasts = NULL, offset, ...) 
#> {
#>     ret.x <- x
#>     ret.y <- y
#>     cl <- match.call()
#>     mf <- match.call(expand.dots = FALSE)
#>     m <- match(c("formula", "data", "subset", "weights", "na.action", 
#>         "offset"), names(mf), 0L)
#>     mf <- mf[c(1L, m)]
#>     mf$drop.unused.levels <- TRUE
#>     mf[[1L]] <- quote(stats::model.frame)
#>     mf <- eval(mf, parent.frame())
#>     if (method == "model.frame") 
#>         return(mf)
#>     else if (method != "qr") 
#>         warning(gettextf("method = '%s' is not supported. Using 'qr'", 
#>             method), domain = NA)
#>     mt <- attr(mf, "terms")
#>     y <- model.response(mf, "numeric")
#>     w <- as.vector(model.weights(mf))
#>     if (!is.null(w) && !is.numeric(w)) 
#>         stop("'weights' must be a numeric vector")
#>     offset <- model.offset(mf)
#>     mlm <- is.matrix(y)
#>     ny <- if (mlm) 
#>         nrow(y)
#>     else length(y)
#>     if (!is.null(offset)) {
#>         if (!mlm) 
#>             offset <- as.vector(offset)
#>         if (NROW(offset) != ny) 
#>             stop(gettextf("number of offsets is %d, should equal %d (number of observations)", 
#>                 NROW(offset), ny), domain = NA)
#>     }
#>     if (is.empty.model(mt)) {
#>         x <- NULL
#>         z <- list(coefficients = if (mlm) matrix(NA_real_, 0, 
#>             ncol(y)) else numeric(), residuals = y, fitted.values = 0 * 
#>             y, weights = w, rank = 0L, df.residual = if (!is.null(w)) sum(w != 
#>             0) else ny)
#>         if (!is.null(offset)) {
#>             z$fitted.values <- offset
#>             z$residuals <- y - offset
#>         }
#>     }
#>     else {
#>         x <- model.matrix(mt, mf, contrasts)
#>         z <- if (is.null(w)) 
#>             lm.fit(x, y, offset = offset, singular.ok = singular.ok, 
#>                 ...)
#>         else lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok, 
#>             ...)
#>     }
#>     class(z) <- c(if (mlm) "mlm", "lm")
#>     z$na.action <- attr(mf, "na.action")
#>     z$offset <- offset
#>     z$contrasts <- attr(x, "contrasts")
#>     z$xlevels <- .getXlevels(mt, mf)
#>     z$call <- cl
#>     z$terms <- mt
#>     if (model) 
#>         z$model <- mf
#>     if (ret.x) 
#>         z$x <- x
#>     if (ret.y) 
#>         z$y <- y
#>     if (!qr) 
#>         z$qr <- NULL
#>     z
#> })(formula = ..1, data = mtcars)
#> 
#> Coefficients:
#> (Intercept)           wt  
#>      37.285       -5.344

But ideally, it should print something like this.

lm(mpg ~ wt, data = mtcars)
#> 
#> Call:
#> lm(formula = mpg ~ wt, data = mtcars)
#> 
#> Coefficients:
#> (Intercept)           wt  
#>      37.285       -5.344

FWIW: I've used partial like this ca. mid-2018 (cannot recall the exact purrr version) and it did not print the lm source then.

Possibly related to #656?

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language en                          
#>  collate  German_Germany.1252         
#>  ctype    German_Germany.1252         
#>  tz       Europe/Berlin               
#>  date     2019-09-18                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.1)                
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)                
#>  callr         3.3.1      2019-07-18 [1] CRAN (R 3.6.1)                
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.1)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.1)                
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.1)                
#>  devtools      2.2.0      2019-09-07 [1] CRAN (R 3.6.1)                
#>  digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.1)                
#>  DT            0.9        2019-09-17 [1] CRAN (R 3.6.1)                
#>  ellipsis      0.2.0.1    2019-07-02 [1] CRAN (R 3.6.1)                
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.1)                
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.1)                
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.1)                
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.1)                
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.1)                
#>  htmlwidgets   1.3        2018-09-30 [1] CRAN (R 3.6.1)                
#>  knitr         1.25       2019-09-18 [1] CRAN (R 3.6.1)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.1)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.1)                
#>  pkgbuild      1.0.5      2019-08-26 [1] CRAN (R 3.6.1)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.1)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.1)                
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.1)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.1)                
#>  purrr         0.3.2      2019-03-15 [1] CRAN (R 3.6.1)                
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.1)                
#>  Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.6.1)                
#>  remotes       2.1.0.9000 2019-07-22 [1] Github (r-lib/remotes@6e9eaa9)
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.6.1)                
#>  rmarkdown     1.15       2019-08-21 [1] CRAN (R 3.6.1)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.1)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.1)                
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.1)                
#>  testthat      2.2.1      2019-07-25 [1] CRAN (R 3.6.1)                
#>  usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.1)                
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.1)                
#>  xfun          0.9        2019-08-21 [1] CRAN (R 3.6.1)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                
#> 
#> [1] C:/Users/daniel/Documents/.R/win-library
#> [2] C:/Program Files/R/R-3.6.1/library

Metadata

Metadata

Assignees

No one assigned

    Labels

    adverb 📚bugan unexpected problem or unintended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions