Skip to content

Commit

Permalink
remove the function delete_columns()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse committed Dec 7, 2023
1 parent d761257 commit a7d12d1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 61 deletions.
12 changes: 3 additions & 9 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ plot_score_table <- function(scores,
id_vars <- get_forecast_unit(scores)
metrics <- get_metrics(scores)

scores <- delete_columns(
scores,
names(scores)[!(names(scores) %in% c(metrics, id_vars))]
)
cols_to_delete <- names(scores)[!(names(scores) %in% c(metrics, id_vars))]
suppressWarnings(scores[, eval(cols_to_delete) := NULL])

# compute scaled values ------------------------------------------------------
# scaling is done in order to colour the different scores
Expand Down Expand Up @@ -403,11 +401,7 @@ plot_predictions <- function(data,
del_cols <-
colnames(truth_data)[!(colnames(truth_data) %in% c(by, "observed", x))]

truth_data <- delete_columns(
truth_data,
del_cols,
make_unique = TRUE
)
truth_data <- unique(suppressWarnings(truth_data[, eval(del_cols) := NULL]))

# find out what type of predictions we have. convert sample based to
# range data
Expand Down
28 changes: 0 additions & 28 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,6 @@ available_metrics <- function() {
}


#' Safely delete Columns From a Data.table
#'
#' @description take a vector of column names and delete the columns if they
#' are present in the data.table
#' @param df A data.table or data.frame from which columns shall be deleted
#' @param cols_to_delete character vector with names of columns to be deleted
#' @param make_unique whether to make the data set unique after removing columns
#' @importFrom data.table as.data.table
#' @return A data.table
#'
#' @keywords internal
#'
delete_columns <- function(df, cols_to_delete, make_unique = FALSE) {
df <- data.table::as.data.table(df)
delete_columns <- names(df)[names(df) %in% cols_to_delete]
if (length(delete_columns) > 0) {
if (make_unique) {
df <- unique(df[, eval(delete_columns) := NULL])
} else {
df <- df[, eval(delete_columns) := NULL]
}
}
return(df)
}

remove_na_observed_predicted <- function(data) {
# remove rows where predicted or observed value are NA -----------------------
data <- data[!is.na(observed) & !is.na(predicted)]
Expand All @@ -45,9 +20,6 @@ remove_na_observed_predicted <- function(data) {
}





#' @title Collapse several messages to one
#'
#' @description Internal helper function to facilitate generating messages
Expand Down
2 changes: 1 addition & 1 deletion R/utils_data_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ quantile_to_interval.data.frame <- function(dt,
}

if (format == "wide") {
delete_columns(dt, "quantile")
suppressWarnings(dt[, "quantile" := NULL])
dt <- dcast(dt, ... ~ boundary, value.var = "predicted")
# if there are NA values in `predicted`, this introduces a column "NA"
if ("NA" %in% colnames(dt) && all(is.na(dt[["NA"]]))) {
Expand Down
23 changes: 0 additions & 23 deletions man/delete_columns.Rd

This file was deleted.

0 comments on commit a7d12d1

Please sign in to comment.