Skip to content

Impossible to pass a variable from lapply into the argument fns in summary_rows / grand_summary_rows #2098

Open

Description

@stauffacherch-bot

Description

Impossible to pass a variable into the argument fns in summary_rows. I woud like to iterate over the columns Sepal.Length and Petal.Length and generate a summary (a mean value, for instance) for them. See also this related answer to this question at SO:

Reproducible example

library(gt)
lapply(c("Sepal", "Petal"),
         \(x)summary_rows(head(iris) |> dplyr::group_by(Species) |> gt(),
  columns = paste0(x, ".Length"),
  fns= list(Mean ~ mean(get(paste0(x, ".Length"))))
  )
)

Error in `summarise()`:
ℹ In argument: `Sepal.Length = (structure(function (..., .x = ..1, .y =
  ..2, . = ..1) ...`.
ℹ In group 1: `::group_id:: = "setosa"`.
Caused by error:
! object 'x' not found
Run `rlang::last_trace()` to see where the error occurred.

Expected result

The code should calculate the mean value of the subset of the columns Sepal.Length and Petal.Length (4.95 and 1.45, respectively),

Session info

R version 4.5.1 (2025-06-13)
Platform: wasm32-unknown-emscripten (32-bit)
Running under: emscripten

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] de_DE.UTF-8 C           de_DE.UTF-8 de_DE.UTF-8 de_DE.UTF-8 C          

time zone: Europe/Berlin
tzcode source: internal

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

other attached packages:
[1] dplyr_1.1.4 gt_0.11.1  

loaded via a namespace (and not attached):
 [1] digest_0.6.39    R6_2.6.1         fastmap_1.2.0    tidyselect_1.2.1 webr_0.5.6       magrittr_2.0.4   glue_1.8.0      
 [8] tibble_3.3.0     pkgconfig_2.0.3  htmltools_0.5.9  generics_0.1.4   lifecycle_1.0.4  xml2_1.3.6       cli_3.6.5       
[15] sass_0.4.10.9000 vctrs_0.6.5      withr_3.0.2      purrr_1.2.0      tools_4.5.1      pillar_1.11.1    rlang_1.1.6     
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions