Skip to content

Commit e664741

Browse files
committed
updated roxygen documentation about 'wcol' argument in gentlg() and added examples
1 parent 44e9127 commit e664741

File tree

7 files changed

+82
-42
lines changed

7 files changed

+82
-42
lines changed

R/gentlg.R

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
#' @param plotheight (optional) Numerical value that indicates the plot height
3636
#' in cm for figure outputs. (Default = 5)
3737
#' @param wcol (optional) Can be one of:
38-
#' - a single numerical value that represents the width of the first column
39-
#' - a vector, specifying the widths of all columns in the final table or listing
40-
#' - a list of vectors (applicable when huxme is a list), specifying
41-
#' the widths of all columns for each element in huxme\cr
38+
#' - a single numeric value that represents the width of the first column
39+
#' - a numeric vector, specifying the widths of all columns in the final table or listing
40+
#' - a list of numeric vectors (applicable when `huxme` is a list). Each element
41+
#' can specify the widths of all columns or the width of the first column only\cr
4242
#'
4343
#' When a single numerical value is used, this will be taken as the column width
4444
#' for the first column. The other columns will be equally spaced across the
@@ -194,6 +194,26 @@
194194
#' )
195195
#' )
196196
#'
197+
#' final_2 <- data.frame(
198+
#' label = c(
199+
#' "Overall", "Safety Analysis Set",
200+
#' "Any Adverse event{\\super a}", "- Serious Adverse Event"
201+
#' ),
202+
#' Drug_A = c("", "40", "10 (25%)", "0"),
203+
#' Drug_B = c("", "40", "10 (25%)", "0")
204+
#' )
205+
#'
206+
#' gentlg(
207+
#' huxme = list(final_2, final_2),
208+
#' wcol = list(c(0.70, 0.15, 0.15), c(0.5)),
209+
#' file = "TSFAEX",
210+
#' title = "This is Amazing Demonstration 1",
211+
#' footers = c(
212+
#' "Note: For demonstrative purposes only",
213+
#' "{\\super a} Subjects are counted once for any given event."
214+
#' )
215+
#' )
216+
#'
197217
#' # Produce output in HTML format
198218
#' hux <- gentlg(
199219
#' huxme = final,
@@ -248,33 +268,15 @@ gentlg <- function(huxme = NULL,
248268
# and wcol[[i]] must be a length 1 vector or a vector with as many numeric values
249269
# as number of columns in huxme[[i]]
250270
if (is.list(wcol)) {
251-
if (!(is.list(huxme) && !is.data.frame(huxme))) {
252-
stop(
253-
"'wcol' appears to be a list while huxme is not a list of tables/listings. ",
254-
"If you intended 'wcol' to apply to the single output, convert it to a ",
255-
"vector, otherwise pass a non-data.frame list to 'huxme'."
256-
)
257-
}
258-
## already know wcol is a list and huxme is a non-data.frame list
259-
if (length(huxme) != length(wcol)) {
260-
stop("Arguments 'wcol' and 'huxme' must have the same length.")
261-
}
262-
# the following checks are also made inside gentlg_single()
263-
formatcolumns <- c(
264-
"anbr", "roworder", "boldme", "indentme", "newrows", "newpage",
265-
"rowvar", "row_type", "nested_level", "group_level"
266-
)
267-
for (i in seq_along(wcol)) {
268-
if (!is.numeric(wcol[[i]])) {
269-
stop("wcol[[", i, "]] must be (a vector of) numeric.")
270-
}
271-
# wcol[[i]] must be a length 1 vector or a vector of length equal of ncol(huxme[[i]])
272-
expected_length <- length(dplyr::setdiff(colnames(huxme[[i]]), formatcolumns))
273-
if (length(wcol[[i]]) != 1 && length(wcol[[i]]) != expected_length) {
274-
stop("wcol[[", i, "]] must be a length 1 vector or contain as many values as number of columns (i.e. ",
275-
expected_length, "), but its length is ", length(wcol[[i]]), ".")
276-
}
277-
}
271+
assertthat::assert_that(is.list(huxme) && !is.data.frame(huxme),
272+
msg = paste0(
273+
"'wcol' appears to be a list while huxme is not a list of tables/listings. ",
274+
"If you intended 'wcol' to apply to the single output, convert it to a ",
275+
"vector, otherwise pass a non-data.frame list to 'huxme'."
276+
))
277+
## already know wcol is a list and huxme is a non-data.frame list
278+
assertthat::assert_that(length(huxme) == length(wcol),
279+
msg = "Arguments 'wcol' and 'huxme' must have the same length.")
278280
}
279281

280282
adjfilename <- stringr::str_replace_all(
@@ -384,7 +386,7 @@ gentlg <- function(huxme = NULL,
384386
border_fns,
385387
alignments,
386388
index,
387-
wcol_i) {
389+
wcol) {
388390
gentlg_single(
389391
huxme = ht,
390392
tlf = tlf,
@@ -394,7 +396,7 @@ gentlg <- function(huxme = NULL,
394396
plotnames = plotnames,
395397
plotwidth = plotwidth,
396398
plotheight = plotheight,
397-
wcol = wcol_i,
399+
wcol = wcol,
398400
orientation = orientation,
399401
opath = opath,
400402
title_file = title_file,
@@ -422,7 +424,7 @@ gentlg <- function(huxme = NULL,
422424
border_fns = border_fns,
423425
alignments = alignments,
424426
index = seq_len(length(huxme)),
425-
wcol_i = wcol,
427+
wcol = wcol,
426428
SIMPLIFY = FALSE
427429
)
428430

man/gentlg.Rd

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-gentlg.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test_that("gentlg() wcol checks", {
6767
}
6868

6969
# example passing all colwidths explicitly
70-
wcol <- list(c(0.5, 0.3, 0.2), c(0.4, 0.4, 0.2))
70+
wcol <- list(c(0.5, 0.3, 0.2), c(0.4))
7171
expect_no_error(hux_tables <- gentlg(
7272
huxme = list(df, df),
7373
wcol = wcol,
@@ -90,7 +90,7 @@ test_that("gentlg() wcol checks", {
9090
wcol = wcol,
9191
print.hux = FALSE
9292
),
93-
"must be a length 1 vector or contain as many values as number of columns"
93+
"wcol\\'s length must be 1 or the length of final output"
9494
)
9595

9696
wcol <- list(c(0.5, 0.2, 0.5), c(0.4, 0.4, 0.2))
@@ -101,4 +101,22 @@ test_that("gentlg() wcol checks", {
101101
),
102102
"wcol not defined properly"
103103
)
104+
105+
wcol <- list(c(0.5, 0.3), c(0.4, 0.4, 0.2))
106+
expect_error(hux_tables <- gentlg(
107+
huxme = df,
108+
wcol = wcol,
109+
print.hux = FALSE
110+
),
111+
"\\'wcol\\' appears to be"
112+
)
113+
114+
wcol <- list(c(0.5, 0.2, 0.5), c(0.4, 0.4, 0.2))
115+
expect_error(hux_tables <- gentlg(
116+
huxme = list(df, df, df),
117+
wcol = wcol,
118+
print.hux = FALSE
119+
),
120+
"Arguments \\'wcol\\' and \\'huxme\\' must have the same length."
121+
)
104122
})
-538 Bytes
Loading

tests/testthat/test_outputs/png1.rtf

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
-909 Bytes
Loading

tests/testthat/test_outputs/png2.rtf

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)