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
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
0 commit comments