Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing with 0 rows print output is an error #238

Closed
averissimo opened this issue Dec 16, 2024 · 4 comments
Closed

Listing with 0 rows print output is an error #238

averissimo opened this issue Dec 16, 2024 · 4 comments
Labels
bug Something isn't working sme

Comments

@averissimo
Copy link
Contributor

averissimo commented Dec 16, 2024

Summary

rlisitings allows the creation of a listing with 0 rows, but with columns defined, however it gives an error when printing it.

It would be nice to print an empty table or with "No data available." replacing the empty row's content (similar to {DT}).

result <- tibble::tibble(col1 = character(0L), col2 = character(0L), col3 = character(0L))

listing <- rlistings::as_listing(result)

sprintf("Rows: %d // Columns: %d", nrow(listing), ncol(listing))
#> [1] "Rows: 0 // Columns: 3"
print(listing)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'toString': (subscript) logical subscript too long

Created on 2024-12-16 with reprex v2.1.1

R session info

R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_IE.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_IE.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_IE.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_IE.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Lisbon
tzcode source: system (glibc)

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

other attached packages:
 [1] teal.modules.clinical_0.9.1.9040 dplyr_1.1.4                      testthat_3.2.1.1                 tern_0.9.6.9017                 
 [5] rtables_0.6.10.9010              magrittr_2.0.3                   formatters_0.5.9.9005            teal.transform_0.5.0.9016       
 [9] teal_0.15.2.9091                 teal.slice_0.5.1.9016            teal.data_0.6.0.9021             teal.code_0.5.0.9020            
[13] shiny_1.9.1                     

loaded via a namespace (and not attached):
  [1] rstudioapi_0.17.1          jsonlite_1.8.8             nestcolor_0.1.2.9017       estimability_1.5.1         farver_2.1.2              
  [6] rmarkdown_2.29             fs_1.6.4                   geepack_1.3.12             ragg_1.3.2                 vctrs_0.6.5               
 [11] memoise_2.0.1              askpass_1.2.0              htmltools_0.5.8.1          forcats_1.0.0              curl_5.2.3                
 [16] broom_1.0.7                sass_0.4.9                 parallelly_1.37.1          bslib_0.7.0                htmlwidgets_1.6.4         
 [21] desc_1.4.3                 fontawesome_0.5.2          emmeans_1.10.5             plotly_4.10.4              cachem_1.1.0              
 [26] uuid_1.2-0                 TMB_1.9.15                 mime_0.12                  lifecycle_1.0.4            teal.widgets_0.4.2.9024   
 [31] pkgconfig_2.0.3            Matrix_1.7-1               R6_2.5.1                   fastmap_1.2.0              rbibutils_2.2.16          
 [36] rlistings_0.2.9.9010       digest_0.6.35              colorspace_2.1-0           ps_1.7.6                   shinycssloaders_1.0.0     
 [41] rprojroot_2.0.4            pkgload_1.4.0              textshaping_0.4.0          crosstalk_1.2.1            labeling_0.4.3            
 [46] fansi_1.0.6                httr_1.4.7                 compiler_4.4.2             fontquiver_0.2.1           withr_3.0.2               
 [51] backports_1.5.0            logger_0.4.0               pkgbuild_1.4.4             MASS_7.3-61                openssl_2.2.0             
 [56] gfonts_0.2.0               tools_4.4.2                zip_2.3.1                  httpuv_1.6.15              shinyvalidate_0.1.3       
 [61] clipr_0.8.0                glue_1.7.0                 callr_3.7.6                nlme_3.1-166               promises_1.3.0            
 [66] mmrm_0.3.14.9001           grid_4.4.2                 checkmate_2.3.2            rtables.officer_0.0.1.9008 generics_0.1.3            
 [71] gtable_0.3.5               tidyr_1.3.1                data.table_1.15.4          xml2_1.3.6                 utf8_1.2.4                
 [76] ggrepel_0.9.6              pillar_1.9.0               later_1.3.2                splines_4.4.2              tern.gee_0.1.5.9004       
 [81] lattice_0.22-6             renv_1.0.5                 survival_3.7-0             tidyselect_1.2.1           fontLiberation_0.1.0      
 [86] tern.mmrm_0.3.2.9002       knitr_1.49                 fontBitstreamVera_0.1.1    teal.logger_0.3.0.9002     crul_1.4.2                
 [91] xfun_0.49                  brio_1.1.5                 DT_0.33                    stringi_1.8.4              lazyeval_0.2.2            
 [96] yaml_2.3.8                 httpcode_0.3.0             shinyWidgets_0.8.7         evaluate_0.23              officer_0.6.6             
[101] gdtools_0.3.7              tibble_3.2.1               BiocManager_1.30.23        cli_3.6.2                  xtable_1.8-4              
[106] systemfonts_1.1.0          Rdpack_2.6                 processx_3.8.4             munsell_0.5.1              jquerylib_0.1.4           
[111] Rcpp_1.0.12                teal.reporter_0.3.1.9018   vistime_1.2.4              parallel_4.4.2             ggplot2_3.5.1             
[116] assertthat_0.2.1           reprex_2.1.1               viridisLite_0.4.2          mvtnorm_1.2-5              scales_1.3.0              
[121] purrr_1.0.2                crayon_1.5.2               flextable_0.9.6            rlang_1.1.3                cowplot_1.1.3             
[126] shinyjs_2.1.0 

OS / Environment

  • OS: Ubuntu 24.10
@Melkiades
Copy link
Contributor

I think @BFalquet has a workaround ready for this in chevron, right?

@Melkiades Melkiades added the sme label Dec 26, 2024
@BFalquet
Copy link

BFalquet commented Jan 5, 2025

You can for instance use:

library(rlistings)
result <- tibble::tibble(col1 = character(0L), col2 = character(0L), col3 = character(0L))
listing <- rlistings::as_listing(result)
chevron::report_null(listing)
                                                                                        
#>   ————————————————————————————————————————————————————————————————————————————————————————
#>      Null Report: No observations met the reporting criteria for inclusion in this output.

Created on 2025-01-05 with reprex v2.1.1

Feel free to add the issue on Overflow

@averissimo
Copy link
Contributor Author

Thanks @BFalquet, that is solved locally just as I'm doing with {tmc}/{tmg},

https://github.com/insightsengineering/teal.modules.clinical/blob/dccf80fd227c35df6239592d2ab0ed1230395ff9/R/tm_t_pp_prior_medication.R#L394-L398

@Melkiades I still think this issue on this repo is relevant here as the print method should:

  • show an empty table
  • a default message
  • an error that is a bit more self-explanatory.

@shajoezhu
Copy link
Collaborator

shajoezhu commented Jan 7, 2025

hi @averissimo

so the ask is to improve the print.listing_df function

print.listing_df <- function(x, widths = NULL, tf_wrap = FALSE, max_width = NULL, fontspec = NULL, col_gap = 3L, ...) {

such that we can perform a check on in this listing is empty, i.e. 0 rows, then it prints out something like
"No data available"

and you do not want this to throw an error? or you do it want it throw an error that can be caught

I incline to throw an error

shajoezhu added a commit that referenced this issue Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sme
Projects
None yet
Development

No branches or pull requests

4 participants