Skip to content

[Bug]: strange title wrapping for grobs #1287

@BFalquet

Description

@BFalquet

What happened?

example:

library(chevron)
library(citril)

# Create a list of ggplot objects
graph <- chevron::run(chevron::mng01, chevron::syn_data, dataset = "adlb")

# decorate with a long title and subtitle
res <- decorate_tlg(
        graph,
        main = append_filter_title(
          paste("My", paste(rep("very", 55), collapse = " "), "long title"),
          suffix = c("PP", "SE", "CNCM", "PAXIS"),
          targets = c("adsl", "adcm")
        ),
        sub = paste("My", paste(rep("very", 55), collapse = " "), "long subtitle"),
        footnote = paste("My", paste(rep("very", 100), collapse = " "), "long footnote"),
        sup_footnote = paste("My", paste(rep("very", 100), collapse = " "), "long supplementary footnote")
      )


# extract the title from the grob
lab <- res[[1]]$children$titles_grob_footnotes$children[[1]]$label

# the length of the individual lines in the title has changes and is a bit surprising
    wrapped_lab <- stringr::str_split(lab, "\\n", simplify = FALSE)
    expect_identical(nchar(wrapped_lab[[1]]), c(182L, 180L, 182L, 108L))


# Error: nchar(wrapped_lab[[1]]) (`actual`) not identical to c(182L, 180L, 182L, 108L) (`expected`).
#
#  `actual`: 172 166  23 147 143
#  `expected`: 182 180 182 108   

The error seems to arise in tern::decorate_grob_set(), the concatenation of the title and subtitle let the system think that the line is longer than it actually is.

thank you for the help

image

sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_Switzerland.utf8  LC_CTYPE=English_Switzerland.utf8    LC_MONETARY=English_Switzerland.utf8 LC_NUMERIC=C                        
[5] LC_TIME=English_Switzerland.utf8    

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
[1] citril_0.1.12.9012 testthat_3.1.10   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0           dplyr_1.1.2                farver_2.1.1               R.utils_2.12.2             fastmap_1.1.1              vdiffr_1.0.7              
 [7] digest_0.6.33              timechange_0.2.0           lifecycle_1.0.3            waldo_0.5.1                ellipsis_0.3.2             survival_3.5-5            
[13] processx_3.8.2             magrittr_2.0.3             compiler_4.3.1             rlang_1.1.1                tools_4.3.1                utf8_1.2.3                
[19] yaml_2.3.7                 prettyunits_1.1.1          labeling_0.4.2             pkgbuild_1.4.2             pkgload_1.3.2.1            R.cache_0.16.0            
[25] withr_2.5.0                purrr_1.0.1                rlistings_0.2.9.9002       desc_1.4.2                 R.oo_1.25.0                grid_4.3.1                
[31] fansi_1.0.4                diffobj_0.3.5              colorspace_2.1-0           nestcolor_0.1.2.9014       ggplot2_3.5.1              scales_1.3.0              
[37] cli_3.6.1                  crayon_1.5.2               generics_0.1.3             remotes_2.4.2              rstudioapi_0.15.0          sessioninfo_1.2.2         
[43] cachem_1.0.8               stringr_1.5.0              splines_4.3.1              vctrs_0.6.3                devtools_2.4.5.9000        Matrix_1.6-0              
[49] jsonlite_1.8.7             dunlin_0.1.7.9007          tern_0.9.5.9013            callr_3.7.3                tidyr_1.3.0                rtables_0.6.9.9007        
[55] formatters_0.5.8.9003      glue_1.6.2                 rematch2_2.1.2             ps_1.7.5                   cowplot_1.1.1              lubridate_1.9.2           
[61] stringi_1.7.12             gtable_0.3.3               munsell_0.5.0              tibble_3.2.1               styler_1.10.3              pillar_1.9.0              
[67] htmltools_0.5.5            brio_1.1.3                 citril.metadata_0.1.7.9003 R6_2.5.1                   Rdpack_2.4                 rprojroot_2.0.3           
[73] lattice_0.21-8             rbibutils_2.2.13           R.methodsS3_1.8.2          backports_1.4.1            memoise_2.0.1              broom_1.0.5               
[79] checkmate_2.2.0            chevron_0.2.6.9013         fs_1.6.2                   forcats_1.0.0              usethis_2.2.2              pkgconfig_2.0.3

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsme

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions