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

Problems generating a 3d Table. #847

Open
ralmond opened this issue May 31, 2024 · 2 comments
Open

Problems generating a 3d Table. #847

ralmond opened this issue May 31, 2024 · 2 comments

Comments

@ralmond
Copy link

ralmond commented May 31, 2024

Describe the bug

I'm using ftable to render a 3d array, but when I pass the output of ftable to kbl, I get an error about bad arguments to an internal sprintf function.

To Reproduce

kableExtra::kbl(ftable(array(runif(50), c(5, 2, 5))))
#> Error in sprintf("   <td%s> %s </td>", align, z): arguments cannot be recycled to the same length

Created on 2024-05-31 with reprex v2.1.0

@haozhu233
Copy link
Owner

haozhu233 commented May 31, 2024

I think kable and functions in this package only addresses 2d array. In my impression, this is probably true for most table generation packages. It probably makes more sense to use some plotting methods to complete this task.

Sorry, I should have thought about it more carefully before throwing out comments. This feature is possible. Let me see what can be done here

@ralmond
Copy link
Author

ralmond commented May 31, 2024

The purpose of ftable is to flatten the 3d array into a matrix (sort of like going from wide to long format using dplyr.

I think that the problem is that ftable is stored as some kind of ragged array. If manually do the step using rbind, it seems to work:

phi2 <- array(runif(50),c(5,5,2))
kableExtra::kbl(rbind(phi2[,,1],phi2[,,2]),digits=3,booktabs=T) |> 
  kableExtra::kable_classic_2() |>
  kableExtra::pack_rows("Y=0",1,5) |>
  kableExtra::pack_rows("Y=1",6,10)

This produces what I want, I just need to be a bit more manual about unrolling the array.

Also, kbl(ftable(array(runif(50),c(5,5,2))) works, but kbl(ftable(array(runif(50),c(5,2,5))) does not.

Finally, I'm realizing the problem is actually upstream in knitr::kable. I should probably refile the bug upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants