Skip to content

Commit

Permalink
Merge pull request #93 from atorus-research/devel
Browse files Browse the repository at this point in the history
Tplyr 1.0.0 Release to Main
  • Loading branch information
elimillera authored Oct 14, 2022
2 parents dabbcbf + aca6f57 commit ec1dbbb
Show file tree
Hide file tree
Showing 173 changed files with 21,610 additions and 16,571 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
inst/doc
Tplyr.Rproj
docs/
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Tplyr
Title: A Grammar of Clinical Data Summary
Version: 0.4.4
Title: A Traceability Focused Grammar of Clinical Data Summary
Version: 1.0.0
Authors@R:
c(
person(given = "Eli",
Expand All @@ -25,7 +25,7 @@ Authors@R:
person(given = "Atorus Research LLC",
role = "cph")
)
Description: A tool created to simplify the data manipulation necessary to create clinical reports.
Description: A traceability focused tool created to simplify the data manipulation necessary to create clinical summaries.
License: MIT + file LICENSE
URL: https://github.com/atorus-research/Tplyr
BugReports: https://github.com/atorus-research/Tplyr/issues
Expand Down Expand Up @@ -55,6 +55,6 @@ Suggests:
pharmaRTF,
withr
VignetteBuilder: knitr
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
RdMacros: lifecycle
Config/testthat/edition: 3
43 changes: 43 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Generated by roxygen2: do not edit by hand

S3method(build,tplyr_table)
S3method(get_meta_result,data.frame)
S3method(get_meta_result,tplyr_table)
S3method(get_meta_subset,data.frame)
S3method(get_meta_subset,tplyr_table)
S3method(get_numeric_data,tplyr_layer)
S3method(get_numeric_data,tplyr_table)
S3method(get_stats_data,tplyr_layer)
Expand All @@ -9,37 +13,55 @@ S3method(get_where,tplyr_layer)
S3method(get_where,tplyr_table)
S3method(print,f_str)
S3method(print,tplyr_layer)
S3method(print,tplyr_layer_template)
S3method(print,tplyr_meta)
S3method(print,tplyr_table)
S3method(process_formatting,count_layer)
S3method(process_formatting,desc_layer)
S3method(process_formatting,shift_layer)
S3method(process_metadata,count_layer)
S3method(process_metadata,desc_layer)
S3method(process_metadata,shift_layer)
S3method(process_metadata,tplyr_riskdiff)
S3method(process_statistic_data,tplyr_riskdiff)
S3method(process_statistic_formatting,tplyr_riskdiff)
S3method(process_summaries,count_layer)
S3method(process_summaries,desc_layer)
S3method(process_summaries,shift_layer)
S3method(set_denoms_by,count_layer)
S3method(set_denoms_by,shift_layer)
S3method(set_format_strings,count_layer)
S3method(set_format_strings,desc_layer)
S3method(set_where,tplyr_layer)
S3method(set_where,tplyr_table)
S3method(str,f_str)
S3method(str,tplyr_layer)
S3method(str,tplyr_table)
export("%>%")
export("header_n<-")
export("pop_data<-")
export(add_column_headers)
export(add_filters)
export(add_layer)
export(add_layers)
export(add_risk_diff)
export(add_total_group)
export(add_total_row)
export(add_treat_grps)
export(add_variables)
export(append_metadata)
export(apply_formats)
export(apply_row_masks)
export(build)
export(f_str)
export(get_by)
export(get_count_layer_formats)
export(get_desc_layer_formats)
export(get_layer_template)
export(get_layer_templates)
export(get_meta_result)
export(get_meta_subset)
export(get_metadata)
export(get_numeric_data)
export(get_pop_where)
export(get_precision_by)
Expand All @@ -53,12 +75,15 @@ export(group_desc)
export(group_shift)
export(header_n)
export(keep_levels)
export(new_layer_template)
export(pop_data)
export(pop_treat_var)
export(process_formatting)
export(process_metadata)
export(process_statistic_data)
export(process_statistic_formatting)
export(process_summaries)
export(remove_layer_template)
export(set_by)
export(set_count_layer_formats)
export(set_custom_summaries)
Expand All @@ -72,46 +97,58 @@ export(set_header_n)
export(set_indentation)
export(set_missing_count)
export(set_nest_count)
export(set_numeric_threshold)
export(set_order_count_method)
export(set_ordering_cols)
export(set_outer_sort_position)
export(set_pop_data)
export(set_pop_treat_var)
export(set_pop_where)
export(set_precision_by)
export(set_precision_data)
export(set_precision_on)
export(set_result_order_var)
export(set_shift_layer_formats)
export(set_stats_as_columns)
export(set_target_var)
export(set_total_row_label)
export(set_treat_var)
export(set_where)
export(str_indent_wrap)
export(tplyr_layer)
export(tplyr_meta)
export(tplyr_table)
export(treat_grps)
export(treat_var)
export(use_template)
importFrom(assertthat,assert_that)
importFrom(dplyr,across)
importFrom(dplyr,add_tally)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
importFrom(dplyr,as_tibble)
importFrom(dplyr,between)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,case_when)
importFrom(dplyr,cur_group)
importFrom(dplyr,distinct)
importFrom(dplyr,do)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_keys)
importFrom(dplyr,if_else)
importFrom(dplyr,lag)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_all)
importFrom(dplyr,mutate_at)
importFrom(dplyr,mutate_if)
importFrom(dplyr,n)
importFrom(dplyr,n_distinct)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,row_number)
importFrom(dplyr,rowwise)
Expand All @@ -128,6 +165,7 @@ importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,deprecate_stop)
importFrom(magrittr,"%>%")
importFrom(magrittr,extract)
importFrom(magrittr,extract2)
importFrom(purrr,flatten)
importFrom(purrr,imap)
importFrom(purrr,map)
Expand Down Expand Up @@ -178,12 +216,14 @@ importFrom(rlang,is_quosure)
importFrom(rlang,is_quosures)
importFrom(rlang,quo)
importFrom(rlang,quo_get_expr)
importFrom(rlang,quo_is_call)
importFrom(rlang,quo_is_missing)
importFrom(rlang,quo_is_null)
importFrom(rlang,quo_is_symbol)
importFrom(rlang,quo_name)
importFrom(rlang,quos)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(rlang,trace_back)
importFrom(rlang,warn)
importFrom(stats,IQR)
Expand All @@ -198,6 +238,7 @@ importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_extract_all)
importFrom(stringr,str_locate_all)
importFrom(stringr,str_match_all)
importFrom(stringr,str_pad)
importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace)
Expand All @@ -206,6 +247,7 @@ importFrom(stringr,str_split)
importFrom(stringr,str_starts)
importFrom(stringr,str_sub)
importFrom(stringr,str_trim)
importFrom(stringr,str_wrap)
importFrom(tibble,add_column)
importFrom(tibble,rownames_to_column)
importFrom(tibble,tibble)
Expand All @@ -218,6 +260,7 @@ importFrom(tidyr,starts_with)
importFrom(tidyselect,all_of)
importFrom(tidyselect,any_of)
importFrom(tidyselect,vars_select)
importFrom(utils,capture.output)
importFrom(utils,head)
importFrom(utils,str)
importFrom(utils,tail)
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Tplyr 1.0.0

- New features
- Introduction of traceability metadata framework #32
- Framework for creating re-usable layer templates #66
- Native pipe compatibility #33
- Automatically load magrittr pipe #22
- Refactor of count layer programming #28
- Allow external precision data for desc layers #27
- Allow denominators within count layers as formattable values #11
- Descriptive statistics layers allow stats as columns #37
- New experimental function `set_numeric_threshold()`
- Apply f_str's outside of a Tplyr table with new function `apply_formats()` #57
- New post processing function helper `str_indent_wrap()` for hyphen-enabled string wrapping #59
- Bug fixes
- Fix errors in partially provided precision caps #20

# Tplyr 0.4.4

- Added new functionality per issue #10. Adds 'Both' an option for sorting outer layers of nested count.
Expand Down
63 changes: 63 additions & 0 deletions R/apply_formats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#' Apply Format Strings outside of a Tplyr table
#'
#' The `f_str` object in Tplyr is used to drive formatting of the outputs
#' strings within a Tplyr table. This function allows a user to use the same
#' interface to apply formatted string on any data frame within a
#' `dplyr::mutate()` context.
#'
#' Note that auto-precision is not currently supported within `apply_formats()`
#'
#' @param format_string The desired display format. X's indicate digits. On the
#' left, the number of x's indicates the integer length. On the right, the
#' number of x's controls decimal precision and rounding. Variables are
#' inferred by any separation of the 'x' values other than a decimal.
#' @param ... The variables to be formatted using the format specified in
#' \code{format_string}. These must be numeric variables.
#' @param empty The string to display when the numeric data is not available.
#' Use a single element character vector, with the element named '.overall' to
#' instead replace the whole string.
#'
#' @return Character vector of formatted values
#' @md
#' @export
#'
#' @examples
#'
#' library(dplyr)
#'
#' mtcars %>%
#' head() %>%
#' mutate(
#' fmt_example = apply_formats('xxx (xx.x)', hp, wt)
#' )
apply_formats <- function(format_string, ..., empty = c(.overall = "")) {
format <- f_str(format_string, ..., empty=empty)

if (format$auto_precision) {
stop('Auto-precision is not currently supported within the `apply_formats()` context',
call.=FALSE)
}

pmap_chr(list(...), function(...) apply_fmts(...), fmt=format)
}

#' Application of individual format string
#'
#' This is what's used internally on the vectorized apply_formats
#'
#' @param ... The variables to be formatted using the format specified in
#' the `f_str` object
#' @param fmt An f_str object
#' @md
#'
#' @return An individually formatted string
#' @noRd
apply_fmts <- function(..., fmt) {
nums <- list(...)
repl <- vector('list', length(fmt$settings))
for (i in seq_along(fmt$settings)) {
repl[[i]] <- num_fmt(nums[[i]], i, fmt=fmt)
}
args <- append(list(fmt$repl_str), repl)
do.call('sprintf', args)
}
4 changes: 2 additions & 2 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ assert_quo_var_present <- function(quo_list, vnames=NULL, envir=NULL, allow_char
# Check each element of the `quo_list` list
for (v in quo_list) {

if (class(quo_get_expr(v)) == "name") {
if (inherits(quo_get_expr(v), "name")) {
vname <- as_name(quo_get_expr(v))
assert_that(vname %in% vnames,
msg = paste0("`", param, "` variable `",vname, "` does not exist in target dataset"))
Expand Down Expand Up @@ -203,7 +203,7 @@ unpack_vars <- function(quo_list, allow_character=TRUE) {
#'
#' @noRd
is_null_or_call <- function(quo_var) {
quo_is_null(quo_var) || class(quo_get_expr(quo_var)) == "call"
quo_is_null(quo_var) || inherits(quo_get_expr(quo_var), "call")
}

#' Check if a quosure is null or contains a logical value
Expand Down
Loading

0 comments on commit ec1dbbb

Please sign in to comment.