Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions R/choices_labeled.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,15 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) {
combined_labels <- combined_labels[ord]
types <- types[ord]
}
choices <- structure(

structure(
choices,
names = combined_labels,
raw_labels = raw_labels,
combined_labels = combined_labels,
class = c("choices_labeled", "character"),
types = types
)

return(choices)
}

#' Wrapper on [choices_labeled] to label variables basing on existing labels in data
Expand Down Expand Up @@ -164,7 +163,7 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) {
#' # functional subset (with delayed data) - return only factor variables
#' variable_choices("ADRS", subset = function(data) {
#' idx <- vapply(data, is.factor, logical(1))
#' return(names(data)[idx])
#' names(data)[idx]
#' })
#' @export
#'
Expand Down Expand Up @@ -222,7 +221,7 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
subset <- unique(subset)
}

res <- if ("" %in% subset) {
if ("" %in% subset) {
choices_labeled(
choices = c("", names(data)),
labels = c("", unname(teal.data::col_labels(data, fill = fill))),
Expand All @@ -237,8 +236,6 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
types = var_types
)
}

return(res)
}

#' Wrapper on [choices_labeled] to label variable values basing on other variable values
Expand Down Expand Up @@ -276,7 +273,7 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
#'
#' # functional subset
#' value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data) {
#' return(levels(data$PARAMCD)[1:2])
#' levels(data$PARAMCD)[1:2]
#' })
#' @export
#'
Expand All @@ -302,7 +299,7 @@ value_choices.character <- function(data,
var_label = NULL,
subset = NULL,
sep = " - ") {
out <- structure(
structure(
list(
data = data,
var_choices = var_choices,
Expand All @@ -312,7 +309,6 @@ value_choices.character <- function(data,
),
class = c("delayed_value_choices", "delayed_data", "choices_labeled")
)
return(out)
}

#' @rdname value_choices
Expand Down Expand Up @@ -373,7 +369,7 @@ value_choices.data.frame <- function(data, # nolint
attr(res, "sep") <- sep
attr(res, "var_choices") <- var_choices
attr(res, "var_label") <- var_label
return(res)
res
}

#' Print choices_labeled object
Expand All @@ -397,5 +393,5 @@ print.choices_labeled <- function(x, ...) {
sep = "\n"
)

return(invisible(x))
invisible(x)
}
24 changes: 12 additions & 12 deletions R/choices_selected.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ no_select_keyword <- "-- no selection --"
#' # with delayed data loading
#' choices_selected(variable_choices("ADSL", subset = function(data) {
#' idx <- vapply(data, is.factor, logical(1))
#' return(names(data)[idx])
#' names(data)[idx]
#' }))
#'
#' cs <- choices_selected(
Expand Down Expand Up @@ -142,11 +142,12 @@ choices_selected <- function(choices,
}

if (inherits(choices, "delayed_data")) {
out <- structure(
list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed),
class = c("delayed_choices_selected", "delayed_data", "choices_selected")
return(
structure(
list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed),
class = c("delayed_choices_selected", "delayed_data", "choices_selected")
)
)
return(out)
}

if (!is.null(choices) && no_select_keyword %in% choices) {
Expand Down Expand Up @@ -254,8 +255,7 @@ vector_reorder <- function(vec, idx) {
}

attributes(vec) <- vec_attrs

return(vec)
vec
}

vector_pop <- function(vec, idx) {
Expand All @@ -277,7 +277,7 @@ vector_pop <- function(vec, idx) {

vec <- vec[-idx]
attributes(vec) <- vec_attrs
return(vec)
vec
}

vector_remove_dups <- function(vec) {
Expand All @@ -286,12 +286,12 @@ vector_remove_dups <- function(vec) {
idx <- which(duplicated(vec))

if (length(idx) == 0) {
return(vec)
vec
} else if (is.null(attributes(vec))) {
return(unique(vec))
unique(vec)
} else if (identical(names(attributes(vec)), "names")) {
return(vec[-idx])
vec[-idx]
} else {
return(vector_pop(vec, idx))
vector_pop(vec, idx)
}
}
39 changes: 19 additions & 20 deletions R/filter_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ filter_spec_internal.delayed_data <- function(vars_choices, # nolint
checkmate::check_class(selected, "all_choices")
)

out <- structure(
structure(
list(
vars_choices = vars_choices,
vars_selected = vars_selected,
Expand All @@ -355,7 +355,6 @@ filter_spec_internal.delayed_data <- function(vars_choices, # nolint
"delayed_data"
)
)
return(out)
}

#' @rdname filter_spec_internal
Expand Down Expand Up @@ -410,23 +409,23 @@ filter_spec_internal.default <- function(vars_choices,
checkmate::assert_subset(selected, choices)
}

res <- list(
vars_choices = vars_choices,
vars_selected = vars_selected,
vars_label = vars_label,
vars_fixed = vars_fixed,
vars_multiple = vars_multiple,
choices = choices,
selected = selected,
label = label,
multiple = multiple,
fixed = fixed,
sep = sep,
drop_keys = drop_keys,
dataname = dataname, # modified by data_extract_spec
initialized = initialized
structure(
list(
vars_choices = vars_choices,
vars_selected = vars_selected,
vars_label = vars_label,
vars_fixed = vars_fixed,
vars_multiple = vars_multiple,
choices = choices,
selected = selected,
label = label,
multiple = multiple,
fixed = fixed,
sep = sep,
drop_keys = drop_keys,
dataname = dataname, # modified by data_extract_spec
initialized = initialized
),
class = "filter_spec"
)
class(res) <- "filter_spec"

return(res)
}
8 changes: 2 additions & 6 deletions R/get_dplyr_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,10 @@ get_dplyr_call <- function(selector_list,
NULL
}

final_call <- Reduce(
Reduce(
function(x, y) call("%>%", x, y),
Filter(function(x) !is.null(x), c(dataname_filtered, filter_call, select_call, rename_call, reshape_call))
)

return(final_call)
}

#' Parse `dplyr` select call
Expand Down Expand Up @@ -639,12 +637,10 @@ get_reshape_unite_vals <- function(selector) {
)
unite_cols_vals <- unite_cols_vals[vapply(unite_cols_vals, length, integer(1)) > 0]

res <- if (length(unite_cols_vals) > 0) {
if (length(unite_cols_vals) > 0) {
grid <- do.call(expand.grid, args = list(unite_cols_vals, stringsAsFactors = FALSE))
apply(grid, 1, paste, collapse = "_")
} else {
character(0)
}

res
}
17 changes: 8 additions & 9 deletions R/get_merge_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ get_merge_call <- function(selector_list,
anl_merge_call_i
)
}
return(anl_merge_calls)

anl_merge_calls
}

#' Gets merge key pair list from keys list
Expand Down Expand Up @@ -443,7 +444,7 @@ get_anl_relabel_call <- function(columns_source, datasets, anl_name = "ANL") {
relabel_call
)

return(relabel_and_assign_call)
relabel_and_assign_call
}

#' Create relabel call from named character
Expand Down Expand Up @@ -482,12 +483,10 @@ get_relabel_call <- function(labels) {
labels <- labels[!duplicated(names(labels))]
labels <- labels[!is.na(labels)]

return(
as.call(
append(
quote(teal.data::col_relabel),
labels
)
as.call(
append(
quote(teal.data::col_relabel),
labels
)
)
}
Expand Down Expand Up @@ -517,7 +516,7 @@ get_relabel_cols <- function(columns_source, dplyr_call_data) {
return(NULL)
}
attr(column_source, "dataname") <- dataname
return(column_source)
column_source
}
)
}
2 changes: 1 addition & 1 deletion R/include_css_js.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ include_css_files <- function(pattern = "*") {
system.file("css", package = "teal.transform", mustWork = TRUE),
pattern = pattern, full.names = TRUE
)
return(singleton(lapply(css_files, includeCSS)))
singleton(lapply(css_files, includeCSS))
}
4 changes: 2 additions & 2 deletions R/merge_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ merge_datasets <- function(selector_list, datasets, join_keys, merge_function =
filter_info = filter_info
)
logger::log_trace("merge_datasets merge code executed resulting in { anl_name } dataset.")
return(res)
res
}

#' Merge selectors when `dataname`, `reshape`, `filters` and `keys` entries are identical
Expand Down Expand Up @@ -259,7 +259,7 @@ merge_selectors <- function(selector_list) {
}
}

return(list(res_list, res_map_id))
list(res_list, res_map_id)
}


Expand Down
Loading