diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index d6b8d02f1..de29e0020 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -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 ) ) diff --git a/R/tm_variable_browser.R b/R/tm_variable_browser.R index 40de67976..a1f79fc41 100644 --- a/R/tm_variable_browser.R +++ b/R/tm_variable_browser.R @@ -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) } diff --git a/R/utils.R b/R/utils.R index 1d2a1e56d..87b5b9884 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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. diff --git a/man/var_labels.Rd b/man/var_labels.Rd deleted file mode 100644 index 151778733..000000000 --- a/man/var_labels.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{var_labels} -\alias{var_labels} -\title{Get Label Attributes of Variables in a \code{data.frame}} -\usage{ -var_labels(x, fill = FALSE) -} -\arguments{ -\item{x}{a \code{data.frame} object} - -\item{fill}{boolean in case the \code{label} attribute does not exist if -\code{TRUE} the variable names is returned, otherwise \code{NA}} -} -\value{ -a named character vector with the variable labels, the names -correspond to the variable names -} -\description{ -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) -} -\note{ -the \code{formatters} package is the source of the function. -} -\keyword{internal}