diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 00ea4778cc..a92de3fcbd 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -693,9 +693,9 @@ DataSheet$set("public", "add_columns_to_data", function(col_name = "", col_data, } } - if(length(col_name) != num_cols) { + if(length(col_name) != num_cols && (num_cols == 1 || length(col_name) == 1)) { use_col_name_as_prefix = TRUE - } + } else use_col_name_as_prefix = FALSE replaced <- FALSE previous_length = self$get_column_count() @@ -712,8 +712,10 @@ DataSheet$set("public", "add_columns_to_data", function(col_name = "", col_data, if(require_correct_length) stop("Length of new column must be divisible by the length of the data frame") else curr_col <- rep(curr_col, length.out = self$get_data_frame_length()) } - if(use_col_name_as_prefix) curr_col_name = self$get_next_default_column_name(col_name[i]) - else curr_col_name = col_name[[i]] +print(use_col_name_as_prefix) + if(use_col_name_as_prefix) curr_col_name = self$get_next_default_column_name(col_name) + else curr_col_name = col_name[i] + curr_col_name <- make.names(iconv(curr_col_name, to = "ASCII//TRANSLIT", sub = ".")) new_col_names <- c(new_col_names, curr_col_name) if(curr_col_name %in% self$get_column_names()) {