insightsengineering / rtables

Reporting tables with R
https://insightsengineering.github.io/rtables/
Other
226 stars 49 forks source link

import export_as_txt from formatters, and remove the current rtables export_as_txt, use staged dependencis 96_exporter_pagination_migration #627

Closed shajoezhu closed 1 year ago

Melkiades commented 1 year ago
✖ | 1      28 | binding [0.9s]                                          
────────────────────────────────────────────────────────────────────────
Error (test-binding.R:142:5): c/rbind and top-left behave
Error in `integer(n)`: invalid 'length' argument
Backtrace:
 1. formatters::matrix_form(cbind_rtables(tab[0, ], tab[0, ]))
      at test-binding.R:142:4
 2. rtables::matrix_form(cbind_rtables(tab[0, ], tab[0, ]))
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters:::splice_fnote_info_in(rowinfo, refdf)
      at formatters/R/matrix_form.R:490:4
 6. base::replicate(nrow(df), list(ref_df_row()[0, ]))
      at formatters/R/matrix_form.R:480:4
 9. base::integer(n)
 ✖ | 1      16 | deprecated functionality [0.7s]                         
────────────────────────────────────────────────────────────────────────
Error (test-deprecated.R:80:5): add_colcounts format argument works
Error in `integer(n)`: invalid 'length' argument
Backtrace:
 1. formatters::matrix_form(tbl1)
      at test-deprecated.R:80:4
 2. rtables::matrix_form(tbl1)
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters:::splice_fnote_info_in(rowinfo, refdf)
      at formatters/R/matrix_form.R:490:4
 6. base::replicate(nrow(df), list(ref_df_row()[0, ]))
      at formatters/R/matrix_form.R:480:4
 9. base::integer(n)
────────────────────────────────────────────────────────────────────────
✖ | 1      22 | Exporters [19.5s]                                       
────────────────────────────────────────────────────────────────────────
Error (test-exporters.R:213:5): flextable export works
Error in `do.call(rbind.data.frame, pagdf$ref_info_df)`: second argument must be a list
Backtrace:
 1. rtables::tt_to_flextable(tbl, paginate = TRUE, lpp = 20)
      at test-exporters.R:213:4
 2. rtables::paginate_table(...)
      at rtables/R/tt_export.R:275:8
 3. rtables::pag_tt_indices(...)
      at rtables/R/tt_paginate.R:774:8
 4. formatters::pag_indices_inner(...)
      at rtables/R/tt_paginate.R:623:4
 5. formatters:::find_pag(...)
      at formatters/R/pagination.R:376:4
 6. formatters:::valid_pag(...)
      at formatters/R/pagination.R:305:2
 7. formatters:::calc_ref_nlines(pagdf[start:guess, ])
      at formatters/R/pagination.R:195:2
 8. base::do.call(rbind.data.frame, pagdf$ref_info_df)
      at formatters/R/pagination.R:166:4
────────────────────────────────────────────────────────────────────────
✖ | 2       6 | value formatting [0.7s]                                 
────────────────────────────────────────────────────────────────────────
Failure (test-formatting.R:40:5): table_shell works
toString(tblsh) not identical to paste0(capture_output(table_shell(tbl)), "\n").
1/1 mismatches
x[1]: "           A             B     \n———————————————————————————————\
x[1]: nHiya   xx (xx.x%)   xx.x - xx.x\nbye      xx.xx         xx.xx   \
x[1]: n"
y[1]: "           A           B    \n————————————————————————————\nHiya 
y[1]:      xx        xx.x -  \n        (xx.x%)      xx.x   \nbye      xx
y[1]: .xx       xx.xx  \n"

Failure (test-formatting.R:56:5): table_shell works
toString(tbl2sh) not identical to paste0(capture_output(table_shell(tbl2)), "\n").
1/1 mismatches
x[1]: "         A          B     \n——————————————————————————\nHiya   <f
x[1]: nc>   xx.x - xx.x\nbye    xx.xx      xx.xx   \n"
y[1]: "         A          B    \n—————————————————————————\nHiya   <fnc
y[1]: >     xx.x -  \n                  xx.x   \nbye    xx.xx      xx.xx
y[1]:   \n"
✖ | 1       8 | headers and footers [0.9s]
────────────────────────────────────────────────────────────────────────────────
Error (test-header-footer.R:82:5): post-processing addition of referential footnotes works
Error in `integer(n)`: invalid 'length' argument
Backtrace:
  1. formatters::matrix_form(tb1)
       at test-header-footer.R:82:4
  2. rtables::matrix_form(tb1)
  3. formatters::MatrixPrintForm(...)
       at insightsengineering_rtables_f0f6291eb2b1f6976bb05ff26dfa212d/R/tt_toString.R:277:4
  4. formatters:::mform_build_refdf(ret)
  5. formatters:::infer_ref_info(mform, colspace_only = TRUE)
  9. base::replicate(ncol(strs), list(mf_lgrouping(mform)[idx] - mf_nlheader(mform)))
 12. base::integer(n)
 ✖ | 1      94 | tabulation framework [10.4s]                            
────────────────────────────────────────────────────────────────────────
Error (test-lyt-tabulation.R:592:5): Colcounts work correctly
Error in `integer(n)`: invalid 'length' argument
Backtrace:
 1. formatters::matrix_form(tbl4)
      at test-lyt-tabulation.R:592:4
 2. rtables::matrix_form(tbl4)
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters:::splice_fnote_info_in(rowinfo, refdf)
      at formatters/R/matrix_form.R:490:4
 6. base::replicate(nrow(df), list(ref_df_row()[0, ]))
      at formatters/R/matrix_form.R:480:4
 9. base::integer(n)
gmbecker commented 1 year ago

I believe I have fixed this locally and it will be in the bundle of fixes and additional tests I push to formatters soon

Melkiades commented 1 year ago

with the latest updates:

✔ | F W S  OK | Context
✔ |        42 | Accessor tests [1.8s]                                   
✖ | 1      28 | binding [0.9s]                                          
────────────────────────────────────────────────────────────────────────
Error (test-binding.R:142:5): c/rbind and top-left behave
Error in `if (nrow(value) != nrs) stop("Rows in new row_info component (", 
    nrow(value), "does not match number of rows reflected in line_grouping component (", 
    nrs, ")")`: argument is of length zero
Backtrace:
 1. formatters::matrix_form(cbind_rtables(tab[0, ], tab[0, ]))
      at test-binding.R:142:4
 2. rtables::matrix_form(cbind_rtables(tab[0, ], tab[0, ]))
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters::`mf_rinfo<-`(...)
      at formatters/R/matrix_form.R:495:4
────────────────────────────────────────────────────────────────────────
✔ |        13 | compare_rtables [5.0s]                                  
✖ | 1      16 | deprecated functionality [0.7s]                         
────────────────────────────────────────────────────────────────────────
Error (test-deprecated.R:80:5): add_colcounts format argument works
Error in `if (nrow(value) != nrs) stop("Rows in new row_info component (", 
    nrow(value), "does not match number of rows reflected in line_grouping component (", 
    nrs, ")")`: argument is of length zero
Backtrace:
 1. formatters::matrix_form(tbl1)
      at test-deprecated.R:80:4
 2. rtables::matrix_form(tbl1)
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters::`mf_rinfo<-`(...)
      at formatters/R/matrix_form.R:495:4
────────────────────────────────────────────────────────────────────────
✖ | 1      22 | Exporters [16.4s]                                       
────────────────────────────────────────────────────────────────────────
Error (test-exporters.R:213:5): flextable export works
Error in `do.call(rbind.data.frame, pagdf$ref_info_df)`: second argument must be a list
Backtrace:
 1. rtables::tt_to_flextable(tbl, paginate = TRUE, lpp = 20)
      at test-exporters.R:213:4
 2. rtables::paginate_table(...)
      at rtables/R/tt_export.R:275:8
 3. rtables::pag_tt_indices(...)
      at rtables/R/tt_paginate.R:774:8
 4. formatters::pag_indices_inner(...)
      at rtables/R/tt_paginate.R:623:4
 5. formatters:::find_pag(...)
      at formatters/R/pagination.R:376:4
 6. formatters:::valid_pag(...)
      at formatters/R/pagination.R:305:2
 7. formatters:::calc_ref_nlines(pagdf[start:guess, ])
      at formatters/R/pagination.R:195:2
 8. base::do.call(rbind.data.frame, pagdf$ref_info_df)
      at formatters/R/pagination.R:166:4
────────────────────────────────────────────────────────────────────────
✖ | 2       6 | value formatting [0.6s]                                 
────────────────────────────────────────────────────────────────────────
Failure (test-formatting.R:40:5): table_shell works
toString(tblsh) not identical to paste0(capture_output(table_shell(tbl)), "\n").
1/1 mismatches
x[1]: "           A             B     \n———————————————————————————————\
x[1]: nHiya   xx (xx.x%)   xx.x - xx.x\nbye      xx.xx         xx.xx   \
x[1]: n"
y[1]: "           A           B    \n————————————————————————————\nHiya 
y[1]:      xx        xx.x -  \n        (xx.x%)      xx.x   \nbye      xx
y[1]: .xx       xx.xx  \n"

Failure (test-formatting.R:56:5): table_shell works
toString(tbl2sh) not identical to paste0(capture_output(table_shell(tbl2)), "\n").
1/1 mismatches
x[1]: "         A          B     \n——————————————————————————\nHiya   <f
x[1]: nc>   xx.x - xx.x\nbye    xx.xx      xx.xx   \n"
y[1]: "         A          B    \n—————————————————————————\nHiya   <fnc
y[1]: >     xx.x -  \n                  xx.x   \nbye    xx.xx      xx.xx
y[1]:   \n"
────────────────────────────────────────────────────────────────────────
✖ | 1       8 | headers and footers [0.7s]                              
────────────────────────────────────────────────────────────────────────
Error (test-header-footer.R:82:5): post-processing addition of referential footnotes works
Error in `integer(n)`: invalid 'length' argument
Backtrace:
  1. formatters::matrix_form(tb1)
       at test-header-footer.R:82:4
  2. rtables::matrix_form(tb1)
       at formatters/R/generics.R:109:2
  3. formatters::MatrixPrintForm(...)
       at rtables/R/tt_toString.R:277:4
  4. formatters:::mform_build_refdf(ret)
       at formatters/R/matrix_form.R:246:2
  5. formatters:::infer_ref_info(mform, colspace_only = TRUE)
       at formatters/R/matrix_form.R:348:4
  9. base::replicate(ncol(strs), list(mf_lgrouping(mform)[idx] - mf_nlheader(mform)))
       at formatters/R/matrix_form.R:316:4
 12. base::integer(n)
────────────────────────────────────────────────────────────────────────
✔ |        19 | Indent modifiers [1.9s]                                 
✖ | 1      94 | tabulation framework [8.8s]                             
────────────────────────────────────────────────────────────────────────
Error (test-lyt-tabulation.R:592:5): Colcounts work correctly
Error in `if (nrow(value) != nrs) stop("Rows in new row_info component (", 
    nrow(value), "does not match number of rows reflected in line_grouping component (", 
    nrs, ")")`: argument is of length zero
Backtrace:
 1. formatters::matrix_form(tbl4)
      at test-lyt-tabulation.R:592:4
 2. rtables::matrix_form(tbl4)
      at formatters/R/generics.R:109:2
 3. formatters::MatrixPrintForm(...)
      at rtables/R/tt_toString.R:277:4
 4. formatters:::shove_refdf_into_rowinfo(ret)
      at formatters/R/matrix_form.R:247:2
 5. formatters::`mf_rinfo<-`(...)
      at formatters/R/matrix_form.R:495:4
────────────────────────────────────────────────────────────────────────
✔ |        35 | make_afun and related machinery [0.4s]                  
✔ |        74 | Pagination [19.2s]                                      
✖ | 1      40 | Printing tables [2.8s]                                  
────────────────────────────────────────────────────────────────────────
Failure (test-printing.R:450:5): row label indentation is kept even if there are newline characters
mf3_v1[-which_to_rm] not equal to mf3_v2[-which_to_rm].
Component “col_widths”: Mean relative difference: 0.1081081
────────────────────────────────────────────────────────────────────────
✖ | 1      75 | regression tests [3.2s]                                 
────────────────────────────────────────────────────────────────────────
Error (test-regressions.R:19:5): printing table with 0 rows works
Error in `h(simpleError(msg, call))`: error in evaluating the argument 'x' in selecting a method for function 'toString': argument is of length zero
Backtrace:
  1. utils::capture.output(...)
       at test-regressions.R:19:4
 14. base::.handleSimpleError(...)
       at formatters/R/matrix_form.R:590:4
 15. base (local) h(simpleError(msg, call))
────────────────────────────────────────────────────────────────────────
✔ |        40 | rtables [0.6s]                                          
✔ |   3    25 | sorting and pruning [9.1s]                              
────────────────────────────────────────────────────────────────────────
Warning (test-sort-prune.R:126:5): trim_zero_rows, trim_rows, prune do the same thing in normal cases
'trim_zero_rows(tbl)' is deprecated.
Use 'prune_table(tbl, all_zero) or prune_table(tbl, prune_zeros_only)' instead.
See help("Deprecated")
Backtrace:
 1. rtables::trim_zero_rows(tbl)
      at test-sort-prune.R:126:4
 2. base::.Deprecated(...)
      at rtables/R/deprecated.R:32:4

Warning (test-sort-prune.R:137:5): trim_zero_rows, trim_rows, prune do the same thing in normal cases
'trim_zero_rows(tbl)' is deprecated.
Use 'prune_table(tbl, all_zero) or prune_table(tbl, prune_zeros_only)' instead.
See help("Deprecated")
Backtrace:
 1. rtables::trim_zero_rows(tbl2)
      at test-sort-prune.R:137:4
 2. base::.Deprecated(...)
      at rtables/R/deprecated.R:32:4

Warning (test-sort-prune.R:149:5): trim_zero_rows, trim_rows, prune do the same thing in normal cases
'trim_zero_rows(tbl)' is deprecated.
Use 'prune_table(tbl, all_zero) or prune_table(tbl, prune_zeros_only)' instead.
See help("Deprecated")
Backtrace:
 1. rtables::trim_zero_rows(tbl3)
      at test-sort-prune.R:149:4
 2. base::.Deprecated(...)
      at rtables/R/deprecated.R:32:4
────────────────────────────────────────────────────────────────────────
✔ |         3 | column spanning                                         
✔ |        36 | Split Functions [1.8s]                                  
✔ |         6 | Summarizing table structure [0.5s]                      
✔ |        74 | Accessing and subsetting tables [9.7s]                  

══ Results ═════════════════════════════════════════════════════════════
Duration: 84.5 s

[ FAIL 9 | WARN 3 | SKIP 0 | PASS 656 ]
shajoezhu commented 1 year ago

Hi @Melkiades , I was wondering do you have a PR linked to this?