Open malcolmbarrett opened 5 years ago
Actually, I'm realizing that simply defining as.data.frame()
might be enough to make kable()
work out of box with a tableone
object as it calls as.data.frame()
internally...
I have a slightly modified version of as.data.frame()
that I've been using with kable()
fairly successfully.
as.data.frame.TableOne <- function(x, ...) {
capture.output(print(x, showAllLevels = TRUE, ...) -> x)
y <- as.data.frame(x)
y$charactersitic <- na_if(rownames(x), "")
y <- y %>%
fill(charactersitic, .direction = "down") %>%
select(charactersitic, everything())
rownames(y) <- NULL
y
}
Before seeing that the problem has already been addressed here, I posted a question on stackoverflow :
https://stackoverflow.com/questions/63700004/missing-the-spaces-with-kableone-package-tableone
The problem with as.data.frame is that he replaces the spaces with characters, like "X..." to indent (with kableone in PDF). The result is not really readable ... And so, options to format other things, like p-value in bold when <0.05 would be greatly appreciated for Rmarkdown report !
I do not understand this issue and documentation. They claim kableone
arguments are only for kable
, but if I include the print.TableOne
argument nonormal = TRUE
it works.
As brought up in #32,
kableone()
only lets you pass arguments tokable()
and not toprint.tableone()
.I think there are a couple of related issues here. Right now I'm thinking a good PR for this will do the following:
1) Move the code currently in
print.tableone
toas.data.frame.tableone
withprintToggle = FALSE
to avoidcapture.output()
2) changeprint.tableone
to something like3) Change
kableone()
to something like