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

Bug in table export #288

Closed
BFalquet opened this issue May 28, 2024 · 4 comments · Fixed by #290
Closed

Bug in table export #288

BFalquet opened this issue May 28, 2024 · 4 comments · Fixed by #290
Assignees
Labels
bug Something isn't working

Comments

@BFalquet
Copy link

Reproducible example:

library(rtables)
lyt <- basic_table() %>%
  split_cols_by("Species") %>%
  analyze("Sepal.Length", afun = function(x) {
    list(
      "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"),
      "range" = diff(range(x))
    )
  })
lyt

tbl <- build_table(lyt, iris)
prov_footer(tbl) <- c("Santa", "is", "real", "!")
export_as_txt(tbl)

leads to

Error in length(prov_footer(obj)) == 0 || !grepl(page_num, prov_footer(obj),  : 
  'length = 4' in coercion to 'logical(1)'

I think there is just a any() missing to handle the case where the prov footer is a vector of several elements.

@BFalquet BFalquet added the bug Something isn't working label May 28, 2024
@Melkiades
Copy link
Contributor

@BFalquet I cannot reproduce the error

@BFalquet
Copy link
Author

BFalquet commented May 28, 2024

@Melkiades There is also something weird happening with the dependencies today, but just from a purely formal code analysis point of view, the following code in paginate_to_mpfs has a small issue:

(length(prov_footer(obj)) == 0 || !grepl(page_num, prov_footer(obj), perl = TRUE))

If the length of prov_footer(obj) is bigger than 1, the grepl expression will return a logical vector bigger than 1 that will cause an issue because here the || expects two vectors of size 1. E.g

> FALSE || grepl("a", letters)
Error in FALSE || grepl("a", letters) : 
  'length = 26' in coercion to 'logical(1)'

It doesn't fail every time, because if the first part of the expression is TRUE, the second part is not evaluated but in the other cases, we have an issue.

Anyway, this makes the non-CRAN tests of one of my internal package fail.

@Melkiades
Copy link
Contributor

ok I see! let me generalize the fix today

@edelarua
Copy link
Contributor

Should be fixed by #290 - bug was still occurring when prov_footer is not empty but it's no longer an issue in my tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants