Skip to content

Commit

Permalink
Merge pull request #2 from stopsack/dev
Browse files Browse the repository at this point in the history
Release 0.6.1
  • Loading branch information
stopsack authored Jun 13, 2023
2 parents 9a26177 + d833243 commit d5d5152
Show file tree
Hide file tree
Showing 27 changed files with 415 additions and 216 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, dev]
pull_request:
# CRON jobs only run on the default branch of the repo
schedule:
Expand All @@ -24,9 +24,9 @@ jobs:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
#- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
#- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Package: rifttable
Type: Package
Title: Results Tables to Bridge the Rift Between Epidemiologists and Their Data
Version: 0.6.0
Version: 0.6.1
Authors@R:
person(given = "Konrad H.",
family = "Stopsack",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-0722-1311"))
Description: The rifttable package creates a presentation-ready stratified
results tables for epidemiologists, containing both descriptive and
inferential statistics.
Description: Presentation-ready stratified results tables for epidemiologists,
containing both descriptive and inferential statistics.
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Expand All @@ -22,7 +21,7 @@ Imports:
broom (>= 0.7.0),
dplyr (>= 1.0.8),
purrr,
risks (>= 0.4.0),
risks (>= 0.4.2),
rlang (>= 0.4.0),
stats,
survival,
Expand Down
30 changes: 28 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# rifttable 0.6.1

* New functionality:
+ Cox models (`type = "hr"`) allow for `weights`, clustering, and `robust`
standard errors.
+ Argument `ratio_digits_decrease`: By default, decrease number of decimal
digits shown for ratios by 1 digit for ratios > 3 and by 2 digits for ratios
> 10. Leads to rounded ratios and confidence intervals of `1.23`, `3.4`, and
`11`.
+ `rt_gt()` now indents the first column and applies markdown formatting to it
by default.
* New FAQ vignette.
* Bug fixes:
+ Binary outcomes returned `NA` instead of `0` in unstratified tables
with all-null outcome.
+ `type = "maxfu"` ignored `digits` and `diff_digits`.
+ Allow for different `exposure` (strata labels) and `arguments` in one table.
+ Show unstratified estimate if `exposure` is `""`, not just for `NA`.
* Internal:
+ `rt_gt()`: suppress random `id` of gt tables to keep git diff slim.
+ Keep variables `.event`, `.outcome`, etc. available under their original
names.
+ Require {risks} >= 0.4.2.
+ Examples load the `breastcancer` dataset from the risks package.


# rifttable 0.6.0

* Breaking changes:
Expand All @@ -14,8 +40,8 @@
* New function `table1_design()`: Generate design of a descriptive "Table 1."
* New `outcome` option `"variable@level"` for categorical variables that
displays `level` as a binary outcome. Used by `table1_design()`.
* Unstratified tables displaying the trend/linear slope (`trend` variable in the
`design`) without an `exposure`.
* Support unstratified tables displaying the trend/linear slope (`trend`
variable in the `design`) without an `exposure`.
* More customization:
+ `rifttable(reference = ...)`: Label for the reference category.
+ `design$ci`: Width of confidence intervals.
Expand Down
18 changes: 0 additions & 18 deletions R/breastcancer.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/estimate_event_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ estimate_event_time <- function(
dplyr::summarize(
res = paste(format_round(
max(.data$.time),
digits = 0)))
digits = digits)))
},
"surv" =,
"surv (ci)" =,
Expand Down
8 changes: 7 additions & 1 deletion R/estimate_regress_binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#' @param to Separator character(s) for confidence interval bounds
#' @param is_trend If called on a continous (trend) variable
#' @param type Estimand
#' @param ratio_digits Digits for ratios
#' @param risk_digits Digits for risks
#' @param ratio_digits Digits for ratios
#' @param ratio_digits_decrease Fewer digits for elevated ratios
#' @param nmin Suppress counts below
#' @param exposure Name of exposure variable
#' @param outcome Name of outcome variable
Expand All @@ -32,6 +33,7 @@ estimate_regress_binary <- function(
risk_percent,
risk_digits,
ratio_digits,
ratio_digits_decrease,
is_trend,
nmin,
na_rm,
Expand Down Expand Up @@ -61,6 +63,9 @@ estimate_regress_binary <- function(
type %in% c("rd", "rd_joint"),
true = risk_digits,
false = ratio_digits))
if(type %in% c("rd", "rd_joint")) {
ratio_digits_decrease <- NULL
}
bootrepeats <- find_argument(
arguments = arguments,
which_argument = "bootrepeats",
Expand Down Expand Up @@ -132,6 +137,7 @@ estimate_regress_binary <- function(
true = 100,
false = 1),
digits = digits,
ratio_digits_decrease = ratio_digits_decrease,
pattern = pattern,
xlevels = xlevels,
reference = dplyr::if_else(
Expand Down
6 changes: 6 additions & 0 deletions R/estimate_regress_continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param is_trend If called on a continous (trend) variable
#' @param type Estimand
#' @param ratio_digits Digits for ratios
#' @param ratio_digits_decrease Fewer digits for elevated ratios
#' @param diff_digits Digits for differences
#' @param nmin Suppress counts below
#' @param exposure Name of exposure variable
Expand All @@ -29,6 +30,7 @@ estimate_regress_continuous <- function(
digits,
risk_percent,
ratio_digits,
ratio_digits_decrease,
diff_digits,
is_trend,
nmin,
Expand All @@ -55,6 +57,9 @@ estimate_regress_continuous <- function(
type %in% c("diff", "diff_joint", "quantreg", "quantreg_joint"),
true = diff_digits,
false = ratio_digits))
if(type %in% c("diff", "diff_joint", "quantreg", "quantreg_joint")) {
ratio_digits_decrease <- NULL
}
tau <- find_argument(
arguments = arguments,
which_argument = "tau",
Expand Down Expand Up @@ -189,6 +194,7 @@ estimate_regress_continuous <- function(
is_trend = is_trend,
multiply = 1,
digits = digits,
ratio_digits_decrease = ratio_digits_decrease,
pattern = pattern,
xlevels = xlevels,
reference = dplyr::if_else(
Expand Down
21 changes: 20 additions & 1 deletion R/estimate_regress_cox.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param is_trend If called on a continous (trend) variable
#' @param type Estimand
#' @param ratio_digits Digits for ratios
#' @param ratio_digits_decrease Fewer digits for elevated ratios
#' @param nmin Suppress counts below
#' @param exposure Name of exposure variable
#' @param na_rm Remove observations with missing outcome data
Expand All @@ -28,6 +29,7 @@ estimate_regress_cox <- function(
confounders,
digits,
ratio_digits,
ratio_digits_decrease,
is_trend,
nmin,
na_rm,
Expand All @@ -50,6 +52,20 @@ estimate_regress_cox <- function(
digits <- find_rounding_digits(
digits = digits,
default = ratio_digits)
coxph_weights <- find_argument(
arguments = arguments,
which_argument = "weights",
is_numeric = FALSE,
default = NULL)
if(!is.null(coxph_weights)) {
coxph_weights <- data %>%
dplyr::pull(dplyr::one_of(coxph_weights))
}
coxph_robust <- find_argument(
arguments = arguments,
which_argument = "robust",
is_numeric = FALSE,
default = NULL)

survival::coxph(
formula = stats::as.formula(
Expand All @@ -60,7 +76,9 @@ estimate_regress_cox <- function(
false = "survival::Surv(time = .time_orig, time2 = .time2, "),
"event = .event) ~ .exposure ",
confounders)),
data = data) %>%
data = data,
weights = coxph_weights,
robust = coxph_robust) %>%
broom::tidy(
conf.int = TRUE,
conf.level = ci,
Expand All @@ -71,6 +89,7 @@ estimate_regress_cox <- function(
is_trend = is_trend,
multiply = 1,
digits = digits,
ratio_digits_decrease = ratio_digits_decrease,
pattern = pattern,
xlevels = xlevels,
reference = 1,
Expand Down
6 changes: 5 additions & 1 deletion R/fill_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' @param diff_digits Number of digits to round difference estimates to
#' @param risk_digits Number of digits to round risk/cumulative incidences to
#' @param ratio_digits Number of digits to round ratio estimates to
#' @param ratio_digits_decrease Fewer digits for elevated ratios
#' @param rate_digits Number of digits to round rate estimates to
#' @param to Separator for mean/difference confidence intervals.
#' @param outcome Outcome variable
Expand Down Expand Up @@ -51,8 +52,9 @@ fill_cells <- function(
diff_digits,
risk_digits,
ratio_digits,
ratio_digits_decrease,
rate_digits) {
if(is.na(exposure)) {
if(is.na(exposure) | exposure == "") {
data <- data %>%
dplyr::mutate(.exposure = "Overall")
} else {
Expand Down Expand Up @@ -238,6 +240,7 @@ fill_cells <- function(
diff_digits = diff_digits,
risk_digits = risk_digits,
ratio_digits = ratio_digits,
ratio_digits_decrease = ratio_digits_decrease,
rate_digits = rate_digits,
risk_percent = risk_percent,
to = to,
Expand Down Expand Up @@ -285,6 +288,7 @@ fill_cells <- function(
diff_digits = diff_digits,
risk_digits = risk_digits,
ratio_digits = ratio_digits,
ratio_digits_decrease = ratio_digits_decrease,
rate_digits = rate_digits,
risk_percent = risk_percent,
to = to,
Expand Down
5 changes: 4 additions & 1 deletion R/format_regression_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#'
#' @param data Data set
#' @param digits Number of digits to round estimates to
#' @param ratio_digits_decrease Ratios to round less
#' @param to Separator character(s) for confidence interval bounds
#' @param is_trend If called on a continous (trend) variable
#' @param nmin Suppress counts below
Expand All @@ -25,6 +26,7 @@ format_regression_results <- function(
is_trend,
multiply,
digits,
ratio_digits_decrease,
pattern,
xlevels,
reference,
Expand All @@ -49,7 +51,8 @@ format_regression_results <- function(
.data$conf.high),
.funs = ~format_round(
. * multiply,
digits = digits)) %>%
digits = digits,
ratio_digits_decrease = ratio_digits_decrease)) %>%
dplyr::full_join(
counts_per_stratum(
data = data,
Expand Down
8 changes: 4 additions & 4 deletions R/format_stratified_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ format_stratified_results <- function(
pattern = stringr::fixed("(NaN%)")),
"(--)"),
TRUE ~ .data$res),
res = dplyr::if_else(
.data$.per_stratum < nmin,
true = paste0("-- (<", nmin, ")"),
false = .data$res)) %>%
res = dplyr::case_when(
.data$.per_stratum < nmin ~
paste0("-- (<", nmin, ")"),
TRUE ~ .data$res)) %>%
dplyr::select(-.data$.per_stratum)
}
2 changes: 1 addition & 1 deletion R/input_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ find_argument <- function(
acceptable = NULL,
default = NA) {
argum <- default
if(!is.na(arguments)) {
if(any(!is.na(arguments))) {
if(is.list(arguments)) {
if(which_argument %in% names(arguments)) {
if(is_numeric) {
Expand Down
Loading

0 comments on commit d5d5152

Please sign in to comment.