Skip to content

Commit

Permalink
Merge pull request #208 from metrumresearchgroup/release/0.3.3
Browse files Browse the repository at this point in the history
Release/0.3.3
  • Loading branch information
kylebaron authored Mar 8, 2021
2 parents 37a65c4 + bdeab13 commit e7d471a
Show file tree
Hide file tree
Showing 37 changed files with 412 additions and 244 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pmtables
Type: Package
Title: Tables for Pharmacometrics
Version: 0.3.2
Version: 0.3.3
Authors@R:
c(
person(given = "Kyle",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# pmtables 0.3.3

- Fix bug where arguments could not be passed along to `stable_long()`
when coercing pmtable output (#203)

- Fix bug where user-specified font size was not getting propagated to
long table output with `stable_long()` (#204)

# pmtables 0.3.2

- Fix cols renaming and utilization of table argument in pt_cont_wide; add tests
Expand Down
4 changes: 2 additions & 2 deletions R/table-long.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ stable_long.data.frame <- function(data,
lt_notes <- longtable_notes(x$mini_notes)

longtab <- c(
"{\\normalsize",
x$sizes$font_size$start,
row_space,
col_space,
extra_row_height,
Expand All @@ -114,7 +114,7 @@ stable_long.data.frame <- function(data,
"\\hline",
"\\end{longtable}",
lt_notes,
"}" # Ends
x$sizes$font_size$end
)
out <- structure(
longtab,
Expand Down
6 changes: 6 additions & 0 deletions R/table-notes.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#' @param output_file_label a prefix for `output_file`
#' @param ... not used
#'
#' @examples
#' tab <- stable(
#' stdata(),
#' note_config = noteconf(type = "mini")
#' )
#'
#'@export
tab_notes <- function(notes, escape_fun = tab_escape,
note_config = noteconf(type = "tpt"),
Expand Down
87 changes: 54 additions & 33 deletions R/table-object.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ check_st <- function(x) {
msg = "the first argument (x) must be an st object"
)
}

st_arg_names <- c(
"data", "panel", "notes",
"align", "r_file", "output_file",
"span", "span_split", "cols_rename", "cols_blank",
"sumrows", "note_config", "clear_reps", "clear_grouped_reps",
"hline_at", "hline_from", "sizes", "units", "drop"
"hline_at", "hline_from", "sizes", "units", "drop",
"lt_cap_text", "lt_cap_macro", "lt_cap_label", "lt_cap_short", "lt_continue",
"args"
)

#' Create an st object
Expand Down Expand Up @@ -74,35 +77,27 @@ st_make <- function(x, ..., .preview = FALSE, .cat = FALSE, long = FALSE) {
long <- isTRUE(long)
# accumulated by the functions
args <- as.list(x)
argnames <- attr(x,"argnames")
if(long) argnames <- c(argnames, "cap_text", "cap_macro")
args <- args[intersect(names(args),argnames)]

# misc args
# misc args passed in via st_args
if(is.list(x$args)) {
args <- combine_list(args, x$args)
}

dots <- list(...)
if(length(dots) > 0) {
args <- combine_list(args,dots)
}

if(long) {
ans <- do.call(stable_long, args)
if(isTRUE(.preview)) {
warning("cannot preview a long table; use st2doc() instead",call.=FALSE)
warning("cannot preview a long table; use st2report() instead", call.=FALSE)
.preview <- FALSE
}
} else {
ans <- do.call(stable, args)
}

if(.preview) { # nocov start
.null <- st_preview(ans)
return(invisible(ans))
}

if(.cat) {
.null <- pt_wrap(ans,stdout())
return(invisible(ans))
Expand All @@ -126,7 +121,7 @@ st_make <- function(x, ..., .preview = FALSE, .cat = FALSE, long = FALSE) {
#' ob %>% st_panel("STUDY") %>% st_make()
#'
#' @export
st_panel <- function(x,...) {
st_panel <- function(x, ...) {
check_st(x)
panel <- rowpanel(...)
assert_that(is.rowpanel(panel))
Expand All @@ -136,8 +131,9 @@ st_panel <- function(x,...) {

#' Add note information to st object
#'
#' See the `notes` and `note_config` arguments to [stable()]. The function can
#' be called multiple times and will accumulate `notes` data.
#' See the `notes` and `note_config` arguments passed to [stable()] and then to
#' [tab_notes()]. The function can be called multiple times and will accumulate
#' `notes` data.
#'
#' @param x an stobject
#' @param ... table notes
Expand Down Expand Up @@ -175,7 +171,8 @@ st_notes <- function(x, ..., esc = NULL, config = NULL, collapse = NULL) {

#' Add note config information to st object
#'
#' See the `note_config` argument to [stable()].
#' See the `note_config` argument passed to [stable()] and then to
#' [tab_notes()].
#'
#' @param x an stobject
#' @param ... named arguments passed to [noteconf()]
Expand Down Expand Up @@ -241,7 +238,8 @@ st_right <- function(x,...) {

#' Add file name information to st object
#'
#' See the `r_file` and `output_file` arguments to [stable()].
#' See the `r_file` and `output_file` arguments passed to [stable()] and then
#' to [tab_notes()].
#'
#' @param x an stobject
#' @param r set `r_file`, passed to [stable()]
Expand Down Expand Up @@ -272,11 +270,12 @@ st_files <- function(x, r = getOption("mrg.script", NULL), output = NULL,

#' Add row and column spacing information to st object
#'
#' See the `row_space` and `col_space` arguments to [stable()].
#' See the `sizes` argument to [stable()] and the `row_space` and `col_space`
#' arguments to [tab_size()].
#'
#' @param x an stobject
#' @param row set `row_space`, passed to [stable()]
#' @param col set `col_space`, passed to [stable()]
#' @param row set `row_space`, passed to [stable()] and then to [tab_size()]
#' @param col set `col_space`, passed to [stable()] and then to [tab_size()]
#'
#' @examples
#' library(dplyr)
Expand Down Expand Up @@ -333,7 +332,7 @@ st_span <- function(x, ..., split = FALSE) {

#' Add column split spanner information to st object
#'
#' See the `span_split` argument to [stable()].
#' See the `span_split` argument passed to [stable()] and then [tab_spanners()].
#'
#' @param x an stobject
#' @param split passed to [colsplit()], if `split` is `FALSE`, then
Expand Down Expand Up @@ -375,8 +374,9 @@ st_span_split <- function(x, ..., split = TRUE) {

#' Add column rename information to st object
#'
#' See the `cols_rename` argument to [stable()]. This function can be called
#' multiple times and will accumulate `cols_rename` data.
#' See the `cols_rename` argument passed to [stable()] and then [tab_cols()].
#' This function can be called multiple times and will accumulate `cols_rename`
#' data.
#'
#' @param x an stobject
#' @param ... column rename items in `new-name = old-name` format; passed
Expand Down Expand Up @@ -422,8 +422,9 @@ st_rename <- function(x, ..., .list = NULL) {

#' Add column blank information to st object
#'
#' See the `cols_blank` argument to [stable()]. This function can be called
#' multiple times and will accumulate `cols_blank` data.
#' See the `cols_blank` argument passed to [stable()] and then [tab_cols()].
#' This function can be called multiple times and will accumulate `cols_blank`
#' data.
#'
#' @param x an stobject
#' @param ... quoted or unquoted column names to be passed to [stable()] as
Expand Down Expand Up @@ -471,7 +472,8 @@ st_sumrow <- function(x, pattern = NULL, cols = names(x$data), rows = integer(0)

#' Add clear rep information to st object
#'
#' See the `clear_reps` argument to [stable()].
#' See the `clear_reps` argument passed to [stable()] and then to
#' [tab_clear_reps()].
#'
#' @param x an stobject
#' @param ... quoted or unquoted column names passed to [stable()] as
Expand Down Expand Up @@ -508,7 +510,8 @@ st_clear_grouped <- function(x, ...) {

#' Add hline information to st object
#'
#' See the `hline_at` and `hline_from` arguments to [stable()].
#' See the `hline_at` and `hline_from` arguments passed to [stable()] and
#' then to [tab_hlines()],
#'
#' @param x and stobject
#' @param pattern a regular expression to find rows where an `hline` will be
Expand Down Expand Up @@ -548,6 +551,8 @@ st_hline <- function(x, pattern = NULL, cols = names(x$data), n = 1,

#' Add table size information to st object
#'
#' See the `sizes` argument to [stable()], passed to [tab_size()].
#'
#' @param x an stobject
#' @param ... passed to [tab_size()]
#'
Expand All @@ -560,27 +565,32 @@ st_sizes <- function(x,...) {

#' Add other arguments to st object
#'
#' The arguments entered here are passed to [stable()] or [stable_long()].
#'
#' @param x an stobject
#' @param ... named arguments to be passed to [stable()]
#'
#' @export
st_args <- function(x,...) {
check_st(x)
args <- list(...)
assert_that(
is_named(args),
msg = "arguments passed to st_args must be named"
)
if(length(args) > 0) {
args <- args[intersect(names(args),st_arg_names)]
x$args <- c(x$args, args)
x$args <- combine_list(x$args, args)
}
x
}

#' Add unit information to st object
#'
#' Units can be passed either as `name=value` pairs or as a named list
#' with [st_args()]. Units can alternatively be passed as an argument
#' to [stable()] as a pre-formed, named list using [st_args()]. Passing
#' as an argument this way will overwrite units specified with
#' [st_units()]. It is recommended to use either [st_units()] or
#' See the `units` argument to [stable()]. Units can be passed either as
#' `name=value` pairs or as a named list with [st_args()]. Units can
#' alternatively be passed as an argument to [stable()] as a pre-formed, named
#' list using [st_args()]. Passing as an argument this way will overwrite units
#' specified with [st_units()]. It is recommended to use either [st_units()] or
#' [st_args()] but not both.
#'
#' @param x an stobject
Expand Down Expand Up @@ -609,6 +619,9 @@ st_units <- function(x, ..., parens = TRUE) {

#' Render table data in bold or italic font
#'
#' These functions modify the input data frame prior to passing it to
#' [stable()] or [stable_long()].
#'
#' @param x an stobject
#' @param cols columns to make bold
#' @param pattern passed to [tex_bold()] or [tex_it()]
Expand Down Expand Up @@ -636,6 +649,8 @@ st_it <- function(x, cols, pattern = "*") {

#' Drop data columns
#'
#' See the `drop` argument to [stable()].
#'
#' @param x an stobject
#' @param ... column names to drop
#'
Expand All @@ -648,6 +663,9 @@ st_drop <- function(x, ...) {

#' Filter, select, or mutate data
#'
#' These functions modify the input data frame prior to passing it to
#' [stable()] or [stable_long()].
#'
#' @param x an stobject
#' @param ... passed to [dplyr::select()], or [dplyr::mutate()]
#'
Expand All @@ -666,6 +684,9 @@ st_mutate <- function(x, ...) {

#' Edit table contents
#'
#' These functions modify the input data frame prior to passing to [stable()]
#' or [stable_long()].
#'
#' @param x an stobject
#' @param ... arguments passed to [tab_edit()]
#'
Expand Down
4 changes: 1 addition & 3 deletions R/table-stable.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ stable_argument_names <- function() {
names(formals(make_tabular)),
names(formals(tab_cols)),
names(formals(tab_size)),
names(formals(stable_long))
names(formals(stable_long.data.frame))
)
)
}
Expand Down Expand Up @@ -314,8 +314,6 @@ as_stable.pmtable <- function(x, ..., long = FALSE, wrap = FALSE, wrapw = FALSE,
up[replace] <- NULL
}
x <- c(x,up)
valid <- intersect(names(x),stable_argument_names())
x <- x[valid]

fun <- ifelse(isTRUE(long), stable_long, stable)

Expand Down
25 changes: 14 additions & 11 deletions inst/covr/coverage.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# coverage: 91.13%
# coverage: 91.21%

|file | coverage|
|:------------------------|--------:|
|R/table-functions.R | 9.09|
|R/AAAA.R | 0.00|
|R/preview.R | 55.56|
|R/utils.R | 68.42|
|R/table-utils.R | 68.57|
|R/table-object.R | 73.71|
|R/table-utils.R | 70.13|
|R/table-align.R | 77.55|
|R/table-object.R | 78.17|
|R/table-tabular.R | 81.08|
|R/summary-functions.R | 82.14|
|R/table-sumrow.R | 87.76|
|R/table-hlines.R | 87.88|
|R/summary-functions.R | 88.89|
|R/yaml-as-df.R | 89.19|
|R/table-stable.R | 89.94|
|R/check.R | 91.67|
|R/table-clear_reps.R | 95.83|
|R/table-stable.R | 96.34|
|R/data_inventory_table.R | 96.68|
|R/table-panel.R | 96.70|
|R/table-span.R | 96.71|
|R/table-long.R | 96.97|
|R/table-span.R | 96.93|
|R/table-notes.R | 97.06|
|R/table-long.R | 97.18|
|R/class-new_names.R | 97.37|
|R/class-digits.R | 97.50|
|R/continuous_table.R | 97.87|
|R/discrete_table.R | 98.68|
|R/continuous_table.R | 97.95|
|R/data_inventory_table.R | 98.10|
|R/discrete_table.R | 98.77|
|R/knit-dependencies.R | 100.00|
|R/summarize-cat-chunk.R | 100.00|
|R/table-cols.R | 100.00|
|R/table-sizes.R | 100.00|
Loading

0 comments on commit e7d471a

Please sign in to comment.