From 9462617c7e74d14e3ce6f63e9833d23689e19240 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Wed, 31 Jul 2024 14:39:45 +0300 Subject: [PATCH 1/3] bug fixes in adding columns --- instat/static/InstatObject/R/data_object_R6.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 8ab9363348a..fec9f351bf3 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -712,7 +712,7 @@ 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]) + 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) From 6c162f444d3d048ea93ac318e7f95f7301ab5097 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Wed, 7 Aug 2024 16:41:07 +0300 Subject: [PATCH 2/3] minor code change --- instat/static/InstatObject/R/data_object_R6.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index fec9f351bf3..64bf2546137 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -712,8 +712,9 @@ 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) - else curr_col_name = col_name[[i]] + else curr_col_name = col_name 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()) { From 5e670184882cc87125d8cd5e8629bf0445716172 Mon Sep 17 00:00:00 2001 From: Ntalumeso Date: Sat, 17 Aug 2024 13:06:16 +0300 Subject: [PATCH 3/3] effectively fixed the bug in adding multipl columns --- instat/static/InstatObject/R/data_object_R6.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 64bf2546137..d27d47ca427 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,9 +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()) } - +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 + 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()) {