rtables
rtables copied to clipboard
pagination fails with zero rows table
basic_table() %>% split_cols_by("Species") %>% build_table(iris) %>% export_as_txt(lpp=10)
Error in while (start <= nr) { : argument is of length zero
TODO
check if table has zero rows, if so, do not paginate
If we are going to fully support zero-row tables (I'm still not fully convinced we should, to be honest) there's a lot more than just this to do.
What happens when the column labels have referential footnotes, for example. Does that (or even the table having footer materials that arent referential) work when there are no rows?
Also, for this specific issue, pagination should still happen. paginate_table always returns a list:
> paginate_table(tt, lpp = 1000)
[[1]]
big title
——————————————————————————
all obs
——————————————————————————
F
A: Drug X
Mean 33.71
B: Placebo
Mean 33.84
C: Combination
Mean 34.89
~~~~~~~~~~~~~~~~~~~~~~~~~~
M
A: Drug X
Mean 36.55
B: Placebo
Mean 32.10
C: Combination
Mean 34.28
~~~~~~~~~~~~~~~~~~~~~~~~~~
U
A: Drug X
Mean NA
B: Placebo
Mean NA
C: Combination
Mean NA
~~~~~~~~~~~~~~~~~~~~~~~~~~
UNDIFFERENTIATED
A: Drug X
Mean NA
B: Placebo
Mean NA
C: Combination
Mean NA
It should still do so in this case, if it is supported, so returning the "table" unmodified wouldn't be the right thing.
Thanks Gabe, so the todo should be
check if table has zero rows, if so, return list(tt).
cc @clarkliming for awareness
I thought about this and I figure out that the only case in which this makes sense is when we have an uneven page split, i.e. when we start the split at the bottom of a page and therefore the table has only a partial (extreme is only the titles) print in the first page (at the bottom) and then the rest is in the subsequent pages. Gabe and I already discussed about "starting the pagination at a specific line" as a very interesting and useful feature for the future. It comes from my understanding of medical writers' needs. I think there are virtually no cases where paginating an empty table makes sense otherwise. Certainly, for the first case, we should be very cautious about where we position the footnotes as they should be ideally on every page that has specific mentions (references) and at the end for general footnotes (or on every page?).
In other more synthetic words, I think we need to support this empty table pagination only in the vision of adding a starting line for its pagination. This would be anyway a new feature, and we need to be certain about footnotes positioning beforehand.
actually I don't care if pagination works for a empty table. What I care is, if export_as_txt(empty_table, lpp = 100)
fails or not
actually I don't care if pagination works for an empty table. What I care is, if
export_as_txt(empty_table, lpp = 100)
fails or not
Yep, that for sure should not fail mysteriously :D. I was more responding to Gabe about why this could happen. My apologies if it was a bit OT
this is taken care of by the table sanitizer?
I checked the new functionalities and here I copy the output of this fast exploration:
> a <- basic_table() %>% split_cols_by("Species") %>% build_table(iris)
> a
setosa versicolor virginica
——————————————————————————————————
> table_structure(a)
[ElementaryTable] root
> find_degen_struct(a)
[[1]]
[1] "root"
> validate_table_struct(a)
[1] FALSE
> assert_valid_table(a)
Error in assert_valid_table(a) :
Invalid table - found 1 (sub)structures which contain no data rows.
The first occured at path: root
Likely Cause: Empty data or first row split on variable with only NA values
Use sanitize_table_struct() to fix these issues
> sanitize_table_struct(a)
setosa versicolor virginica
————————————————————————————————————————————
-- This Section Contains No Data --
Now if you do add the latter to your pipeline the problem is solved:
> basic_table() %>% split_cols_by("Species") %>% build_table(iris) %>% sanitize_table_struct() %>% export_as_txt(lpp=10)
[1] " setosa versicolor virginica \n————————————————————————————————————————————\n -- This Section Contains No Data -- \n"
Of course if not empty works too:
> basic_table() %>% split_cols_by("Species") %>% analyze("Petal.Width") %>% build_table(iris) %>% sanitize_table_struct() %>% export_as_txt(lpp=10)
[1] " setosa versicolor virginica\n——————————————————————————————————————\nMean 0.25 1.33 2.03 \n"
Here we have two options:
a) we sanitize automatically from export_as_txt
b) we rely on the user to apply sanitize (and add a better error handling, i.e. with assert_valid_table
)
I am inclined to do the second. The involved functions are: (still to complete)
- [ ] Exporters
- [ ] Sorting
- [ ] Pruning & trimming
- [ ] Utilities