From 053e0b032a5f87e58ef1194eeb8aa52ec7441450 Mon Sep 17 00:00:00 2001 From: Dillon Hammill Date: Mon, 27 Jul 2020 16:32:44 +1000 Subject: [PATCH] Handle NA columns for dropdowns specified in col_options. --- R/data_edit.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/data_edit.R b/R/data_edit.R index 7914352..6e906fa 100644 --- a/R/data_edit.R +++ b/R/data_edit.R @@ -195,14 +195,22 @@ data_edit <- function(x, # COLUMN OPTIONS - LOGICAL if(!is.null(col_options)){ lapply(names(col_options), function(z){ - if(is.logical(type.convert(col_options[[z]]))){ + col_type <- type.convert(col_options[[z]], as.is = TRUE) + # CHECKBOXES + if(is.logical(col_type)){ if(!is.logical(x[, z])){ - res <- type.convert(x[, z]) + res <- type.convert(x[, z], as.is = TRUE) if(!is.logical(res)){ res <- rep(NA, nrow(x)) } x[, z] <<- res } + # DROPDOWN MENUS + }else{ + # NA TO EMPTY CHARACTERS + if(all(is.na(x[, z]))){ + x[, z] <<- rep("", nrow(x)) + } } }) } @@ -330,6 +338,10 @@ data_edit <- function(x, if(length(empty_col_names) > 0){ colnames(x_new)[empty_col_names] <- old_col_names[empty_col_names] values[["x"]] <- x_new + # REVERT COLUMN NAME EDITS + }else if(col_names == FALSE){ + colnames(x_new) <- old_col_names + values[["x"]] <- x_new } # ROW NAMES CANNOT BE EDITED } else if ("rowHeaders" %in% names(input$x_changeHeaders)) {