davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
562 stars 81 forks source link

enable paragraph() class as input for add_footer_lines() #466

Closed patrickvdb closed 2 years ago

patrickvdb commented 2 years ago

Since I updated flextable I receive this message:

Usage of empty symbol '' with footnote should not happen, use `add_footer_lines()` instead, it does not require any symbol. This usage will be forbidden in the next release. Please, wait for 10 seconds!

I am using footnote() with an empty ref_symbol as a workaround for using paragraph styling in the footnote section. I want to be able to use superscript/subscript in the footer section which works fine with footnote()

davidgohel commented 2 years ago

Can you share a reprex so that I can propose a solution?

patrickvdb commented 2 years ago
library(reprex)
library(flextable)
library(magrittr)

flextable(cars) %>% 
  add_footer_lines("footnote without superscript")
flextable(cars) %>% 
  footnote(i =1,
           j = 1, 
           as_paragraph("footnote with ", as_sup("superscript"), "!"), 
           ref_symbols = "")
#> Usage of empty symbol '' with footnote should not happen, use `add_footer_lines()` instead, it does not require any symbol. This usage will be forbidden in the next release. Please, wait for 10 seconds!
flextable(cars) %>% 
  add_footer_lines(as_paragraph("add_footer_lines doesn't allow as_paragraph.."))
#> Error in inverse.rle(structure(list(lengths = colwidths, values = values), : invalid 'rle' structure

sessionInfo()
#> R version 4.1.3 (2022-03-10)
#> Platform: x86_64-redhat-linux-gnu (64-bit)
#> Running under: Red Hat Enterprise Linux 8.5 (Ootpa)
#> 
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.15.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] magrittr_2.0.3  flextable_0.8.1 reprex_2.0.2   
#> 
#> loaded via a namespace (and not attached):
#>  [1] zip_2.2.0         Rcpp_1.0.8.3      pillar_1.7.0      compiler_4.1.3   
#>  [5] highr_0.9         R.methodsS3_1.8.2 R.utils_2.12.0    base64enc_0.1-3  
#>  [9] tools_4.1.3       uuid_1.1-0        digest_0.6.29     jsonlite_1.8.0   
#> [13] evaluate_0.15     lifecycle_1.0.1   tibble_3.1.7      R.cache_0.16.0   
#> [17] pkgconfig_2.0.3   rlang_1.0.5       cli_3.3.0         rstudioapi_0.13  
#> [21] yaml_2.3.5        xfun_0.31         fastmap_1.1.0     xml2_1.3.3       
#> [25] officer_0.4.4     withr_2.5.0       styler_1.7.0      stringr_1.4.0    
#> [29] knitr_1.39        systemfonts_1.0.4 gdtools_0.2.4     fs_1.5.2         
#> [33] vctrs_0.4.1       webshot_0.5.3     grid_4.1.3        glue_1.6.2       
#> [37] data.table_1.14.2 R6_2.5.1          processx_3.6.1    fansi_1.0.3      
#> [41] rmarkdown_2.14    callr_3.7.1       purrr_0.3.4       ps_1.7.1         
#> [45] ellipsis_0.3.2    htmltools_0.5.2   utf8_1.2.2        stringi_1.7.6    
#> [49] crayon_1.5.1      R.oo_1.25.0

Created on 2022-09-20 with reprex v2.0.2

NOTE: the tables don't show in this md

davidgohel commented 2 years ago

Thanks,

I'll add support for as_paragraph in add_footer_lines/add_header_lines in the next release.

Meanwhile, here are two workarounds:

library(reprex)
library(flextable)
library(magrittr)

ft01 <- fp_text_default(color = "orange")
ft02 <- fp_text_default(color = "red", vertical.align = "superscript")

## WA 1
flextable(head(cars)) %>% 
  add_footer_lines("add_footer_lines doesn't allow as_paragraph.") %>% 
  prepend_chunks(i = nrow_part(., "footer"), j = 1, as_chunk("++++", props = ft02), part = "footer")
Capture d’écran 2022-09-20 à 14 43 19
## WA 2
flextable(head(cars)) %>% 
  add_footer_lines("") %>% 
  mk_par(
    i = nrow_part(., "footer"), j = 1, 
    value = as_paragraph(
      as_chunk("*******", props = ft02), 
      as_chunk("add_footer_lines doesn't allow as_paragraph.", props = ft01)
    ), part = "footer")
Capture d’écran 2022-09-20 à 14 43 05
davidgohel commented 2 years ago

It's now available:

library(flextable)

ft01 <- fp_text_default(color = "red")
ft02 <- fp_text_default(color = "orange")
ref <- c("(1)", "(2)")
pars <- as_paragraph(
  as_chunk(ref, props = ft02), " ",
  as_chunk(rep("My tailor is rich", length(ref)), props = ft01)
)

ft_1 <- flextable(head(mtcars))
ft_1 <- add_header_lines(ft_1, values = pars, top = FALSE)
ft_1 <- add_header_lines(ft_1, values = ref, top = TRUE)
ft_1 <- add_footer_lines(ft_1, values = "blah", top = TRUE)
ft_1 <- add_footer_lines(ft_1, values = pars, top = TRUE)
ft_1 <- add_footer_lines(ft_1, values = ref, top = FALSE)
ft_1 <- autofit(ft_1)
ft_1
Capture d’écran 2022-10-17 à 21 50 01
github-actions[bot] commented 1 year ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.