vincentarelbundock/modelsummary

Including a call to datasummary_correlation as an argument to datasummary fails with an uninformative error message

mronkko opened this issue · 1 comments

Including a call to datasummary_correlation as an argument to datasummary fails with an uninformative error message. The error message that I get is:

Error in factory_fun(tab, align = align, hrule = hrule, notes = notes, :
could not find function "factory_fun"

This occurs with the GitHub version of modelsummary. I checked the code, and I could not figure out what the problem was. I am attaching a minimal reproducible example and session info.

library(car)             # Prestige data 
library(modelsummary)
library(tidyverse)

# This causes an error

select(Prestige, income, education, women, prestige) %>%
  # The . in the arguments refer to the dataset passed forward by the pipe
  # %>% operator.
  datasummary(All(.) ~ Mean + SD, ., 
              add_columns = datasummary_correlation(., output = "data.frame")[,-1])


# Same without pipe, causes error

data <- select(Prestige, income, education, women, prestige)

datasummary(All(data) ~ Mean + SD, data, 
            add_columns = datasummary_correlation(data, output = "data.frame")[,-1])

# This works

correlations <- datasummary_correlation(data, output = "data.frame")[,-1]

datasummary(All(data) ~ Mean + SD, data, 
            add_columns = correlations)

Sesssioninfo

> sessionInfo()
R version 4.4.1 Patched (2024-07-08 r86915)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.3      forcats_1.0.0        stringr_1.5.1        dplyr_1.1.4          purrr_1.0.2          readr_2.1.5         
 [7] tidyr_1.3.1          tibble_3.2.1         ggplot2_3.5.1        tidyverse_2.0.0      car_3.1-2            carData_3.0-5       
[13] modelsummary_2.1.1.5

loaded via a namespace (and not attached):
 [1] utf8_1.2.4        generics_0.1.3    stringi_1.8.4     hms_1.1.3         digest_0.6.36     magrittr_2.0.3    grid_4.4.1       
 [8] timechange_0.3.0  fastmap_1.2.0     jsonlite_1.8.8    backports_1.5.0   fansi_1.0.6       scales_1.3.0      abind_1.4-5      
[15] cli_3.6.3         rlang_1.1.4       munsell_0.5.1     base64enc_0.1-3   withr_3.0.0       repr_1.1.7        tinytable_0.3.0  
[22] tools_4.4.1       tzdb_0.4.0        checkmate_2.3.2   colorspace_2.1-1  IRdisplay_1.1     vctrs_0.6.5       R6_2.5.1         
[29] lifecycle_1.0.4   insight_0.20.2    pkgconfig_2.0.3   pillar_1.9.0      gtable_0.3.5      data.table_1.15.4 glue_1.7.0       
[36] xfun_0.45         tidyselect_1.2.1  rstudioapi_0.16.0 knitr_1.48        htmltools_0.5.8.1 tables_0.9.28     compiler_4.4.1
``

Thanks for the report. Should be fixed after installing the latest development versions of both tinytable and modelsummary.

Then, restart your R session completely.

Let me know if it's still broken.

Thanks for the report!