Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the internal function var_labels in favour of teal.data::col_labels #690

Merged
merged 1 commit into from
Feb 27, 2024
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
2 changes: 1 addition & 1 deletion R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
},
env = list(
new_col_name = new_col_name,
column_labels_value = c(var_labels(data_r())[selected_vars()],
column_labels_value = c(teal.data::col_labels(data_r())[selected_vars()],
new_col_name = new_col_name
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ get_plotted_data <- function(input, plot_var, data) {
varname <- plot_var$variable[[dataset_name]]
df <- data()[[dataset_name]]

var_description <- var_labels(df)[[varname]]
var_description <- teal.data::col_labels(df)[[varname]]
list(data = df[[varname]], var_description = var_description)
}

Expand Down
49 changes: 0 additions & 49 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,55 +287,6 @@ include_css_files <- function(pattern = "*") {
return(shiny::singleton(shiny::tags$head(lapply(css_files, shiny::includeCSS))))
}


#' Get Label Attributes of Variables in a \code{data.frame}
#'
#' Variable labels can be stored as a \code{label} attribute for each variable.
#' This functions returns a named character vector with the variable labels
#' (empty sting if not specified)
#'
#' @param x a \code{data.frame} object
#' @param fill boolean in case the \code{label} attribute does not exist if
#' \code{TRUE} the variable names is returned, otherwise \code{NA}
#'
#' @return a named character vector with the variable labels, the names
#' correspond to the variable names
#'
#' @note the `formatters` package is the source of the function.
#'
#' @keywords internal
var_labels <- function(x, fill = FALSE) {
stopifnot(is.data.frame(x))
if (NCOL(x) == 0) {
return(character())
}

y <- Map(function(col, colname) {
label <- attr(col, "label")

if (is.null(label)) {
if (fill) {
colname
} else {
NA_character_
}
} else {
if (!is.character(label) && !(length(label) == 1)) {
stop("label for variable ", colname, "is not a character string")
}
as.vector(label)
}
}, x, colnames(x))

labels <- unlist(y, recursive = FALSE, use.names = TRUE)

if (!is.character(labels)) {
stop("label extraction failed")
}

labels
}

#' Get a string with java-script code checking if the specific tab is clicked
#' @description will be the input for `shiny::conditionalPanel()`
#' @param id `character(1)` the id of the tab panel with tabs.
Expand Down
27 changes: 0 additions & 27 deletions man/var_labels.Rd

This file was deleted.

Loading