Skip to content

cols_width specifications and as_gtable #1771

@srcm-mark

Description

@srcm-mark

Prework

Description

Hello, all:

Thanks so very much for the as_gtable update. As I was converting code to take advantage of this new feature, I have found that the as_gtable step seems to break on a table that includes a cols_width specification using pct(). The error arises when setting a single column to a value < 100, or multiple columns to values <= 100.

Reproducible example

library(gt)

start_date <- "2010-06-07"
end_date <- "2010-06-08"

sp_tab <- 
  sp500 |>
  dplyr::filter(date >= start_date & date <= end_date) |>
  gt() |>
  cols_width(date ~ pct(50))

sp_tab |> as_gtable()
#> Warning in parse_px_to_pt(column_width[fixed]): NAs introduced by coercion
#> Error in if (extra_width < 0) {: missing value where TRUE/FALSE needed

Created on 2024-07-11 with reprex v2.1.1

Session info
sessionInfo()
#> R version 4.3.3 (2024-02-29 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows Server 2019 x64 (build 19045)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/Los_Angeles
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] gt_0.11.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.5       cli_3.6.3         knitr_1.48        rlang_1.1.4      
#>  [5] xfun_0.45         generics_0.1.3    glue_1.7.0        htmltools_0.5.8.1
#>  [9] sass_0.4.9        fansi_1.0.6       rmarkdown_2.27    grid_4.3.3       
#> [13] evaluate_0.24.0   tibble_3.2.1      fastmap_1.2.0     yaml_2.3.9       
#> [17] lifecycle_1.0.4   compiler_4.3.3    dplyr_1.1.4       fs_1.6.4         
#> [21] pkgconfig_2.0.3   rstudioapi_0.16.0 digest_0.6.36     R6_2.5.1         
#> [25] reprex_2.1.1      tidyselect_1.2.1  utf8_1.2.4        pillar_1.9.0     
#> [29] magrittr_2.0.3    gtable_0.3.5      tools_4.3.3       withr_3.0.0      
#> [33] xml2_1.3.6

Expected result

I would expect the result to reflect specific column width assignment prior to output via as_gtable. Without the cols_width set, tables output as expected using as_gtable. With cols_width set, none does.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions