Skip to content

Commit

Permalink
Fix a problem with t1kable when the row with the label contains data
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrich committed May 27, 2022
1 parent 8b381a7 commit 1aa0681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* Fix issue with `t1kable` (#82)

* Fix a problem with `t1kable` when the row with the label contains data.

# table1 1.4.2

* Add option `rounding.fn` to `stats.apply.rounding()` to allow changing the
Expand Down
14 changes: 11 additions & 3 deletions R/table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -1185,11 +1185,19 @@ t1kable <- function(x, booktabs=TRUE, ..., format) {
with(obj, {
rlh <- if (is.null(rowlabelhead) || rowlabelhead=="") "\U{00A0}" else rowlabelhead
i <- lapply(contents, function(y) {
nrow(y) - 1
if (all(y[1,, drop=T] == "")) {
nrow(y) - 1
} else {
nrow(y)
}
})
z <- lapply(contents, function(y) {
y <- as.data.frame(y[-1,, drop=F], stringsAsFactors=F)
y2 <- data.frame(x=rownames(y), stringsAsFactors=F)
if (all(y[1,, drop=T] == "")) {
y <- as.data.frame(y[-1,, drop=F], stringsAsFactors=F)
y2 <- data.frame(x=rownames(y), stringsAsFactors=F)
} else {
y2 <- data.frame(x="", stringsAsFactors=F)
}
y <- cbind(setNames(y2, rlh), y)
y
})
Expand Down

0 comments on commit 1aa0681

Please sign in to comment.