From 2ac9a4d735a1ba0bb64226564c4b205520aeffbd Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski <114988527+chlebowa@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:56:12 +0100 Subject: [PATCH] 658 remove var labels@pre release@main (#673) Closes #658 All instances of `var_labels` were replaced with `teal.data::col_labels`. Source for `var_labels` was removed. --- R/tm_a_pca.R | 2 +- R/tm_missing_data.R | 2 +- R/tm_variable_browser.R | 2 +- R/utils.R | 48 ----------------------------------------- man/var_labels.Rd | 27 ----------------------- 5 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 man/var_labels.Rd diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index a21edc708..a692e589f 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -294,7 +294,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl response[[i]]$select$multiple <- FALSE response[[i]]$select$always_selected <- NULL response[[i]]$select$selected <- NULL - response[[i]]$select$choices <- var_labels(isolate(data())[[response[[i]]$dataname]]) + response[[i]]$select$choices <- teal.data::col_labels(isolate(data())[[response[[i]]$dataname]]) response[[i]]$select$choices <- setdiff( response[[i]]$select$choices, unlist(teal.data::join_keys(isolate(data()))[[response[[i]]$dataname]]) diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index a5060206d..4e856dffd 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 239dc26eb..2e5a53ed5 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 0262e0b49..ef6702ee6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -272,54 +272,6 @@ include_css_files <- function(pattern = "*") { } -#' 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}