-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Roche/devel
release v0.1.1
- Loading branch information
Showing
145 changed files
with
8,280 additions
and
2,549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: rtables | ||
Title: Reporting Tables | ||
Version: 0.1.0.6 | ||
Version: 0.1.1 | ||
Authors@R: c( | ||
person("Adrian", "Waddell", email = "[email protected]", role = c("aut", "cre")) | ||
) | ||
|
@@ -18,7 +18,7 @@ Suggests: | |
License: Apache License 2.0 | file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.0 | ||
RoxygenNote: 6.1.1 | ||
VignetteBuilder: knitr | ||
URL: https://github.com/roche/rtables, https://roche.github.io/rtables/ | ||
BugReports: https://github.com/roche/rtables/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#' Add N=xx to header | ||
#' | ||
#' Helper function used to add the population total (N) in the | ||
#' column header of \code{\link{rtable}} object. | ||
#' | ||
#' @param x \code{rtable} | ||
#' @param N vector with counts to be displayed in the header. The | ||
#' length must match the number of columns in \code{x} | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' | ||
#' tbl <- rtable( | ||
#' header = letters[1:3], | ||
#' rrow("X", 1, 2, 3), | ||
#' rrow("Y", 4, 5, 6) | ||
#' ) | ||
#' | ||
#' tbl | ||
#' | ||
#' header_add_N(tbl, 1:3) | ||
#' | ||
header_add_N <- function(x, N) { | ||
is(x, "rtable") || stop("x is expected to be an rtable") | ||
length(N) == ncol(x) || stop("dimension missmatch") | ||
|
||
header(x) <- rheader( | ||
header(x)[[1]], | ||
rrowl("", N, format = "(N=xx)") | ||
) | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#' Stack rtable objects | ||
#' | ||
#' Note that the columns order are not mached by the header: the first table | ||
#' header is taken as the reference. | ||
#' | ||
#' @param ... \code{\link{rtable}} objects | ||
#' @param gap number of empty rows to add between tables | ||
#' | ||
#' @return an \code{\link{rtable}} object | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' | ||
#' mtbl <- rtable( | ||
#' header = rheader( | ||
#' rrow(row.name = NULL, rcell("Sepal.Length", colspan = 2), rcell("Petal.Length", colspan=2)), | ||
#' rrow(NULL, "mean", "median", "mean", "median") | ||
#' ), | ||
#' rrow( | ||
#' row.name = "All Species", | ||
#' mean(iris$Sepal.Length), median(iris$Sepal.Length), | ||
#' mean(iris$Petal.Length), median(iris$Petal.Length), | ||
#' format = "xx.xx" | ||
#' ) | ||
#' ) | ||
#' | ||
#' mtbl2 <- with(subset(iris, Species == 'setosa'), rtable( | ||
#' header = rheader( | ||
#' rrow(row.name = NULL, rcell("Sepal.Length", colspan = 2), rcell("Petal.Length", colspan=2)), | ||
#' rrow(NULL, "mean", "median", "mean", "median") | ||
#' ), | ||
#' rrow( | ||
#' row.name = "Setosa", | ||
#' mean(Sepal.Length), median(Sepal.Length), | ||
#' mean(Petal.Length), median(Petal.Length), | ||
#' format = "xx.xx" | ||
#' ) | ||
#' )) | ||
#' | ||
#' tbl <- rbind(mtbl, mtbl2) | ||
#' tbl | ||
#' | ||
#' tbl <- rbind(mtbl, mtbl2, gap = 1) | ||
#' tbl | ||
#' | ||
#' tbl <- rbind(mtbl, mtbl2, gap = 2) | ||
#' tbl | ||
#' | ||
rbind.rtable <- function(..., gap = 0) { | ||
dots <- Filter(Negate(is.null), list(...)) | ||
rbindl_rtables(dots, gap = gap) | ||
} | ||
|
||
#' Stack a list of rtables | ||
#' | ||
#' See \code{\link{rbind.rtable}} for details | ||
#' | ||
#' @param x a list of rtable objects | ||
#' @inheritParams rbind.rtable | ||
#' | ||
#' @export | ||
#' | ||
rbindl_rtables <- function(x, gap = 0) { | ||
|
||
stopifnot(is.list(x)) | ||
stopifnot(are(x, "rtable")) | ||
stopifnot(length(x) > 0) | ||
stopifnot(is.numeric(gap), gap >= 0) | ||
|
||
if (!num_all_equal(vapply(x, ncol, numeric(1)))) | ||
stop("non-matching number of columns between tables") | ||
|
||
tbl <- if (gap != 0) { | ||
gap_rows <- replicate(gap, rrow(), simplify = FALSE) | ||
Reduce(function(tbl1, tbl2) c(tbl1, gap_rows, tbl2), x) | ||
} else { | ||
unlist(x, recursive = FALSE) | ||
} | ||
|
||
ref_header <- header(x[[1]]) | ||
class(tbl) <- "rtable" | ||
attr(tbl, "header") <- ref_header | ||
attr(tbl, "nrow") <- length(tbl) | ||
attr(tbl, "ncol") <- ncol(ref_header) | ||
|
||
tbl | ||
} | ||
|
||
|
||
#' Unlist method for rtables | ||
#' | ||
#' rtable objects should not be unlisted. This allows us to create nested lists with rtables objects and then flatten | ||
#' them to a list of rtable objects. | ||
#' | ||
#' @inheritParams base::unlist | ||
#' | ||
#' @return rtable object | ||
#' | ||
#' @method unlist rtable | ||
#' @export | ||
unlist.rtable <- function(x, recursive = TRUE, use.names = TRUE) { | ||
x | ||
} |
Oops, something went wrong.