Skip to content

Commit

Permalink
[skip style] [skip vbump] Restyle files
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 4, 2024
1 parent 7b738d1 commit 4f9a3f8
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 80 deletions.
6 changes: 3 additions & 3 deletions R/00tabletrees.R
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ setClass("LayoutAxisLeaf",
representation(
func = "function",
display_columncounts = "logical",
columncount_format = "FormatSpec", #character",
columncount_format = "FormatSpec", # character",
col_footnotes = "list",
column_count = "integer"
)
Expand All @@ -1117,7 +1117,7 @@ setClass("LayoutColTree",
contains = "LayoutAxisTree",
representation(
display_columncounts = "logical",
columncount_format = "FormatSpec", #"character",
columncount_format = "FormatSpec", # "character",
col_footnotes = "list",
column_count = "integer"
)
Expand Down Expand Up @@ -1803,7 +1803,7 @@ setClass("PreDataColLayout",
contains = "PreDataAxisLayout",
representation(
display_columncounts = "logical",
columncount_format = "FormatSpec" #"character"
columncount_format = "FormatSpec" # "character"
)
)

Expand Down
2 changes: 1 addition & 1 deletion R/colby_constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ basic_table <- function(title = "",
subtitles = character(),
main_footer = character(),
prov_footer = character(),
show_colcounts = NA, #FALSE,
show_colcounts = NA, # FALSE,
colcount_format = "(N=xx)",
header_section_div = NA_character_,
top_level_section_div = NA_character_,
Expand Down
6 changes: 4 additions & 2 deletions R/make_split_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ add_combo_facet <- function(name, label = name, levels, extra = list()) {
}


val <- LevelComboSplitValue(val = name, extr = extra, combolevels = levels, label = label,
sub_expr = subexpr)
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
Expand Down
5 changes: 3 additions & 2 deletions R/make_subset_expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ create_colinfo <- function(lyt, df, rtpos = TreePos(),
cc_format <- colcount_format(lyt) %||% "(N=xx)"

## do it this way for full backwards compatibility
if (is.null(alt_counts_df))
if (is.null(alt_counts_df)) {
alt_counts_df <- df
}
ctree <- coltree(clayout, df = df, rtpos = rtpos, alt_counts_df = alt_counts_df, ccount_format = cc_format)
if (!is.na(disp_ccounts(lyt))) {
leaf_pths <- make_col_df(ctree, visible_only = TRUE, na_str = "", ccount_format = cc_format)$path
Expand Down Expand Up @@ -253,7 +254,7 @@ create_colinfo <- function(lyt, df, rtpos = TreePos(),
}

counts_df_name <- "alt_counts_df"
if (identical(alt_counts_df, df)) { #is.null(alt_counts_df)) {
if (identical(alt_counts_df, df)) { # is.null(alt_counts_df)) {
alt_counts_df <- df
counts_df_name <- "df"
}
Expand Down
89 changes: 57 additions & 32 deletions R/tree_accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,8 @@ setMethod(
all_paths <- make_col_df(obj, visible_only = TRUE)$path
}
if (length(value) != length(all_paths)) {
stop("Got ", length(value), "values for ",
stop(
"Got ", length(value), "values for ",
length(all_paths), " column paths",
if (is.null(path)) " (from path = NULL)",
"."
Expand Down Expand Up @@ -2452,8 +2453,10 @@ match_path_by_pos <- function(kidlst, path) {
kidlst,
function(kd) {
pos <- tree_pos(kd)
c(obj_name(tail(pos_splits(pos), 1)[[1]]),
value_names(tail(pos_splvals(pos), 1))[[1]])
c(
obj_name(tail(pos_splits(pos), 1)[[1]]),
value_names(tail(pos_splvals(pos), 1))[[1]]
)
}
)

Expand All @@ -2464,16 +2467,16 @@ match_path_by_pos <- function(kidlst, path) {
},
TRUE
)
if (any(matches))
if (any(matches)) {
ret <- which(matches)
}
ret

}

## this is a horrible hack but when we have non-nested siblings at the top level
## the beginning of the "path <-> position" relationship breaks down.
## we probably *should* have e.g., c("root", "top_level_splname_1",
##"top_level_splname_1, "top_level_splname_1_value", ...)
## "top_level_splname_1, "top_level_splname_1_value", ...)
## but its pretty clear why no one will be happy with that, I think
## so we punt on the problem for now with an explicit workaround
##
Expand All @@ -2483,12 +2486,13 @@ root_match_finder <- function(kidlst, path) {
matches <- vapply(kidlst, function(kid) {
obj_name(kid) == path[1]
}, TRUE)
if (sum(matches) == 0)
if (sum(matches) == 0) {
stop("unable to find first-step match in path: ", path[1])
else if (sum(matches) > 1)
} else if (sum(matches) > 1) {
stop("multiple matches for first-step in path: ", path[1])
else
} else {
which(matches)
}
}


Expand All @@ -2507,28 +2511,32 @@ pos_singleton_path <- function(obj) {
## close to a duplicate of tt_at_path, but... not quite :(
#' @rdname int_methods
coltree_at_path <- function(obj, path, ...) {
if (length(path) == 0)
if (length(path) == 0) {
return(obj)
}
stopifnot(
is(path, "character"),
length(path) > 0
)
if (any(grepl("@content", path, fixed = TRUE)))
if (any(grepl("@content", path, fixed = TRUE))) {
stop("@content token is not valid for column paths.")
}


## if(obj_name(obj) == path[1]) {
## path <- path[-1]
## }
cur <- obj
curpath <- pos_to_path(tree_pos(obj)) #path
curpath <- pos_to_path(tree_pos(obj)) # path
num_consume_path <- 2
while (!identical(curpath, path) && !is(cur, "LayoutColLeaf")) { #length(curpath) > 0) {
while (!identical(curpath, path) && !is(cur, "LayoutColLeaf")) { # length(curpath) > 0) {
kids <- tree_children(cur)
kidmatch <- find_kid_path_match(kids, path)
if (length(kidmatch) == 0) {
stop("unable to match full path: ", paste(path, sep = "->"),
"\n path of last match: ", paste(curpath, sep = "->"))
stop(
"unable to match full path: ", paste(path, sep = "->"),
"\n path of last match: ", paste(curpath, sep = "->")
)
}
cur <- kids[[kidmatch]]
curpath <- pos_to_path(tree_pos(cur))
Expand All @@ -2537,8 +2545,9 @@ coltree_at_path <- function(obj, path, ...) {
}

find_kid_path_match <- function(kids, path) {
if (length(kids) == 0)
if (length(kids) == 0) {
return(integer())
}
kidpaths <- lapply(kids, function(k) pos_to_path(tree_pos(k)))

matches <- vapply(kidpaths, function(kpth) identical(path[seq_along(kpth)], kpth), NA)
Expand All @@ -2556,8 +2565,10 @@ ct_recursive_replace <- function(ctree, path, value, pos = 1) {
if (identical(path, curpth)) {
return(value)
} else if (is(ctree, "LayoutColLeaf")) {
stop("unable to match full path: ", paste(path, sep = "->"),
"\n path at leaf: ", paste(curpth, sep = "->"))
stop(
"unable to match full path: ", paste(path, sep = "->"),
"\n path at leaf: ", paste(curpth, sep = "->")
)
}
kids <- tree_children(ctree)
kids_singl <- pos_singleton_path(kids[[1]])
Expand All @@ -2566,12 +2577,16 @@ ct_recursive_replace <- function(ctree, path, value, pos = 1) {
if (length(kidind) == 0) {
stop("Path appears invalid for this tree at step ", path[1])
} else if (length(kidind) > 1) {
stop("singleton step (root, cbind_root, etc) in path appears to have matched multiple children. ",
"This shouldn't happen, please contact the maintainers.")
stop(
"singleton step (root, cbind_root, etc) in path appears to have matched multiple children. ",
"This shouldn't happen, please contact the maintainers."
)
}

kids[[kidind]] <- ct_recursive_replace(kids[[kidind]],
path, value)
kids[[kidind]] <- ct_recursive_replace(
kids[[kidind]],
path, value
)
tree_children(ctree) <- kids
ctree
}
Expand Down Expand Up @@ -2631,8 +2646,10 @@ ct_recursive_replace <- function(ctree, path, value, pos = 1) {
#' @examples
#' lyt <- basic_table() %>%
#' split_cols_by("ARM", show_colcounts = TRUE) %>%
#' split_cols_by("SEX", split_fun = keep_split_levels(c("F", "M")),
#' show_colcounts = TRUE) %>%
#' split_cols_by("SEX",
#' split_fun = keep_split_levels(c("F", "M")),
#' show_colcounts = TRUE
#' ) %>%
#' split_cols_by("STRATA1", show_colcounts = TRUE) %>%
#' analyze("AGE")
#'
Expand All @@ -2648,12 +2665,15 @@ ct_recursive_replace <- function(ctree, path, value, pos = 1) {
#' ## show black space for certain counts by assign NA
#'
#' facet_colcount(tbl, c("ARM", "A: Drug X", "SEX", "F", "STRATA1", "C")) <- NA
setGeneric("facet_colcount",
function(obj, path) standardGeneric("facet_colcount"))
setGeneric(
"facet_colcount",
function(obj, path) standardGeneric("facet_colcount")
)

#' @rdname facet_colcount
#' @export
setMethod("facet_colcount", "LayoutColTree",
setMethod(
"facet_colcount", "LayoutColTree",
function(obj, path = NULL) {
## if(length(path) == 0L)
## stop("face_colcount requires a non-null path") #nocov
Expand All @@ -2664,7 +2684,8 @@ setMethod("facet_colcount", "LayoutColTree",

#' @rdname facet_colcount
#' @export
setMethod("facet_colcount", "LayoutColLeaf",
setMethod(
"facet_colcount", "LayoutColLeaf",
function(obj, path = NULL) {
## not sure if we should check for null here as above
obj@column_count
Expand Down Expand Up @@ -2758,13 +2779,17 @@ setGeneric("colcount_visible", function(obj, path) standardGeneric("colcount_vis

#' @rdname colcount_visible
#' @export
setMethod("colcount_visible", "VTableTree",
function(obj, path) colcount_visible(coltree(obj), path))
setMethod(
"colcount_visible", "VTableTree",
function(obj, path) colcount_visible(coltree(obj), path)
)

#' @rdname colcount_visible
#' @export
setMethod("colcount_visible", "InstantiatedColumnInfo",
function(obj, path) colcount_visible(coltree(obj), path))
setMethod(
"colcount_visible", "InstantiatedColumnInfo",
function(obj, path) colcount_visible(coltree(obj), path)
)

#' @rdname colcount_visible
#' @export
Expand Down
35 changes: 22 additions & 13 deletions R/tt_compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,17 @@ EmptyTreePos <- TreePos()
## must be pathable, which they aren't if siblings have
## identical names
fix_col_nm_recursive <- function(ct, newname, rename_obj = TRUE, oldnm) {
if (rename_obj)
if (rename_obj) {
obj_name(ct) <- newname
}
if (is(ct, "LayoutColTree")) {
kids <- tree_children(ct)
kidnms <- names(kids)
newkids <- lapply(kids, fix_col_nm_recursive,
newname = newname,
rename_obj = FALSE,
oldnm = oldnm)
newname = newname,
rename_obj = FALSE,
oldnm = oldnm
)
names(newkids) <- kidnms
tree_children(ct) <- newkids
}
Expand All @@ -577,19 +579,25 @@ fix_col_nm_recursive <- function(ct, newname, rename_obj = TRUE, oldnm) {
if (!rename_obj) {
spls <- pos_splits(mypos)
splvals <- pos_splvals(mypos)
pos_splits(mypos) <- c(list(AllSplit(split_name = newname)),
spls)
pos_splvals(mypos) <- c(list(SplitValue(NA_character_,
sub_expr = quote(TRUE))),
splvals)
pos_splits(mypos) <- c(
list(AllSplit(split_name = newname)),
spls
)
pos_splvals(mypos) <- c(
list(SplitValue(NA_character_,
sub_expr = quote(TRUE)
)),
splvals
)
tree_pos(ct) <- mypos
}
ct
}

fix_nms <- function(ct) {
if (is(ct, "LayoutColLeaf"))
if (is(ct, "LayoutColLeaf")) {
return(ct)
}
kids <- lapply(tree_children(ct), fix_nms)
names(kids) <- vapply(kids, obj_name, "")
tree_children(ct) <- kids
Expand Down Expand Up @@ -619,7 +627,7 @@ combine_cinfo <- function(..., new_total = NULL, sync_count_vis) {
nms <- make_cbind_names(num = length(oldnms), tokens = path_els)

ctrees <- mapply(function(ct, nm, oldnm) {
ct <- fix_col_nm_recursive(ct, nm, rename_obj = TRUE, oldnm = "")#oldnm)
ct <- fix_col_nm_recursive(ct, nm, rename_obj = TRUE, oldnm = "") # oldnm)
ct
}, ct = ctrees, nm = nms, oldnm = oldnms, SIMPLIFY = FALSE)
names(ctrees) <- nms
Expand All @@ -632,10 +640,11 @@ combine_cinfo <- function(..., new_total = NULL, sync_count_vis) {
}
newexprs <- unlist(lapply(cinfs, col_exprs), recursive = FALSE)
newexargs <- unlist(lapply(cinfs, col_extra_args), recursive = FALSE) %||% vector("list", length(newcounts))
if (!sync_count_vis)
if (!sync_count_vis) {
newdisp <- NA
else
} else {
newdisp <- any(vapply(cinfs, disp_ccounts, NA))
}
alltls <- lapply(cinfs, top_left)
newtl <- character()
if (!are(tabs, "TableRow")) {
Expand Down
7 changes: 4 additions & 3 deletions R/tt_showmethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ lastposmsg <- function(pos) {
spls <- pos_splits(pos)
splvals <- value_names(pos_splvals(pos))
indiv_msgs <- unlist(mapply(function(spl, valnm) paste(obj_name(spl), valnm, sep = ": "),
spl = spls,
valnm = splvals,
SIMPLIFY = FALSE))
spl = spls,
valnm = splvals,
SIMPLIFY = FALSE
))
paste(indiv_msgs, collapse = " -> ")
}

Expand Down
Loading

0 comments on commit 4f9a3f8

Please sign in to comment.