Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Apr 9, 2024
1 parent ea5f068 commit 2b93b01
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
66 changes: 34 additions & 32 deletions R/make_split_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ validate_split_result <- function(pinfo, component = NULL) {
#' @param labels (`character`)\cr the labels associated with each facet.
#' @param extras (`list` or `NULL`)\cr extra values associated with each of the facets which will be passed to
#' analysis functions applied within the facet.
#' @param subset_exprs (`list`)\cr a list of subsetting expressions (e.g., created with `quote()`) to be used
#' @param subset_exprs (`list`)\cr a list of subsetting expressions (e.g., created with `quote()`) to be used
#' during column subsetting.
#'
#' @return A named list representing the facets generated by the split with elements `values`, `datasplit`, and
Expand All @@ -91,9 +91,9 @@ validate_split_result <- function(pinfo, component = NULL) {
#' These functions performs various housekeeping tasks to ensure that the split result list is as the rtables
#' internals expect it, most of which are not relevant to end users.
#'
#' @note Column splitting will not work correctly if a split function calls `make_split_result` without specifying
#' subset expressions; row splitting will work as normal. This is due to the fact that subsetting expressions are
#' used during column splitting to represent the data associated with facets, while actual data subsets are used
#' @note Column splitting will not work correctly if a split function calls `make_split_result` without specifying
#' subset expressions; row splitting will work as normal. This is due to the fact that subsetting expressions are
#' used during column splitting to represent the data associated with facets, while actual data subsets are used
#' during row splitting.
#'
#' @examples
Expand Down Expand Up @@ -176,8 +176,8 @@ add_to_split_result <- function(splres, values, datasplit, labels, extras = NULL
#' `labels`, and can optionally accept `.spl_context`. They must return a split result object constructed via
#' `make_split_result()`.
#'
#' In particular, if the custom split function will be used in column space, subsetting expressions (e.g., as returned by
#' `quote()` or `bquote()` must be provided, while they are optional (and largely ignored, currently) in row space.
#' In particular, if the custom split function will be used in column space, subsetting expressions (e.g., as returned
#' by `quote()` or `bquote()` must be provided, while they are optional (and largely ignored, currently) in row space.
#'
#' Post-processing functions (3) must accept the result of the core split as their first argument (which can be
#' anything), in addition to `spl`, and `fulldf`, and can optionally accept `.spl_context`. They must each return a
Expand Down Expand Up @@ -336,41 +336,43 @@ make_split_fun <- function(pre = list(), core_split = NULL, post = list()) {
#' @family make_custom_split
#' @export
add_combo_facet <- function(name, label = name, levels, extra = list()) {
function(ret, spl, .spl_context, fulldf) {
if(is(levels, "AllLevelsSentinel")) {
subexpr <- expression(TRUE)
datpart <- list(fulldf)
} else {
subexpr <- Reduce(.or_combine_exprs, lapply(ret$value[levels], value_expr))
datpart <- list(do.call(rbind, ret$datasplit[levels]))
}
function(ret, spl, .spl_context, fulldf) {
if (is(levels, "AllLevelsSentinel")) {
subexpr <- expression(TRUE)
datpart <- list(fulldf)
} else {
subexpr <- Reduce(.or_combine_exprs, lapply(ret$value[levels], value_expr))
datpart <- list(do.call(rbind, ret$datasplit[levels]))
}


val <- LevelComboSplitValue(val = name, extr = extra, combolevels = levels, label = label,
sub_expr = subexpr)
add_to_split_result(ret,
values = list(val), labels = label,
datasplit = datpart
)
val <- LevelComboSplitValue(
val = name, extr = extra, combolevels = levels, label = label,
sub_expr = subexpr
)
add_to_split_result(ret,
values = list(val), labels = label,
datasplit = datpart
)
}
}


.or_combine_exprs <- function(ex1, ex2) {
if(is.null(ex1) || identical(ex1, expression(FALSE))) {
if(is.expression(ex2) && !identical(ex2, expression(FALSE))) {
return(ex2)
} else {
return(expression(FALSE))
}
} else if (is.null(ex2) || identical(ex2, expression(FALSE))) {
return(ex1)
} else if(identical(ex1, expression(TRUE)) ||
identical(ex2, expression(TRUE))) {
return(expression(TRUE))
if (is.null(ex1) || identical(ex1, expression(FALSE))) {
if (is.expression(ex2) && !identical(ex2, expression(FALSE))) {
return(ex2)
} else {
return(expression(FALSE))
}
} else if (is.null(ex2) || identical(ex2, expression(FALSE))) {
return(ex1)
} else if (identical(ex1, expression(TRUE)) ||
identical(ex2, expression(TRUE))) { # nolint
return(expression(TRUE))
}

as.expression(bquote((.(a)) | .(b), list(a = ex1[[1]], b = ex2[[1]])))
as.expression(bquote((.(a)) | .(b), list(a = ex1[[1]], b = ex2[[1]])))
}

#' @rdname add_combo_facet
Expand Down
4 changes: 2 additions & 2 deletions man/make_split_fun.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b93b01

Please sign in to comment.