From 20709650c7dd35f56ba34e4ea4db5b99e2bfbcdd Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Wed, 19 Jan 2022 06:24:42 +0300 Subject: [PATCH 01/32] Reduced the size of the dialog, added other possibilities in the pull down and kept N/A as default in the pull down --- instat/dlgInsertColumn.Designer.vb | 8 ++++---- instat/dlgInsertColumn.vb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instat/dlgInsertColumn.Designer.vb b/instat/dlgInsertColumn.Designer.vb index 45699321f50..8a602fedad2 100644 --- a/instat/dlgInsertColumn.Designer.vb +++ b/instat/dlgInsertColumn.Designer.vb @@ -98,7 +98,7 @@ Partial Class dlgInsertColumn Me.grpInsert.Controls.Add(Me.ucrPnlInsertColumns) Me.grpInsert.Location = New System.Drawing.Point(235, 85) Me.grpInsert.Name = "grpInsert" - Me.grpInsert.Size = New System.Drawing.Size(286, 122) + Me.grpInsert.Size = New System.Drawing.Size(271, 122) Me.grpInsert.TabIndex = 6 Me.grpInsert.TabStop = False Me.grpInsert.Text = "Insert" @@ -172,9 +172,9 @@ Partial Class dlgInsertColumn 'ucrPnlInsertColumns ' Me.ucrPnlInsertColumns.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink - Me.ucrPnlInsertColumns.Location = New System.Drawing.Point(3, 17) + Me.ucrPnlInsertColumns.Location = New System.Drawing.Point(2, 17) Me.ucrPnlInsertColumns.Name = "ucrPnlInsertColumns" - Me.ucrPnlInsertColumns.Size = New System.Drawing.Size(277, 101) + Me.ucrPnlInsertColumns.Size = New System.Drawing.Size(265, 99) Me.ucrPnlInsertColumns.TabIndex = 5 ' 'grpOptions @@ -370,7 +370,7 @@ Partial Class dlgInsertColumn Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi Me.AutoSize = True - Me.ClientSize = New System.Drawing.Size(526, 369) + Me.ClientSize = New System.Drawing.Size(510, 369) Me.Controls.Add(Me.ucrInputDefaultValue) Me.Controls.Add(Me.lblInputColumnPrefix) Me.Controls.Add(Me.ucrInputPrefixForNewColumn) diff --git a/instat/dlgInsertColumn.vb b/instat/dlgInsertColumn.vb index 4f5cb77b400..5a7f07ad3c2 100644 --- a/instat/dlgInsertColumn.vb +++ b/instat/dlgInsertColumn.vb @@ -75,7 +75,7 @@ Public Class dlgInsertColumn ucrNudNumberOfColumns.SetMinMax(1, Integer.MaxValue) ucrInputDefaultValue.SetParameter(New RParameter("col_data", 5)) - ucrInputDefaultValue.SetItems({"NA", "NA_real_", " NA_integer_", " NA_complex_", "NA_character_"}) + ucrInputDefaultValue.SetItems({"NA", 0, "Kisumu", "New Zealand", True, False}) ucrInputDefaultValue.AddQuotesIfUnrecognised = False ucrInputDefaultValue.bAllowNonConditionValues = True From a4166b57f77870a137720c581512c0170d026f18 Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Wed, 19 Jan 2022 09:32:09 +0300 Subject: [PATCH 02/32] Changing the pull-down values to be read as strings --- instat/dlgInsertColumn.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgInsertColumn.vb b/instat/dlgInsertColumn.vb index 5a7f07ad3c2..1d2255c1b9f 100644 --- a/instat/dlgInsertColumn.vb +++ b/instat/dlgInsertColumn.vb @@ -76,7 +76,7 @@ Public Class dlgInsertColumn ucrInputDefaultValue.SetParameter(New RParameter("col_data", 5)) ucrInputDefaultValue.SetItems({"NA", 0, "Kisumu", "New Zealand", True, False}) - ucrInputDefaultValue.AddQuotesIfUnrecognised = False + ucrInputDefaultValue.AddQuotesIfUnrecognised = True ucrInputDefaultValue.bAllowNonConditionValues = True ucrPnlInsertColumns.SetParameter(New RParameter("before", 3)) From 804a6743b94055dc86ab094f889385681d72b68b Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Mon, 24 Jan 2022 12:14:36 +0300 Subject: [PATCH 03/32] Added values of the pull-down to dictionary --- instat/dlgInsertColumn.vb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/instat/dlgInsertColumn.vb b/instat/dlgInsertColumn.vb index 1d2255c1b9f..7d26f828eae 100644 --- a/instat/dlgInsertColumn.vb +++ b/instat/dlgInsertColumn.vb @@ -37,6 +37,8 @@ Public Class dlgInsertColumn Private Sub InitialiseDialog() Dim dctBeforeAfter As New Dictionary(Of String, String) + Dim dctDefaultValue As New Dictionary(Of String, String) + ucrBase.iHelpTopicID = 164 ucrSelectorInsertColumns.SetParameter(New RParameter("data_name", 0)) @@ -75,7 +77,13 @@ Public Class dlgInsertColumn ucrNudNumberOfColumns.SetMinMax(1, Integer.MaxValue) ucrInputDefaultValue.SetParameter(New RParameter("col_data", 5)) - ucrInputDefaultValue.SetItems({"NA", 0, "Kisumu", "New Zealand", True, False}) + dctDefaultValue.Add("NA", "NA") + dctDefaultValue.Add("0", "0") + dctDefaultValue.Add("Kisumu", Chr(34) & "Kisumu" & Chr(34)) + dctDefaultValue.Add("New Zealand", Chr(34) & "New Zealand" & Chr(34)) + dctDefaultValue.Add("True", Chr(34) & "True" & Chr(34)) + dctDefaultValue.Add("False", Chr(34) & "False" & Chr(34)) + ucrInputDefaultValue.SetItems(dctDefaultValue) ucrInputDefaultValue.AddQuotesIfUnrecognised = True ucrInputDefaultValue.bAllowNonConditionValues = True From fd2e8716fcce54a33352f89e2291004338b5bcb6 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Thu, 3 Feb 2022 10:52:40 +0300 Subject: [PATCH 04/32] Fixes the position error when user changes selected dataframe inf dialogs --- instat/ucrSave.vb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index 36016bc76a9..0635b6ab060 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -88,10 +88,6 @@ Public Class ucrSave ''' a named column (i.e. the R "col_name" parameter needs to be set). ''' Private bAssignToColumnWithoutNames As Boolean = False - ''' If true then set the R "before" parameter to true, else set it to false. - ''' Only used when this control is saving a column. - ''' - Private bInsertColumnBefore As Boolean = False ''' If true then a list of data frames is assigned (i.e. the R "data_names" ''' parameter needs to be set). ''' Only used when this control is saving a data frame. @@ -114,8 +110,14 @@ Public Class ucrSave ''' the column name. ''' Only used when this control is saving a column. Private ucrLinkedReceiver As ucrReceiver + ''' If true then set the R "before" parameter to true, else set it to false. + ''' Only used when this control is saving a column. + ''' + Private bInsertColumnBefore As Boolean = False Private strAdjacentColumn As String = "" - Private bKeepExistingPosition As Boolean = True 'todo. not used yet + 'todo. not used yet. + 'In future this could be used to determine whether to change the position of existing coulmns or not. + Private bKeepExistingPosition As Boolean = True Private bSetPositionParamsDirectly As String = True Private strReadNameFromParameterName As String = "" @@ -543,6 +545,11 @@ Public Class ucrSave ''' The ucr changed control. '''-------------------------------------------------------------------------------------------- Private Sub ucrInputControls_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputComboSave.ControlValueChanged, ucrInputTextSave.ControlValueChanged, ucrDataFrameSelector.ControlValueChanged + If ucrChangedControl Is ucrDataFrameSelector Then + 'when the dataframe is changed then reset position variables to correspond to 'end' + bInsertColumnBefore = False + strAdjacentColumn = "" + End If OnControlValueChanged() End Sub '''-------------------------------------------------------------------------------------------- From 3ce8c4fe5ba7b20d68171e65f7d396e735e3e063 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Thu, 3 Feb 2022 11:46:12 +0300 Subject: [PATCH 05/32] Amended the save control to retain defaults for all dialogs --- instat/ucrSave.vb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index 0635b6ab060..fbf19e338a5 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -549,6 +549,8 @@ Public Class ucrSave 'when the dataframe is changed then reset position variables to correspond to 'end' bInsertColumnBefore = False strAdjacentColumn = "" + 'reset the super selected option, because the control has reset the position variables + sdgSaveColumnPosition.bUserSelected = False End If OnControlValueChanged() End Sub From 2c10602df1491c87148bd0999503222ff9e2aa1d Mon Sep 17 00:00:00 2001 From: patowhiz Date: Thu, 3 Feb 2022 12:48:59 +0300 Subject: [PATCH 06/32] Fixed the duplicate paths bug in recent files --- instat/clsRecentFiles.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instat/clsRecentFiles.vb b/instat/clsRecentFiles.vb index 636cddef78f..f61e8c16dcb 100644 --- a/instat/clsRecentFiles.vb +++ b/instat/clsRecentFiles.vb @@ -64,7 +64,7 @@ Public Class clsRecentFiles 'read file contents Dim arrStrPaths() As String = File.ReadAllLines(strRecentFilesPath) For Each strPath As String In arrStrPaths - If Not String.IsNullOrEmpty(strPath) Then + If Not String.IsNullOrEmpty(strPath) AndAlso Not lstRecentOpenedFiles.Contains(strPath.Replace("\", "/")) Then lstRecentOpenedFiles.Add(strPath.Replace("\", "/")) End If Next @@ -106,10 +106,10 @@ Public Class clsRecentFiles ''' ''' file path to add to menu items Public Sub addToMenu(strFilePath As String) + strFilePath = strFilePath.Replace("\", "/") 'remove file if it exists(helps with making sure displayed file names are rearranged) lstRecentOpenedFiles.Remove(strFilePath) 'add to recent opened files list.. - strFilePath = strFilePath.Replace("\", "/") lstRecentOpenedFiles.Add(strFilePath) 'make sure there are only ever 30 items... 'todo. add this to the general options on the number of recently files to show From 6687843e17ef53c8992eb80bea8ce34eede3012b Mon Sep 17 00:00:00 2001 From: patowhiz Date: Thu, 3 Feb 2022 13:00:04 +0300 Subject: [PATCH 07/32] Update instat/ucrSave.vb --- instat/ucrSave.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index fbf19e338a5..966fce306b7 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -549,7 +549,8 @@ Public Class ucrSave 'when the dataframe is changed then reset position variables to correspond to 'end' bInsertColumnBefore = False strAdjacentColumn = "" - 'reset the super selected option, because the control has reset the position variables + 'reset the user selected option, because the control has reset the position variables + sdgSaveColumnPosition.bUserSelected = False End If OnControlValueChanged() From 5759b6bf88d3b4305122feb192c689c75da8797e Mon Sep 17 00:00:00 2001 From: patowhiz Date: Thu, 3 Feb 2022 13:01:28 +0300 Subject: [PATCH 08/32] removed blank line --- instat/ucrSave.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index 966fce306b7..5ac697210f8 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -550,7 +550,6 @@ Public Class ucrSave bInsertColumnBefore = False strAdjacentColumn = "" 'reset the user selected option, because the control has reset the position variables - sdgSaveColumnPosition.bUserSelected = False End If OnControlValueChanged() From d18c8ad724073a4dcf3ca2bb72a4bb6d5405632d Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 4 Feb 2022 09:53:21 +0300 Subject: [PATCH 09/32] Apply As Selected Columns --- instat/dlgSelect.Designer.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgSelect.Designer.vb b/instat/dlgSelect.Designer.vb index 993bd6e3f26..b3cf0367122 100644 --- a/instat/dlgSelect.Designer.vb +++ b/instat/dlgSelect.Designer.vb @@ -85,7 +85,7 @@ Partial Class dlgSelect Me.rdoApplyAsSelect.Size = New System.Drawing.Size(154, 17) Me.rdoApplyAsSelect.TabIndex = 0 Me.rdoApplyAsSelect.TabStop = True - Me.rdoApplyAsSelect.Text = "Selector Only" + Me.rdoApplyAsSelect.Text = "Apply As Selected Columns" Me.rdoApplyAsSelect.UseVisualStyleBackColor = True ' 'ucrPnlApplyOptions From 4b67161cb64f2c29737e8c526e909ed683bbf1e9 Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 4 Feb 2022 10:06:58 +0300 Subject: [PATCH 10/32] removed include hidden columns parameter and added use_column_selection --- instat/Model/DataFrame/clsDataFramePage.vb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/instat/Model/DataFrame/clsDataFramePage.vb b/instat/Model/DataFrame/clsDataFramePage.vb index 1bd9470f609..a56a593dc9a 100644 --- a/instat/Model/DataFrame/clsDataFramePage.vb +++ b/instat/Model/DataFrame/clsDataFramePage.vb @@ -191,19 +191,19 @@ Public Class clsDataFramePage End Function Private Function GetDataFrameFromRCommand() As DataFrame - Dim clsRFunction As New RFunction + Dim clsGetDataFrameRFunction As New RFunction Dim expTemp As SymbolicExpression _hasChanged = True - clsRFunction.SetRCommand(_clsRLink.strInstatDataObject & "$get_data_frame") - clsRFunction.AddParameter("convert_to_character", "TRUE") - clsRFunction.AddParameter("include_hidden_columns", "FALSE") - clsRFunction.AddParameter("use_current_filter", "TRUE") - clsRFunction.AddParameter("max_cols", iColumnIncrements) - clsRFunction.AddParameter("max_rows", intRowIncrements) - clsRFunction.AddParameter("start_row", _iRowStart) - clsRFunction.AddParameter("start_col", _iColumnStart) - clsRFunction.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34)) - expTemp = _clsRLink.RunInternalScriptGetValue(clsRFunction.ToScript(), bSilent:=True) + clsGetDataFrameRFunction.SetRCommand(_clsRLink.strInstatDataObject & "$get_data_frame") + clsGetDataFrameRFunction.AddParameter("convert_to_character", "TRUE") + clsGetDataFrameRFunction.AddParameter("use_current_filter", "TRUE") + clsGetDataFrameRFunction.AddParameter("use_column_selection", "TRUE") + clsGetDataFrameRFunction.AddParameter("max_cols", iColumnIncrements) + clsGetDataFrameRFunction.AddParameter("max_rows", intRowIncrements) + clsGetDataFrameRFunction.AddParameter("start_row", _iRowStart) + clsGetDataFrameRFunction.AddParameter("start_col", _iColumnStart) + clsGetDataFrameRFunction.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34)) + expTemp = _clsRLink.RunInternalScriptGetValue(clsGetDataFrameRFunction.ToScript(), bSilent:=True) If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then Return expTemp.AsDataFrame Else From 4969b1c6a4ba1259093116bcb6607a5ad4f904df Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 4 Feb 2022 10:09:36 +0300 Subject: [PATCH 11/32] Added an option in "get_data_frame" method to extract selected columns when a column selection is applied --- instat/static/InstatObject/R/data_object_R6.R | 19 ++++++++++++++++++- .../static/InstatObject/R/instat_object_R6.R | 8 ++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 5b78af702d8..ed54b1b6d74 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -278,7 +278,7 @@ DataSheet$set("public", "set_metadata_changed", function(new_val) { } ) -DataSheet$set("public", "get_data_frame", function(convert_to_character = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, filter_name = "", stack_data = FALSE, remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...) { +DataSheet$set("public", "get_data_frame", function(convert_to_character = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, use_column_selection = TRUE, filter_name = "", stack_data = FALSE, remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...) { if(!stack_data) { if(!include_hidden_columns && self$is_variables_metadata(is_hidden_label)) { hidden <- self$get_variables_metadata(property = is_hidden_label) @@ -302,6 +302,21 @@ DataSheet$set("public", "get_data_frame", function(convert_to_character = FALSE, out <- out[self$get_filter_as_logical(filter_name = filter_name), ] } } + #TODO: consider removing include_hidden_columns argument from this function + if(use_column_selection && self$column_selection_applied()) { + old_metadata <- attributes(private$data) + selected_columns <- self$get_column_names() + out <- out[ ,selected_columns, drop = FALSE] + for(name in names(old_metadata)) { + if(!name %in% c("names", "class", "row.names")) { + attr(out, name) <- old_metadata[[name]] + } + } + all_columns <- self$get_column_names(use_current_column_selection = FALSE) + hidden_cols <- all_columns[!(all_columns %in% selected_columns)] + self$append_to_variables_metadata(hidden_cols, is_hidden_label, TRUE) + private$.variables_metadata_changed <- TRUE + } if(!is.data.frame(out)) { out <- data.frame(out) if(length(nam) == length(out)) names(out) <- nam @@ -1944,6 +1959,8 @@ DataSheet$set("public", "column_selection_applied", function() { DataSheet$set("public", "remove_current_column_selection", function() { self$set_current_column_selection(".everything") + self$append_to_variables_metadata(self$get_column_names(), is_hidden_label, FALSE) + private$.variables_metadata_changed <- TRUE } ) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 9a0c56c4ac2..a80f6ffbc5b 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -328,22 +328,22 @@ DataBook$set("public", "get_data_objects", function(data_name, as_list = FALSE, } ) -DataBook$set("public", "get_data_frame", function(data_name, convert_to_character = FALSE, stack_data = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, filter_name = "", remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...) { +DataBook$set("public", "get_data_frame", function(data_name, convert_to_character = FALSE, stack_data = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, use_column_selection = TRUE, filter_name = "", remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...) { if(!stack_data) { if(missing(data_name)) data_name <- self$get_data_names() if(length(data_name) > 1) { retlist <- list() for (curr_name in data_name) { - retlist[[curr_name]] = self$get_data_objects(curr_name)$get_data_frame(convert_to_character = convert_to_character, include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, filter_name = filter_name, remove_attr = remove_attr, retain_attr = retain_attr, max_cols = max_cols, max_rows = max_rows, drop_unused_filter_levels = drop_unused_filter_levels, start_row = start_row, start_col = start_col) + retlist[[curr_name]] = self$get_data_objects(curr_name)$get_data_frame(convert_to_character = convert_to_character, include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, use_column_selection = use_column_selection, filter_name = filter_name, remove_attr = remove_attr, retain_attr = retain_attr, max_cols = max_cols, max_rows = max_rows, drop_unused_filter_levels = drop_unused_filter_levels, start_row = start_row, start_col = start_col) } return(retlist) } - else return(self$get_data_objects(data_name)$get_data_frame(convert_to_character = convert_to_character, include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, filter_name = filter_name, remove_attr = remove_attr, retain_attr = retain_attr, max_cols = max_cols, max_rows = max_rows, drop_unused_filter_levels = drop_unused_filter_levels, start_row = start_row, start_col = start_col)) + else return(self$get_data_objects(data_name)$get_data_frame(convert_to_character = convert_to_character, include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, use_column_selection = use_column_selection, filter_name = filter_name, remove_attr = remove_attr, retain_attr = retain_attr, max_cols = max_cols, max_rows = max_rows, drop_unused_filter_levels = drop_unused_filter_levels, start_row = start_row, start_col = start_col)) } else { if(missing(data_name)) stop("data to be stacked is missing") if(!data_name %in% names(private$.data_sheets)) stop(paste(data_name, "not found.")) - return(self$get_data_objects(data_name)$get_data_frame(include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, filter_name = filter_name, stack_data = TRUE, ...)) + return(self$get_data_objects(data_name)$get_data_frame(include_hidden_columns = include_hidden_columns, use_current_filter = use_current_filter, use_column_selection = use_column_selection, filter_name = filter_name, stack_data = TRUE, ...)) } } ) From 822a6c7854f427df702f310699253a9a9ec91ad8 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Fri, 4 Feb 2022 11:31:27 +0300 Subject: [PATCH 12/32] fixed the numeric and factor options miz up in duplicates column --- instat/dlgDuplicateColumns.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instat/dlgDuplicateColumns.vb b/instat/dlgDuplicateColumns.vb index 3c62bc63a56..6b887be603d 100644 --- a/instat/dlgDuplicateColumns.vb +++ b/instat/dlgDuplicateColumns.vb @@ -84,8 +84,8 @@ Public Class dlgDuplicateColumns ucrPnlConvertTo.AddRadioButton(rdoConvertToCharacter, Chr(34) & "character" & Chr(34)) ucrPnlConvertTo.AddRadioButton(rdoConvertToInteger, Chr(34) & "integer" & Chr(34)) ucrPnlConvertTo.AddRadioButton(rdoConvertToLogical, Chr(34) & "logical" & Chr(34)) - ucrPnlConvertTo.AddToLinkedControls(ucrChkConvertSpecifyDecimalsToDisplay, {rdoConvertToFactor, rdoConvertToOrderedFactor}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrPnlConvertTo.AddToLinkedControls(ucrPnlConvertFactorToNumericOptions, {rdoConvertToNumeric}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:=rdoConvertDefault) + ucrPnlConvertTo.AddToLinkedControls(ucrPnlConvertFactorToNumericOptions, {rdoConvertToFactor, rdoConvertToOrderedFactor}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlConvertTo.AddToLinkedControls(ucrChkConvertSpecifyDecimalsToDisplay, {rdoConvertToNumeric}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True) ucrPnlConvertFactorToNumericOptions.SetParameter(New RParameter("factor_values", 3)) ucrPnlConvertFactorToNumericOptions.AddRadioButton(rdoConvertDefault, "NULL") From 32bcbe2f4da2a3212177b86c3fd5a7d0a25c9da4 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Fri, 4 Feb 2022 16:46:31 +0300 Subject: [PATCH 13/32] Update instat/ucrSave.vb Co-authored-by: Shadrack Kibet --- instat/ucrSave.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index 5ac697210f8..93e146a489d 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -116,7 +116,8 @@ Public Class ucrSave Private bInsertColumnBefore As Boolean = False Private strAdjacentColumn As String = "" 'todo. not used yet. - 'In future this could be used to determine whether to change the position of existing coulmns or not. + 'In future, this could be used to determine whether to change the position of the existing column or not. + Private bKeepExistingPosition As Boolean = True Private bSetPositionParamsDirectly As String = True Private strReadNameFromParameterName As String = "" From 94005c912bcc658fe3c818e462eb80cdaadd0696 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Fri, 4 Feb 2022 16:47:02 +0300 Subject: [PATCH 14/32] Update instat/ucrSave.vb Co-authored-by: Shadrack Kibet --- instat/ucrSave.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/ucrSave.vb b/instat/ucrSave.vb index 93e146a489d..bf4a8b20c77 100644 --- a/instat/ucrSave.vb +++ b/instat/ucrSave.vb @@ -110,7 +110,8 @@ Public Class ucrSave ''' the column name. ''' Only used when this control is saving a column. Private ucrLinkedReceiver As ucrReceiver - ''' If true then set the R "before" parameter to true, else set it to false. + ''' If true then set the R "before" parameter to TRUE, else set it to FALSE. + ''' Only used when this control is saving a column. ''' Private bInsertColumnBefore As Boolean = False From 91ce7654a6ba168af34587d08978535c7f5aeada Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 28 Jan 2022 12:53:55 +0300 Subject: [PATCH 15/32] trial --- instat/static/InstatObject/R/data_object_R6.R | 9 +++++++++ instat/static/InstatObject/R/instat_object_R6.R | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 5b78af702d8..cce4b8b6411 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -4231,3 +4231,12 @@ DataSheet$set("public", "add_flag_fields", function(col_names) { self$add_columns_to_data(col_data = col_data, col_name = paste0(i, "_fl")) } }) + +DataSheet$set("Public", "replace_values_with_NA", function(row_index, column_index) { + curr_data <- self$get_data_frame(use_current_filter = FALSE) + if(!all(row_index %in% seq_along(nrow(curr_data)))) stop("All row indexes must be within the dataframe") + if(!all(collumn_index %in% seq_along(ncol(curr_data)))) stop("All column indexes must be within the dataframe") + curr_data[row_index, column_index] <- NA + self$set_data(curr_data) +} +) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 9a0c56c4ac2..8f7dec05b63 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -2714,3 +2714,7 @@ DataBook$set("public", "add_flag_fields", function(data_name, col_names, key_col self$get_data_objects(data_name)$add_flag_fields(col_names = col_names) } ) + +DataBook$set("public", "replace_values_with_NA", function(data_name, row_index, column_index) { + self$get_data_objects(data_name)$replace_values_with_NA(row_index = row_index, column_index = column_index) +}) From bf01587a9a78ebe63f575e45e918be91fb2d3f9a Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 28 Jan 2022 13:32:35 +0300 Subject: [PATCH 16/32] added a function for replacing cell values with NA --- instat/static/InstatObject/R/data_object_R6.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index cce4b8b6411..3b6c96d23c5 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -4232,10 +4232,10 @@ DataSheet$set("public", "add_flag_fields", function(col_names) { } }) -DataSheet$set("Public", "replace_values_with_NA", function(row_index, column_index) { +DataSheet$set("public", "replace_values_with_NA", function(row_index, column_index) { curr_data <- self$get_data_frame(use_current_filter = FALSE) - if(!all(row_index %in% seq_along(nrow(curr_data)))) stop("All row indexes must be within the dataframe") - if(!all(collumn_index %in% seq_along(ncol(curr_data)))) stop("All column indexes must be within the dataframe") + if(!all(row_index %in% seq_len(nrow(curr_data)))) stop("All row indexes must be within the dataframe") + if(!all(column_index %in% seq_len(ncol(curr_data)))) stop("All column indexes must be within the dataframe") curr_data[row_index, column_index] <- NA self$set_data(curr_data) } From 22564c8f9d3cada93875f5cb66bdeb3db902a093 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom Date: Fri, 28 Jan 2022 11:23:16 -0800 Subject: [PATCH 17/32] Partially_Fixes_issues_#7149 implementing a delete option on the cells of reogrid --- .../RCommand/clsPrepareFunctionsForGrids.vb | 30 ++++++++----------- instat/ucrDataView.Designer.vb | 12 ++++++-- instat/ucrDataView.vb | 15 +++++++++- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb index 87546528b9c..d3fecd42418 100644 --- a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb +++ b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb @@ -293,24 +293,19 @@ Public Class clsPrepareFunctionsForGrids ''' ''' Replace value in given cell ''' - ''' - ''' - ''' - ''' - Public Sub ReplaceValueInData(strNewValue As String, strColumnName As String, strRowText As String, bWithQuotes As Boolean) - Dim clsReplaceValue As New RFunction + ''' + ''' + + Public Sub DeleteCells(lstColumnNames As List(Of String), lstRowNames As List(Of String)) + Dim clsDeleteCells As New RFunction 'trim white space from ends of value - strNewValue = strNewValue.Trim() - clsReplaceValue.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$replace_value_in_data") - clsReplaceValue.AddParameter("data_name", Chr(34) & _strDataFrame & Chr(34)) - clsReplaceValue.AddParameter("col_name", Chr(34) & strColumnName & Chr(34)) - clsReplaceValue.AddParameter("rows", Chr(34) & strRowText & Chr(34)) - If bWithQuotes Then - clsReplaceValue.AddParameter("new_value", Chr(34) & strNewValue & Chr(34)) - Else - clsReplaceValue.AddParameter("new_value", strNewValue) - End If - _RLink.RunScript(clsReplaceValue.ToScript(), strComment:="Replace Value In Data") + clsDeleteCells.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$replace_values_with_NA") + clsDeleteCells.SetRCommand(_RLink.strInstatDataObject & "$replace_values_with_NA") + clsDeleteCells.AddParameter("data_name", Chr(34) & _strDataFrame & Chr(34)) + clsDeleteCells.AddParameter("col_name", _RLink.GetListAsRString(lstColumnNames)) + clsDeleteCells.AddParameter("rows", _RLink.GetListAsRString(lstRowNames)) + + _RLink.RunScript(clsDeleteCells.ToScript(), strComment:="Right click menu: Replace Value In Data") End Sub ''' ''' Get the column type for a given column @@ -320,6 +315,5 @@ Public Class clsPrepareFunctionsForGrids Public Function GetColumnType(strColumnName As String) As String Return _RLink.GetColumnType(_strDataFrame, strColumnName) End Function - End Class diff --git a/instat/ucrDataView.Designer.vb b/instat/ucrDataView.Designer.vb index 5f8e794edff..f90018650fe 100644 --- a/instat/ucrDataView.Designer.vb +++ b/instat/ucrDataView.Designer.vb @@ -131,6 +131,7 @@ Partial Class ucrDataView Me.lblRowNext = New System.Windows.Forms.Label() Me.lblColLast = New System.Windows.Forms.Label() Me.lblRowBack = New System.Windows.Forms.Label() + Me.mnuDeleteCell = New System.Windows.Forms.ToolStripMenuItem() Me.ucrReoGrid = New instat.ucrDataViewReoGrid() Me.ucrLinuxGrid = New instat.ucrDataViewLinuxGrid() Me.columnContextMenuStrip.SuspendLayout() @@ -284,9 +285,9 @@ Partial Class ucrDataView 'cellContextMenuStrip ' Me.cellContextMenuStrip.ImageScalingSize = New System.Drawing.Size(20, 20) - Me.cellContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripSeparator3, Me.mnuRenameColumn, Me.mnuDuplColumn, Me.mnuReorderColumn, Me.mnuCellPasteRange, Me.ToolStripSeparator5, Me.mnuConvertToFact, Me.mnuConvertToOrderedFactor, Me.mnuConvertToCharacter, Me.mnuConvertToLogic, Me.mnuConvertToNumeric, Me.ToolStripSeparator6, Me.mnuLabelsLevel, Me.ToolStripSeparator7, Me.mnuSorts, Me.mnuComment, Me.mnuFilters, Me.mnuCellContextColumnSelection, Me.mnuCellContextRemoveCurrentColumnSelection, Me.mnuRemoveCurrentFilters}) + Me.cellContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripSeparator3, Me.mnuRenameColumn, Me.mnuDuplColumn, Me.mnuReorderColumn, Me.mnuDeleteCell, Me.mnuCellPasteRange, Me.ToolStripSeparator5, Me.mnuConvertToFact, Me.mnuConvertToOrderedFactor, Me.mnuConvertToCharacter, Me.mnuConvertToLogic, Me.mnuConvertToNumeric, Me.ToolStripSeparator6, Me.mnuLabelsLevel, Me.ToolStripSeparator7, Me.mnuSorts, Me.mnuComment, Me.mnuFilters, Me.mnuCellContextColumnSelection, Me.mnuCellContextRemoveCurrentColumnSelection, Me.mnuRemoveCurrentFilters}) Me.cellContextMenuStrip.Name = "cellContextMenuStrip" - Me.cellContextMenuStrip.Size = New System.Drawing.Size(215, 380) + Me.cellContextMenuStrip.Size = New System.Drawing.Size(215, 402) ' 'ToolStripSeparator3 ' @@ -893,6 +894,12 @@ Partial Class ucrDataView Me.lblRowBack.Text = "<" Me.lblRowBack.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' + 'mnuDeleteCell + ' + Me.mnuDeleteCell.Name = "mnuDeleteCell" + Me.mnuDeleteCell.Size = New System.Drawing.Size(214, 22) + Me.mnuDeleteCell.Text = "Delete Cell(s)" + ' 'ucrReoGrid ' Me.ucrReoGrid.Dock = System.Windows.Forms.DockStyle.Fill @@ -1032,4 +1039,5 @@ Partial Class ucrDataView Friend WithEvents mnuCellContextRemoveCurrentColumnSelection As ToolStripMenuItem Friend WithEvents mnuRowContextColumnSelection As ToolStripMenuItem Friend WithEvents mnuRowContextRemoveCurrentColumnSelection As ToolStripMenuItem + Friend WithEvents mnuDeleteCell As ToolStripMenuItem End Class diff --git a/instat/ucrDataView.vb b/instat/ucrDataView.vb index 24825936138..6b93635d2e1 100644 --- a/instat/ucrDataView.vb +++ b/instat/ucrDataView.vb @@ -333,7 +333,7 @@ Public Class ucrDataView End Select End If StartWait() - GetCurrentDataFrameFocus().clsPrepareFunctions.ReplaceValueInData(strNewValue, strColumnName, strRowText, bWithQuotes) + GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) EndWait() End Sub @@ -838,4 +838,17 @@ Public Class ucrDataView Private Sub ucrDataView_Resize(sender As Object, e As EventArgs) Handles TblPanPageDisplay.Resize ResizeLabels() End Sub + + Private Sub mnuDeleteCell_Click(sender As Object, e As EventArgs) Handles mnuDeleteCell.Click + If GetSelectedColumns.Count = GetCurrentDataFrameFocus()?.iTotalColumnCount Then + MsgBox("Cannot delete all visible cells." & Environment.NewLine & "Use Prepare > Data Object > Delete Data Frame if you wish to delete the data.", MsgBoxStyle.Information, "Cannot Delete All Columns") + Else + Dim deleteCell = MsgBox("Are you sure you want to delete these cell(s)?" & Environment.NewLine & "This action cannot be undone.", MessageBoxButtons.YesNo, "Delete Cells") + If deleteCell = DialogResult.Yes Then + StartWait() + GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) + EndWait() + End If + End If + End Sub End Class \ No newline at end of file From b9eee18e01e6712d0ea74f6986bc59e884124b53 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom Date: Mon, 31 Jan 2022 06:07:35 -0800 Subject: [PATCH 18/32] Partially fixes delete implementation --- instat/Interface/IDataViewGrid.vb | 2 ++ .../Model/RCommand/clsPrepareFunctionsForGrids.vb | 11 +++++------ .../DataGrid/Linux/ucrDataViewLinuxGrid.vb | 8 ++++++++ .../DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 7 +++++++ instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb | 8 ++++---- instat/ucrDataView.vb | 13 +++++++++---- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/instat/Interface/IDataViewGrid.vb b/instat/Interface/IDataViewGrid.vb index 29bc0f8c89a..fa0a5071e1b 100644 --- a/instat/Interface/IDataViewGrid.vb +++ b/instat/Interface/IDataViewGrid.vb @@ -19,6 +19,8 @@ Public Interface IDataViewGrid Event CellDataChanged() + Event DeleteValuesToDataframe() + Event PasteValuesToDataframe() Event ReplaceValueInData(strNewValue As String, strColumnName As String, strRowText As String) diff --git a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb index d3fecd42418..3d6e89468ca 100644 --- a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb +++ b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb @@ -293,17 +293,16 @@ Public Class clsPrepareFunctionsForGrids ''' ''' Replace value in given cell ''' - ''' - ''' + ''' + ''' - Public Sub DeleteCells(lstColumnNames As List(Of String), lstRowNames As List(Of String)) + Public Sub DeleteCells(lstRowIndexes As List(Of String), lstColumnIndexes As List(Of String)) Dim clsDeleteCells As New RFunction 'trim white space from ends of value clsDeleteCells.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$replace_values_with_NA") - clsDeleteCells.SetRCommand(_RLink.strInstatDataObject & "$replace_values_with_NA") clsDeleteCells.AddParameter("data_name", Chr(34) & _strDataFrame & Chr(34)) - clsDeleteCells.AddParameter("col_name", _RLink.GetListAsRString(lstColumnNames)) - clsDeleteCells.AddParameter("rows", _RLink.GetListAsRString(lstRowNames)) + clsDeleteCells.AddParameter("row_index", _RLink.GetListAsRString(lstRowIndexes)) + clsDeleteCells.AddParameter("column_index", _RLink.GetListAsRString(lstColumnIndexes)) _RLink.RunScript(clsDeleteCells.ToScript(), strComment:="Right click menu: Replace Value In Data") End Sub diff --git a/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb b/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb index 9d6de5928cc..9ed0593c390 100644 --- a/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb +++ b/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb @@ -29,6 +29,8 @@ Public Class ucrDataViewLinuxGrid Public Event WorksheetChanged() Implements IDataViewGrid.WorksheetChanged + Public Event DeleteValueToDataframe() Implements IDataViewGrid.DeleteValuesToDataframe + Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns @@ -106,6 +108,12 @@ Public Class ucrDataViewLinuxGrid RaiseEvent CellDataChanged() End Sub + Private Sub DataGridView_BeforeCellKeyDown(sender As Object, e As KeyEventArgs) + If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then + RaiseEvent DeleteValueToDataframe() + End If + End Sub + Private Sub DataGridView_KeyDown(sender As Object, e As KeyEventArgs) Dim ctrlV As Boolean = e.Modifiers = Keys.Control And e.KeyCode = Keys.V Dim shiftIns As Boolean = e.Modifiers = Keys.Shift And e.KeyCode = Keys.Insert diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index 98e64373c90..796177d7f24 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -28,6 +28,8 @@ Public Class ucrDataViewReoGrid Public Event WorksheetChanged() Implements IDataViewGrid.WorksheetChanged + Public Event DeleteValueToDataframe() Implements IDataViewGrid.DeleteValuesToDataframe + Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns Dim workSheetColumnHeader As ColumnHeader @@ -132,6 +134,11 @@ Public Class ucrDataViewReoGrid e.EndReason = unvell.ReoGrid.EndEditReason.Cancel End Sub + Private Sub Worksheet_BeforeCellKeyDown(sender As Object, e As BeforeCellKeyDownEventArgs) + If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then + RaiseEvent DeleteValueToDataframe() + End If + End Sub Private Sub Worksheet_BeforePaste(sender As Object, e As BeforeRangeOperationEventArgs) e.IsCancelled = True 'prevents pasted data from being added directly into the data view diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb index 6ae084453f3..b235a6c23ee 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb @@ -150,10 +150,10 @@ Public MustInherit Class ucrReoGrid Protected MustOverride Sub AttachEventsToWorksheet(Worksheet As Worksheet) Protected Sub Worksheet_BeforeCellKeyDown(sender As Object, e As BeforeCellKeyDownEventArgs) - If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then - MsgBox("Deleting cells is currently disabled. This feature will be included in future versions." & Environment.NewLine & "To remove a cell's value, replace the value with NA.", MsgBoxStyle.Information, "Cannot delete cells.") - e.IsCancelled = True - End If + 'If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then + ' MsgBox("This will replace the selected cells with missing values (NA)." & Environment.NewLine & "Continue?", MsgBoxStyle.Question, "Replace values with NA") + ' e.IsCancelled = True + 'End If End Sub Protected Sub Worksheet_BeforeCut(sender As Object, e As BeforeRangeOperationEventArgs) diff --git a/instat/ucrDataView.vb b/instat/ucrDataView.vb index 6b93635d2e1..13165d8c0e7 100644 --- a/instat/ucrDataView.vb +++ b/instat/ucrDataView.vb @@ -90,6 +90,7 @@ Public Class ucrDataView AddHandler _grid.ReplaceValueInData, AddressOf ReplaceValueInData AddHandler _grid.PasteValuesToDataframe, AddressOf PasteValuesToDataFrame AddHandler _grid.CellDataChanged, AddressOf CellDataChanged + AddHandler _grid.DeleteValuesToDataframe, AddressOf DeleteCell_Click End Sub Private Sub RefreshWorksheet(fillWorkSheet As clsWorksheetAdapter, dataFrame As clsDataFrame) @@ -833,22 +834,26 @@ Public Class ucrDataView StartWait() GetCurrentDataFrameFocus().clsPrepareFunctions.RemoveCurrentColumnSelection() EndWait() - End Sub - + End Sub + Private Sub ucrDataView_Resize(sender As Object, e As EventArgs) Handles TblPanPageDisplay.Resize ResizeLabels() End Sub - Private Sub mnuDeleteCell_Click(sender As Object, e As EventArgs) Handles mnuDeleteCell.Click + Private Sub DeleteCell_Click() If GetSelectedColumns.Count = GetCurrentDataFrameFocus()?.iTotalColumnCount Then MsgBox("Cannot delete all visible cells." & Environment.NewLine & "Use Prepare > Data Object > Delete Data Frame if you wish to delete the data.", MsgBoxStyle.Information, "Cannot Delete All Columns") Else Dim deleteCell = MsgBox("Are you sure you want to delete these cell(s)?" & Environment.NewLine & "This action cannot be undone.", MessageBoxButtons.YesNo, "Delete Cells") If deleteCell = DialogResult.Yes Then StartWait() - GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) + GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumns()) EndWait() End If End If End Sub + + Private Sub mnuDeleteCell_Click(sender As Object, e As EventArgs) Handles mnuDeleteCell.Click + DeleteCell_Click() + End Sub End Class \ No newline at end of file From 761c5befa8e7643bb97b72ab2c50ee49907d0f8d Mon Sep 17 00:00:00 2001 From: Derrick Agorhom Date: Mon, 31 Jan 2022 10:17:28 -0800 Subject: [PATCH 19/32] Fixes error in line 850 of the ucrDataView --- instat/ucrDataView.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/ucrDataView.vb b/instat/ucrDataView.vb index 13165d8c0e7..91f7a386f5b 100644 --- a/instat/ucrDataView.vb +++ b/instat/ucrDataView.vb @@ -847,7 +847,7 @@ Public Class ucrDataView Dim deleteCell = MsgBox("Are you sure you want to delete these cell(s)?" & Environment.NewLine & "This action cannot be undone.", MessageBoxButtons.YesNo, "Delete Cells") If deleteCell = DialogResult.Yes Then StartWait() - GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumns()) + GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) EndWait() End If End If From a9f539780b8bb120dbc5d99daaafaa2398642ef2 Mon Sep 17 00:00:00 2001 From: N-thony Date: Mon, 31 Jan 2022 21:11:40 +0200 Subject: [PATCH 20/32] Revert "Testing pr" --- instat/Interface/IDataViewGrid.vb | 2 -- .../RCommand/clsPrepareFunctionsForGrids.vb | 29 ++++++++++++------- .../DataGrid/Linux/ucrDataViewLinuxGrid.vb | 8 ----- .../DataGrid/ReoGrid/ucrDataViewReoGrid.vb | 7 ----- .../DataGrid/ReoGrid/ucrReoGrid.vb | 8 ++--- instat/static/InstatObject/R/data_object_R6.R | 9 ------ .../static/InstatObject/R/instat_object_R6.R | 4 --- instat/ucrDataView.Designer.vb | 12 ++------ instat/ucrDataView.vb | 24 ++------------- 9 files changed, 27 insertions(+), 76 deletions(-) diff --git a/instat/Interface/IDataViewGrid.vb b/instat/Interface/IDataViewGrid.vb index fa0a5071e1b..29bc0f8c89a 100644 --- a/instat/Interface/IDataViewGrid.vb +++ b/instat/Interface/IDataViewGrid.vb @@ -19,8 +19,6 @@ Public Interface IDataViewGrid Event CellDataChanged() - Event DeleteValuesToDataframe() - Event PasteValuesToDataframe() Event ReplaceValueInData(strNewValue As String, strColumnName As String, strRowText As String) diff --git a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb index 3d6e89468ca..87546528b9c 100644 --- a/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb +++ b/instat/Model/RCommand/clsPrepareFunctionsForGrids.vb @@ -293,18 +293,24 @@ Public Class clsPrepareFunctionsForGrids ''' ''' Replace value in given cell ''' - ''' - ''' - - Public Sub DeleteCells(lstRowIndexes As List(Of String), lstColumnIndexes As List(Of String)) - Dim clsDeleteCells As New RFunction + ''' + ''' + ''' + ''' + Public Sub ReplaceValueInData(strNewValue As String, strColumnName As String, strRowText As String, bWithQuotes As Boolean) + Dim clsReplaceValue As New RFunction 'trim white space from ends of value - clsDeleteCells.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$replace_values_with_NA") - clsDeleteCells.AddParameter("data_name", Chr(34) & _strDataFrame & Chr(34)) - clsDeleteCells.AddParameter("row_index", _RLink.GetListAsRString(lstRowIndexes)) - clsDeleteCells.AddParameter("column_index", _RLink.GetListAsRString(lstColumnIndexes)) - - _RLink.RunScript(clsDeleteCells.ToScript(), strComment:="Right click menu: Replace Value In Data") + strNewValue = strNewValue.Trim() + clsReplaceValue.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$replace_value_in_data") + clsReplaceValue.AddParameter("data_name", Chr(34) & _strDataFrame & Chr(34)) + clsReplaceValue.AddParameter("col_name", Chr(34) & strColumnName & Chr(34)) + clsReplaceValue.AddParameter("rows", Chr(34) & strRowText & Chr(34)) + If bWithQuotes Then + clsReplaceValue.AddParameter("new_value", Chr(34) & strNewValue & Chr(34)) + Else + clsReplaceValue.AddParameter("new_value", strNewValue) + End If + _RLink.RunScript(clsReplaceValue.ToScript(), strComment:="Replace Value In Data") End Sub ''' ''' Get the column type for a given column @@ -314,5 +320,6 @@ Public Class clsPrepareFunctionsForGrids Public Function GetColumnType(strColumnName As String) As String Return _RLink.GetColumnType(_strDataFrame, strColumnName) End Function + End Class diff --git a/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb b/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb index 9ed0593c390..9d6de5928cc 100644 --- a/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb +++ b/instat/UserControls/DataGrid/Linux/ucrDataViewLinuxGrid.vb @@ -29,8 +29,6 @@ Public Class ucrDataViewLinuxGrid Public Event WorksheetChanged() Implements IDataViewGrid.WorksheetChanged - Public Event DeleteValueToDataframe() Implements IDataViewGrid.DeleteValuesToDataframe - Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns @@ -108,12 +106,6 @@ Public Class ucrDataViewLinuxGrid RaiseEvent CellDataChanged() End Sub - Private Sub DataGridView_BeforeCellKeyDown(sender As Object, e As KeyEventArgs) - If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then - RaiseEvent DeleteValueToDataframe() - End If - End Sub - Private Sub DataGridView_KeyDown(sender As Object, e As KeyEventArgs) Dim ctrlV As Boolean = e.Modifiers = Keys.Control And e.KeyCode = Keys.V Dim shiftIns As Boolean = e.Modifiers = Keys.Shift And e.KeyCode = Keys.Insert diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb index 796177d7f24..98e64373c90 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb @@ -28,8 +28,6 @@ Public Class ucrDataViewReoGrid Public Event WorksheetChanged() Implements IDataViewGrid.WorksheetChanged - Public Event DeleteValueToDataframe() Implements IDataViewGrid.DeleteValuesToDataframe - Public Event WorksheetRemoved(worksheet As clsWorksheetAdapter) Implements IDataViewGrid.WorksheetRemoved Public Sub AddColumns(visiblePage As clsDataFramePage) Implements IDataViewGrid.AddColumns Dim workSheetColumnHeader As ColumnHeader @@ -134,11 +132,6 @@ Public Class ucrDataViewReoGrid e.EndReason = unvell.ReoGrid.EndEditReason.Cancel End Sub - Private Sub Worksheet_BeforeCellKeyDown(sender As Object, e As BeforeCellKeyDownEventArgs) - If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then - RaiseEvent DeleteValueToDataframe() - End If - End Sub Private Sub Worksheet_BeforePaste(sender As Object, e As BeforeRangeOperationEventArgs) e.IsCancelled = True 'prevents pasted data from being added directly into the data view diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb index b235a6c23ee..6ae084453f3 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb @@ -150,10 +150,10 @@ Public MustInherit Class ucrReoGrid Protected MustOverride Sub AttachEventsToWorksheet(Worksheet As Worksheet) Protected Sub Worksheet_BeforeCellKeyDown(sender As Object, e As BeforeCellKeyDownEventArgs) - 'If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then - ' MsgBox("This will replace the selected cells with missing values (NA)." & Environment.NewLine & "Continue?", MsgBoxStyle.Question, "Replace values with NA") - ' e.IsCancelled = True - 'End If + If e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Delete OrElse e.KeyCode = unvell.ReoGrid.Interaction.KeyCode.Back Then + MsgBox("Deleting cells is currently disabled. This feature will be included in future versions." & Environment.NewLine & "To remove a cell's value, replace the value with NA.", MsgBoxStyle.Information, "Cannot delete cells.") + e.IsCancelled = True + End If End Sub Protected Sub Worksheet_BeforeCut(sender As Object, e As BeforeRangeOperationEventArgs) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 3b6c96d23c5..5b78af702d8 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -4231,12 +4231,3 @@ DataSheet$set("public", "add_flag_fields", function(col_names) { self$add_columns_to_data(col_data = col_data, col_name = paste0(i, "_fl")) } }) - -DataSheet$set("public", "replace_values_with_NA", function(row_index, column_index) { - curr_data <- self$get_data_frame(use_current_filter = FALSE) - if(!all(row_index %in% seq_len(nrow(curr_data)))) stop("All row indexes must be within the dataframe") - if(!all(column_index %in% seq_len(ncol(curr_data)))) stop("All column indexes must be within the dataframe") - curr_data[row_index, column_index] <- NA - self$set_data(curr_data) -} -) diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 8f7dec05b63..9a0c56c4ac2 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -2714,7 +2714,3 @@ DataBook$set("public", "add_flag_fields", function(data_name, col_names, key_col self$get_data_objects(data_name)$add_flag_fields(col_names = col_names) } ) - -DataBook$set("public", "replace_values_with_NA", function(data_name, row_index, column_index) { - self$get_data_objects(data_name)$replace_values_with_NA(row_index = row_index, column_index = column_index) -}) diff --git a/instat/ucrDataView.Designer.vb b/instat/ucrDataView.Designer.vb index f90018650fe..5f8e794edff 100644 --- a/instat/ucrDataView.Designer.vb +++ b/instat/ucrDataView.Designer.vb @@ -131,7 +131,6 @@ Partial Class ucrDataView Me.lblRowNext = New System.Windows.Forms.Label() Me.lblColLast = New System.Windows.Forms.Label() Me.lblRowBack = New System.Windows.Forms.Label() - Me.mnuDeleteCell = New System.Windows.Forms.ToolStripMenuItem() Me.ucrReoGrid = New instat.ucrDataViewReoGrid() Me.ucrLinuxGrid = New instat.ucrDataViewLinuxGrid() Me.columnContextMenuStrip.SuspendLayout() @@ -285,9 +284,9 @@ Partial Class ucrDataView 'cellContextMenuStrip ' Me.cellContextMenuStrip.ImageScalingSize = New System.Drawing.Size(20, 20) - Me.cellContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripSeparator3, Me.mnuRenameColumn, Me.mnuDuplColumn, Me.mnuReorderColumn, Me.mnuDeleteCell, Me.mnuCellPasteRange, Me.ToolStripSeparator5, Me.mnuConvertToFact, Me.mnuConvertToOrderedFactor, Me.mnuConvertToCharacter, Me.mnuConvertToLogic, Me.mnuConvertToNumeric, Me.ToolStripSeparator6, Me.mnuLabelsLevel, Me.ToolStripSeparator7, Me.mnuSorts, Me.mnuComment, Me.mnuFilters, Me.mnuCellContextColumnSelection, Me.mnuCellContextRemoveCurrentColumnSelection, Me.mnuRemoveCurrentFilters}) + Me.cellContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripSeparator3, Me.mnuRenameColumn, Me.mnuDuplColumn, Me.mnuReorderColumn, Me.mnuCellPasteRange, Me.ToolStripSeparator5, Me.mnuConvertToFact, Me.mnuConvertToOrderedFactor, Me.mnuConvertToCharacter, Me.mnuConvertToLogic, Me.mnuConvertToNumeric, Me.ToolStripSeparator6, Me.mnuLabelsLevel, Me.ToolStripSeparator7, Me.mnuSorts, Me.mnuComment, Me.mnuFilters, Me.mnuCellContextColumnSelection, Me.mnuCellContextRemoveCurrentColumnSelection, Me.mnuRemoveCurrentFilters}) Me.cellContextMenuStrip.Name = "cellContextMenuStrip" - Me.cellContextMenuStrip.Size = New System.Drawing.Size(215, 402) + Me.cellContextMenuStrip.Size = New System.Drawing.Size(215, 380) ' 'ToolStripSeparator3 ' @@ -894,12 +893,6 @@ Partial Class ucrDataView Me.lblRowBack.Text = "<" Me.lblRowBack.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' - 'mnuDeleteCell - ' - Me.mnuDeleteCell.Name = "mnuDeleteCell" - Me.mnuDeleteCell.Size = New System.Drawing.Size(214, 22) - Me.mnuDeleteCell.Text = "Delete Cell(s)" - ' 'ucrReoGrid ' Me.ucrReoGrid.Dock = System.Windows.Forms.DockStyle.Fill @@ -1039,5 +1032,4 @@ Partial Class ucrDataView Friend WithEvents mnuCellContextRemoveCurrentColumnSelection As ToolStripMenuItem Friend WithEvents mnuRowContextColumnSelection As ToolStripMenuItem Friend WithEvents mnuRowContextRemoveCurrentColumnSelection As ToolStripMenuItem - Friend WithEvents mnuDeleteCell As ToolStripMenuItem End Class diff --git a/instat/ucrDataView.vb b/instat/ucrDataView.vb index 91f7a386f5b..24825936138 100644 --- a/instat/ucrDataView.vb +++ b/instat/ucrDataView.vb @@ -90,7 +90,6 @@ Public Class ucrDataView AddHandler _grid.ReplaceValueInData, AddressOf ReplaceValueInData AddHandler _grid.PasteValuesToDataframe, AddressOf PasteValuesToDataFrame AddHandler _grid.CellDataChanged, AddressOf CellDataChanged - AddHandler _grid.DeleteValuesToDataframe, AddressOf DeleteCell_Click End Sub Private Sub RefreshWorksheet(fillWorkSheet As clsWorksheetAdapter, dataFrame As clsDataFrame) @@ -334,7 +333,7 @@ Public Class ucrDataView End Select End If StartWait() - GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) + GetCurrentDataFrameFocus().clsPrepareFunctions.ReplaceValueInData(strNewValue, strColumnName, strRowText, bWithQuotes) EndWait() End Sub @@ -834,26 +833,9 @@ Public Class ucrDataView StartWait() GetCurrentDataFrameFocus().clsPrepareFunctions.RemoveCurrentColumnSelection() EndWait() - End Sub - + End Sub + Private Sub ucrDataView_Resize(sender As Object, e As EventArgs) Handles TblPanPageDisplay.Resize ResizeLabels() End Sub - - Private Sub DeleteCell_Click() - If GetSelectedColumns.Count = GetCurrentDataFrameFocus()?.iTotalColumnCount Then - MsgBox("Cannot delete all visible cells." & Environment.NewLine & "Use Prepare > Data Object > Delete Data Frame if you wish to delete the data.", MsgBoxStyle.Information, "Cannot Delete All Columns") - Else - Dim deleteCell = MsgBox("Are you sure you want to delete these cell(s)?" & Environment.NewLine & "This action cannot be undone.", MessageBoxButtons.YesNo, "Delete Cells") - If deleteCell = DialogResult.Yes Then - StartWait() - GetCurrentDataFrameFocus().clsPrepareFunctions.DeleteCells(GetSelectedRows(), GetSelectedColumnNames()) - EndWait() - End If - End If - End Sub - - Private Sub mnuDeleteCell_Click(sender As Object, e As EventArgs) Handles mnuDeleteCell.Click - DeleteCell_Click() - End Sub End Class \ No newline at end of file From b2feb677f8b1ef5f4e01e75634f89bf2ec58c094 Mon Sep 17 00:00:00 2001 From: Antoine Ntalumeso Date: Mon, 7 Feb 2022 22:51:13 +0200 Subject: [PATCH 21/32] Enabled multiple instances application --- instat/My Project/Application.Designer.vb | 2 +- instat/My Project/Application.myapp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instat/My Project/Application.Designer.vb b/instat/My Project/Application.Designer.vb index 34770b44f59..10b732a311d 100644 --- a/instat/My Project/Application.Designer.vb +++ b/instat/My Project/Application.Designer.vb @@ -24,7 +24,7 @@ Namespace My _ Public Sub New() MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) - Me.IsSingleInstance = true + Me.IsSingleInstance = false Me.EnableVisualStyles = true Me.SaveMySettingsOnExit = true Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses diff --git a/instat/My Project/Application.myapp b/instat/My Project/Application.myapp index 5eb49b3b096..739ea6fe438 100644 --- a/instat/My Project/Application.myapp +++ b/instat/My Project/Application.myapp @@ -2,7 +2,7 @@ true frmMain - true + false 0 true 0 From 5db6df4405d4ae9e7d892c54a7105e28a4de0563 Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Tue, 8 Feb 2022 09:41:38 +0300 Subject: [PATCH 22/32] Removed the Use unique values for comparisons checkbox. --- instat/dlgCompareColumns.Designer.vb | 12 ------------ instat/dlgCompareColumns.vb | 10 +++++----- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/instat/dlgCompareColumns.Designer.vb b/instat/dlgCompareColumns.Designer.vb index d1f44088a26..fe7120b4b7a 100644 --- a/instat/dlgCompareColumns.Designer.vb +++ b/instat/dlgCompareColumns.Designer.vb @@ -41,7 +41,6 @@ Partial Class dlgCompareColumns Me.ucrReceiverSecond = New instat.ucrReceiverSingle() Me.ucrReceiverFirst = New instat.ucrReceiverSingle() Me.ucrSelectorCompareColumns = New instat.ucrSelectorByDataFrameAddRemove() - Me.ucrChkUnique = New instat.ucrCheck() Me.grpComparisions.SuspendLayout() Me.SuspendLayout() ' @@ -255,15 +254,6 @@ Partial Class dlgCompareColumns Me.ucrSelectorCompareColumns.Size = New System.Drawing.Size(213, 183) Me.ucrSelectorCompareColumns.TabIndex = 0 ' - 'ucrChkUnique - ' - Me.ucrChkUnique.AutoSize = True - Me.ucrChkUnique.Checked = False - Me.ucrChkUnique.Location = New System.Drawing.Point(13, 240) - Me.ucrChkUnique.Name = "ucrChkUnique" - Me.ucrChkUnique.Size = New System.Drawing.Size(257, 24) - Me.ucrChkUnique.TabIndex = 5 - ' 'dlgCompareColumns ' Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!) @@ -283,7 +273,6 @@ Partial Class dlgCompareColumns Me.Controls.Add(Me.ucrReceiverSecond) Me.Controls.Add(Me.ucrReceiverFirst) Me.Controls.Add(Me.ucrSelectorCompareColumns) - Me.Controls.Add(Me.ucrChkUnique) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False @@ -304,7 +293,6 @@ Partial Class dlgCompareColumns Friend WithEvents lblFirstColumn As Label Friend WithEvents ucrReceiverSecond As ucrReceiverSingle Friend WithEvents ucrBase As ucrButtons - Friend WithEvents ucrChkUnique As ucrCheck Friend WithEvents grpComparisions As GroupBox Friend WithEvents ucrChkSort As ucrCheck Friend WithEvents ucrChkFirstNotSecond As ucrCheck diff --git a/instat/dlgCompareColumns.vb b/instat/dlgCompareColumns.vb index b14616587ad..19913822349 100644 --- a/instat/dlgCompareColumns.vb +++ b/instat/dlgCompareColumns.vb @@ -51,7 +51,7 @@ Public Class dlgCompareColumns ucrPnlOptions.AddRadioButton(rdoByRow) ucrPnlOptions.AddRadioButton(rdoByValue) - ucrPnlOptions.AddToLinkedControls({ucrChkUnique, ucrChkSort, ucrChkFirstNotSecond}, {rdoByValue}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlOptions.AddToLinkedControls({ucrChkSort, ucrChkFirstNotSecond}, {rdoByValue}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrChkFirstNotSecond.SetLinkedDisplayControl(grpComparisions) ucrReceiverFirst.SetParameter(New RParameter("x", 0)) @@ -78,9 +78,9 @@ Public Class dlgCompareColumns ucrInputTolerance.SetLinkedDisplayControl(lblTolerance) ucrInputTolerance.bAllowNonConditionValues = True - ucrChkUnique.SetParameter(New RParameter("use_unique", 2), bNewChangeParameterValue:=True) - ucrChkUnique.SetText("Use unique values for comparison") - ucrChkUnique.SetRDefault("TRUE") + 'ucrChkUnique.SetParameter(New RParameter("use_unique", 2), bNewChangeParameterValue:=True) + 'ucrChkUnique.SetText("Use unique values for comparison") + 'ucrChkUnique.SetRDefault("TRUE") ucrChkSort.SetParameter(New RParameter("sort_values", 3), bNewChangeParameterValue:=True) ucrChkSort.SetText("Sort values") @@ -171,7 +171,7 @@ Public Class dlgCompareColumns ucrReceiverFirst.SetRCode(clsCompareColumnsFunction, bReset) ucrReceiverSecond.SetRCode(clsCompareColumnsFunction, bReset) - ucrChkUnique.SetRCode(clsCompareColumnsFunction, bReset) + 'ucrChkUnique.SetRCode(clsCompareColumnsFunction, bReset) ucrChkSort.SetRCode(clsCompareColumnsFunction, bReset) ucrChkFirstNotSecond.SetRCode(clsCompareColumnsFunction, bReset) ucrChkSecondNotFirst.SetRCode(clsCompareColumnsFunction, bReset) From f5e34df05332296143582fb32adc136752492ab1 Mon Sep 17 00:00:00 2001 From: patowhiz Date: Tue, 8 Feb 2022 17:55:11 +0300 Subject: [PATCH 23/32] Made suggested changes --- instat/clsRecentFiles.vb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/instat/clsRecentFiles.vb b/instat/clsRecentFiles.vb index f61e8c16dcb..241e6a9b24b 100644 --- a/instat/clsRecentFiles.vb +++ b/instat/clsRecentFiles.vb @@ -64,8 +64,12 @@ Public Class clsRecentFiles 'read file contents Dim arrStrPaths() As String = File.ReadAllLines(strRecentFilesPath) For Each strPath As String In arrStrPaths - If Not String.IsNullOrEmpty(strPath) AndAlso Not lstRecentOpenedFiles.Contains(strPath.Replace("\", "/")) Then - lstRecentOpenedFiles.Add(strPath.Replace("\", "/")) + If String.IsNullOrEmpty(strPath) Then + Continue For + End If + Dim strNewPath As String = strPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + If Not lstRecentOpenedFiles.Contains(strNewPath) Then + lstRecentOpenedFiles.Add(strNewPath) End If Next 'display the recently opened files if there are any items to display in the file @@ -106,8 +110,8 @@ Public Class clsRecentFiles ''' ''' file path to add to menu items Public Sub addToMenu(strFilePath As String) - strFilePath = strFilePath.Replace("\", "/") - 'remove file if it exists(helps with making sure displayed file names are rearranged) + strFilePath = strFilePath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + 'remove file if already in lists(helps with making sure displayed file names are rearranged) lstRecentOpenedFiles.Remove(strFilePath) 'add to recent opened files list.. lstRecentOpenedFiles.Add(strFilePath) @@ -187,7 +191,6 @@ Public Class clsRecentFiles End If Dim strFilePathTmp As String = strFilePath.Replace("MRU:", "") - strFilePathTmp = strFilePathTmp.Replace("\", "/") If File.Exists(strFilePathTmp) Then dlgImportDataset.strFileToOpenOn = strFilePathTmp dlgImportDataset.ShowDialog() From 9b405d8be8c983ef78dca0b1fb851e81d8255ca7 Mon Sep 17 00:00:00 2001 From: Shadrack Kibet Date: Tue, 8 Feb 2022 18:44:03 +0300 Subject: [PATCH 24/32] Update instat/static/InstatObject/R/data_object_R6.R Co-authored-by: lloyddewit <57253949+lloyddewit@users.noreply.github.com> --- 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 ed54b1b6d74..2b022b0c310 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -308,7 +308,7 @@ DataSheet$set("public", "get_data_frame", function(convert_to_character = FALSE, selected_columns <- self$get_column_names() out <- out[ ,selected_columns, drop = FALSE] for(name in names(old_metadata)) { - if(!name %in% c("names", "class", "row.names")) { + if(!(name %in% c("names", "class", "row.names"))) { attr(out, name) <- old_metadata[[name]] } } From 44269c1a28ecb5682045db24f353e8f1b42d9a3c Mon Sep 17 00:00:00 2001 From: Antoine Ntalumeso Date: Wed, 9 Feb 2022 08:34:00 +0200 Subject: [PATCH 25/32] Minor change for overflow cells text --- instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb | 1 + 1 file changed, 1 insertion(+) diff --git a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb index 6ae084453f3..a1862afb6a2 100644 --- a/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb +++ b/instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb @@ -62,6 +62,7 @@ Public MustInherit Class ucrReoGrid fillWorkSheet.SelectionForwardDirection = unvell.ReoGrid.SelectionForwardDirection.Down fillWorkSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False) fillWorkSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToFillSerial, False) + fillWorkSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.View_AllowCellTextOverflow, False) AttachEventsToWorksheet(fillWorkSheet) Return New clsWorksheetAdapter(fillWorkSheet) End Function From 91d2fc4c27e2a2fded8f4d1cf552b1aeb61725f3 Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:28:38 +0300 Subject: [PATCH 26/32] Removed the unecessary lines --- instat/dlgCompareColumns.vb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/instat/dlgCompareColumns.vb b/instat/dlgCompareColumns.vb index 19913822349..112bbf11c3b 100644 --- a/instat/dlgCompareColumns.vb +++ b/instat/dlgCompareColumns.vb @@ -78,10 +78,6 @@ Public Class dlgCompareColumns ucrInputTolerance.SetLinkedDisplayControl(lblTolerance) ucrInputTolerance.bAllowNonConditionValues = True - 'ucrChkUnique.SetParameter(New RParameter("use_unique", 2), bNewChangeParameterValue:=True) - 'ucrChkUnique.SetText("Use unique values for comparison") - 'ucrChkUnique.SetRDefault("TRUE") - ucrChkSort.SetParameter(New RParameter("sort_values", 3), bNewChangeParameterValue:=True) ucrChkSort.SetText("Sort values") ucrChkSort.SetRDefault("TRUE") @@ -171,7 +167,6 @@ Public Class dlgCompareColumns ucrReceiverFirst.SetRCode(clsCompareColumnsFunction, bReset) ucrReceiverSecond.SetRCode(clsCompareColumnsFunction, bReset) - 'ucrChkUnique.SetRCode(clsCompareColumnsFunction, bReset) ucrChkSort.SetRCode(clsCompareColumnsFunction, bReset) ucrChkFirstNotSecond.SetRCode(clsCompareColumnsFunction, bReset) ucrChkSecondNotFirst.SetRCode(clsCompareColumnsFunction, bReset) From 3cba3700633f7dd53b11dfc1b75671b0b0e17712 Mon Sep 17 00:00:00 2001 From: mmulahvictor <60970331+mmulahvictor@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:40:37 +0300 Subject: [PATCH 27/32] Alligning the sort values dialog --- instat/dlgCompareColumns.Designer.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgCompareColumns.Designer.vb b/instat/dlgCompareColumns.Designer.vb index fe7120b4b7a..dac74a68761 100644 --- a/instat/dlgCompareColumns.Designer.vb +++ b/instat/dlgCompareColumns.Designer.vb @@ -202,7 +202,7 @@ Partial Class dlgCompareColumns ' Me.ucrChkSort.AutoSize = True Me.ucrChkSort.Checked = False - Me.ucrChkSort.Location = New System.Drawing.Point(276, 240) + Me.ucrChkSort.Location = New System.Drawing.Point(21, 241) Me.ucrChkSort.Name = "ucrChkSort" Me.ucrChkSort.Size = New System.Drawing.Size(115, 23) Me.ucrChkSort.TabIndex = 6 From 9e2237a93ffa843d69a2d9393e700ff9b38d1be7 Mon Sep 17 00:00:00 2001 From: Haward Ketoyo Date: Thu, 10 Feb 2022 12:36:54 +0300 Subject: [PATCH 28/32] In this ommit I added two geoms, (geom_categorical_model and geom_parallel_slopes) from moderndive package. I also changed the location of geom_mosaic in the list of geoms so that geom_mosaic can follow the alphabetic order in the list of all geoms. --- instat/ucrGeom.vb | 86 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/instat/ucrGeom.vb b/instat/ucrGeom.vb index d6df65fb6eb..6b514eef24c 100644 --- a/instat/ucrGeom.vb +++ b/instat/ucrGeom.vb @@ -123,6 +123,7 @@ Public Class ucrGeom Dim clsgeom_bin2d As New Geoms Dim clsgeom_blank As New Geoms Dim clsgeom_boxplot As New Geoms + Dim clsgeom_categorical_model As New Geoms Dim clsgeom_contour As New Geoms Dim clsgeom_count As New Geoms Dim clsgeom_col As New Geoms @@ -149,6 +150,7 @@ Public Class ucrGeom Dim clsgeom_lollipop As New Geoms Dim clsgeom_map As New Geoms Dim clsgeom_mosaic As New Geoms + Dim clsgeom_parallel_slopes As New Geoms Dim clsgeom_path As New Geoms Dim clsgeom_point As New Geoms Dim clsgeom_pointrange As New Geoms @@ -511,6 +513,27 @@ Public Class ucrGeom lstAllGeoms.Add(clsgeom_boxplot) + clsgeom_categorical_model.SetGeomPackage("moderndive") + clsgeom_categorical_model.SetGeomName("geom_categorical_model") + 'Mandatory Aesthetics + clsgeom_categorical_model.AddAesParameter("x", bIsMandatory:=True) + clsgeom_categorical_model.AddAesParameter("y", bIsMandatory:=True) + + 'Optional Aesthetics + clsgeom_categorical_model.AddAesParameter("colour") + clsgeom_categorical_model.AddAesParameter("size") + + 'Add layer parameters + clsgeom_categorical_model.AddLayerParameter("position", "list", Chr(34) & "identity" & Chr(34), lstParameterStrings:={Chr(34) & "identity" & Chr(34), Chr(34) & "jitter" & Chr(34)}) + clsgeom_categorical_model.AddLayerParameter("se ", "list", "TRUE", lstParameterStrings:={"TRUE", "FALSE"}) 'We add space after parameter name se ("se ") for correct labeling, if the space is omitted, vb labels "se" as "ifelse" but when the space is included "se " is correctly labelled as "se". + clsgeom_categorical_model.AddLayerParameter("level", "numeric", "0.95", lstParameterStrings:={2, 0, 1}) + clsgeom_categorical_model.AddLayerParameter("size", "numeric", "3", lstParameterStrings:={0, 0}) + clsgeom_categorical_model.AddLayerParameter("na.rm", "boolean", "FALSE") + clsgeom_categorical_model.AddLayerParameter("show.legend", "list", "TRUE", lstParameterStrings:={"NA", "TRUE", "FALSE"}) + clsgeom_categorical_model.AddLayerParameter("inherit.aes", "boolean", "TRUE") + + lstAllGeoms.Add(clsgeom_categorical_model) + clsgeom_col.SetGeomName("geom_col") 'Mandatory Aesthetics clsgeom_col.AddAesParameter("x", strIncludedDataTypes:=({"factor", "numeric"}), bIsMandatory:=True) @@ -1371,26 +1394,6 @@ Public Class ucrGeom lstAllGeoms.Add(clsgeom_lollipop) - clsgeom_path.strGeomName = "geom_path" - 'mandatory - clsgeom_path.AddAesParameter("x", bIsMandatory:=True) - clsgeom_path.AddAesParameter("y", bIsMandatory:=True) - 'optional - clsgeom_path.AddAesParameter("alpha") - clsgeom_path.AddAesParameter("colour") - clsgeom_path.AddAesParameter("linetype") - clsgeom_path.AddAesParameter("size") - 'add layer parameters - - clsgeom_path.AddLayerParameter("stat", "list", Chr(34) & "contour" & Chr(34), lstParameterStrings:={Chr(34) & "contour" & Chr(34), Chr(34) & "identity" & Chr(34)}) - clsgeom_path.AddLayerParameter("position", "list", Chr(34) & "identity" & Chr(34), lstParameterStrings:={Chr(34) & "identity" & Chr(34)}) - clsgeom_path.AddLayerParameter("lineend", "list", Chr(34) & "butt" & Chr(34), lstParameterStrings:={Chr(34) & "round" & Chr(34), Chr(34) & "butt" & Chr(34), Chr(34) & "square" & Chr(34)}) - clsgeom_path.AddLayerParameter("linejoin", "list", Chr(34) & "round" & Chr(34), lstParameterStrings:={Chr(34) & "round" & Chr(34), Chr(34) & "mitre" & Chr(34), Chr(34) & "bevel" & Chr(34)}) - 'linemitre should 1 or a number >1 - clsgeom_path.AddLayerParameter("linemitre", "numeric", "1", lstParameterStrings:={0, 1}) - clsgeom_path.AddLayerParameter("arrow", "editablelist", "arrow()", lstParameterStrings:={"arrow()"}) - lstAllGeoms.Add(clsgeom_path) - clsgeom_mosaic.SetGeomPackage("ggmosaic") clsgeom_mosaic.strGeomName = "geom_mosaic" 'mandatory @@ -1410,6 +1413,49 @@ Public Class ucrGeom clsgeom_mosaic.AddLayerParameter("show.legend", "list", "TRUE", lstParameterStrings:={"NA", "TRUE", "FALSE"}) lstAllGeoms.Add(clsgeom_mosaic) + clsgeom_parallel_slopes.SetGeomPackage("moderndive") + clsgeom_parallel_slopes.SetGeomName("geom_parallel_slopes") + 'Mandatory Aesthetics + clsgeom_parallel_slopes.AddAesParameter("x", bIsMandatory:=True) + clsgeom_parallel_slopes.AddAesParameter("y", bIsMandatory:=True) + + 'Optional Aesthetics + clsgeom_parallel_slopes.AddAesParameter("colour") + clsgeom_parallel_slopes.AddAesParameter("size") + + 'Add layer parameters + clsgeom_parallel_slopes.AddLayerParameter("position", "list", Chr(34) & "identity" & Chr(34), lstParameterStrings:={Chr(34) & "identity" & Chr(34), Chr(34) & "jitter" & Chr(34)}) + clsgeom_parallel_slopes.AddLayerParameter("se ", "list", "TRUE", lstParameterStrings:={"TRUE", "FALSE"}) 'We add space after parameter name se ("se ") for correct labeling, if the space is omitted, vb labels "se" as "ifelse" but when the space is included "se " is correctly labelled as "se". + clsgeom_parallel_slopes.AddLayerParameter("formula", "editablelist", "y ~ x", lstParameterStrings:={"y ~ x", "y ~ poly(x, 2)", "y ~ log(x)"}) + clsgeom_parallel_slopes.AddLayerParameter("n", "numeric", "0") + clsgeom_parallel_slopes.AddLayerParameter("fullrange", "boolean", "FALSE") + clsgeom_parallel_slopes.AddLayerParameter("level", "numeric", "0.95", lstParameterStrings:={2, 0, 1}) + clsgeom_parallel_slopes.AddLayerParameter("size", "numeric", "3", lstParameterStrings:={0, 0}) + clsgeom_parallel_slopes.AddLayerParameter("na.rm", "boolean", "FALSE") + clsgeom_parallel_slopes.AddLayerParameter("show.legend", "list", "TRUE", lstParameterStrings:={"NA", "TRUE", "FALSE"}) + clsgeom_parallel_slopes.AddLayerParameter("inherit.aes", "boolean", "TRUE") + + lstAllGeoms.Add(clsgeom_parallel_slopes) + + clsgeom_path.strGeomName = "geom_path" + 'mandatory + clsgeom_path.AddAesParameter("x", bIsMandatory:=True) + clsgeom_path.AddAesParameter("y", bIsMandatory:=True) + 'optional + clsgeom_path.AddAesParameter("alpha") + clsgeom_path.AddAesParameter("colour") + clsgeom_path.AddAesParameter("linetype") + clsgeom_path.AddAesParameter("size") + 'add layer parameters + + clsgeom_path.AddLayerParameter("stat", "list", Chr(34) & "contour" & Chr(34), lstParameterStrings:={Chr(34) & "contour" & Chr(34), Chr(34) & "identity" & Chr(34)}) + clsgeom_path.AddLayerParameter("position", "list", Chr(34) & "identity" & Chr(34), lstParameterStrings:={Chr(34) & "identity" & Chr(34)}) + clsgeom_path.AddLayerParameter("lineend", "list", Chr(34) & "butt" & Chr(34), lstParameterStrings:={Chr(34) & "round" & Chr(34), Chr(34) & "butt" & Chr(34), Chr(34) & "square" & Chr(34)}) + clsgeom_path.AddLayerParameter("linejoin", "list", Chr(34) & "round" & Chr(34), lstParameterStrings:={Chr(34) & "round" & Chr(34), Chr(34) & "mitre" & Chr(34), Chr(34) & "bevel" & Chr(34)}) + 'linemitre should 1 or a number >1 + clsgeom_path.AddLayerParameter("linemitre", "numeric", "1", lstParameterStrings:={0, 1}) + clsgeom_path.AddLayerParameter("arrow", "editablelist", "arrow()", lstParameterStrings:={"arrow()"}) + lstAllGeoms.Add(clsgeom_path) clsgeom_point.SetGeomName("geom_point") 'Mandatory aesthetics : here x and y are mandatory, however, when not filled, default values "" are given. Alternatively, if we want to have at least on filled, could add bIsDependentlyMandatory:=TRUE in both. Planning on refining the mandatory aes methods to include the "" cases systematically. From f6b339dbffd5ef6524a434a217835db39e14ccd9 Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 11 Feb 2022 10:48:19 +0300 Subject: [PATCH 29/32] added fastDummies R package --- instat/static/InstatObject/R/install_packages.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/install_packages.R b/instat/static/InstatObject/R/install_packages.R index 955df9a6ef6..5a880c0d72b 100644 --- a/instat/static/InstatObject/R/install_packages.R +++ b/instat/static/InstatObject/R/install_packages.R @@ -116,7 +116,9 @@ pkgs <- "janitor", "ggwordcloud", # For producing periodic and natural splines in Climatic > Compare > Seasonal Plot - "splines2" + "splines2", + # For fast creation of dummy (binary) variables from categories variables in Prepare > Column:Factor > Dummy Variables + "fastDummies" # also install mmtable2 from GitHub devtools::install_github("ianmoran11/mmtable2") ) pkgList <- pkgDep(pkgs, type="win.binary", repos = "https://cran.rstudio.com/", suggests = FALSE, includeBasePkgs = FALSE, Rversion = r_version) From d4044f46830b0c7180fe0d6c2402876dabef431b Mon Sep 17 00:00:00 2001 From: shadrack kibet Date: Fri, 11 Feb 2022 10:53:05 +0300 Subject: [PATCH 30/32] removed dummies R package --- instat/static/InstatObject/R/install_packages.R | 1 - 1 file changed, 1 deletion(-) diff --git a/instat/static/InstatObject/R/install_packages.R b/instat/static/InstatObject/R/install_packages.R index 5a880c0d72b..30435fd43e9 100644 --- a/instat/static/InstatObject/R/install_packages.R +++ b/instat/static/InstatObject/R/install_packages.R @@ -32,7 +32,6 @@ pkgs <- "rio", "readxl", "lme4", - "dummies", "ggthemes", "lazyeval", "stringr", From 4aa9df5138369a71938e9c94817a70edab026d29 Mon Sep 17 00:00:00 2001 From: Lily Clements Date: Mon, 14 Feb 2022 13:17:09 +0000 Subject: [PATCH 31/32] adding dates functionality in summary tables code --- .../R/Backend_Components/summary_functions.R | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 8d0b89f9a04..37115361fb9 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -1361,12 +1361,12 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise levels(cell_values[[i]]) <- c(levels(cell_values[[i]]), na_level_display) cell_values[[i]][is.na(cell_values[[i]])] <- na_level_display } - grps <- nrow(cell_values) - cell_values <- reshape2:::melt.data.frame(cell_values, id.vars = factors, variable.name = "summary-variable", value.name = "value") + cell_values <- cell_values %>% dplyr::mutate(dplyr::across(where(is.numeric), round, signif_fig)) + cell_values <- cell_values %>% + tidyr::pivot_longer(cols = !factors, names_to = "summary-variable", values_to = "value", values_transform = list(value = as.character)) if (treat_columns_as_factor) { - cell_values[["variable"]] <- rep(columns_to_summarise, each = nrow(cell_values) / length(columns_to_summarise)) - cell_values[["summary"]] <- rep(summaries_display, each = grps, length.out = nrow(cell_values)) - cell_values[["summary-variable"]] <- NULL + cell_values <- cell_values %>% + tidyr::separate(col = "summary-variable", into = c("summary", "variable"), sep = "-") } shaped_cell_values <- cell_values %>% dplyr::relocate(value, .after = last_col()) @@ -1386,12 +1386,16 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise for (facts in power_sets_outer) { if (length(facts) == 0) facts <- c() margin_tables[[length(margin_tables) + 1]] <- self$calculate_summary(data_name = data_name, columns_to_summarise = columns_to_summarise, summaries = summaries, factors = facts, store_results = FALSE, drop = drop, na.rm = na.rm, return_output = TRUE, weights = weights, result_names = result_names, percentage_type = percentage_type, perc_total_columns = perc_total_columns, perc_total_factors = perc_total_factors, perc_total_filter = perc_total_filter, perc_decimal = perc_decimal, margin_name = margin_name, additional_filter = additional_filter, perc_return_all = FALSE, sep = "-", ...) - margin_tables[[length(margin_tables)]] <- margin_tables[[length(margin_tables)]] %>% dplyr::select(c(all_of(facts), order_names)) + margin_tables[[length(margin_tables)]] <- margin_tables[[length(margin_tables)]] %>% dplyr::select(c(tidyselect::all_of(facts), tidyselect::all_of(order_names))) } # for outer margins margin_item <- length(summaries) * length(columns_to_summarise) - if (("outer" %in% margins) && (length(factors) > 0)) { + # to prevent changing all variables to dates/converting dates to numeric + for (i in 1:length(margin_tables)){ + margin_tables[[i]] <- margin_tables[[i]] %>% dplyr::mutate(dplyr::across(where(is.numeric), round, signif_fig)) + margin_tables[[i]] <- margin_tables[[i]] %>% purrr::modify_if(lubridate::is.Date, as.character) + } outer_margins <- plyr::ldply(margin_tables) # Change shape if (length(margin_tables) == 1) { @@ -1399,7 +1403,8 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise names(outer_margins) <- c("summary-variable", "value") } else { outer_margins <- outer_margins %>% - tidyr::pivot_longer(cols = 1:margin_item, values_to = "value", names_to = "summary-variable") + tidyr::pivot_longer(cols = 1:margin_item, values_to = "value", names_to = "summary-variable", + values_transform = list(value = as.character)) } if (treat_columns_as_factor) { outer_margins <- outer_margins %>% @@ -1418,28 +1423,29 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise for (facts in power_sets_summary) { if (length(facts) == 0) facts <- c() summary_margins_df <- data_book$get_data_frame(data_name = data_name) %>% - dplyr::select(c(factors, columns_to_summarise)) %>% - tidyr::pivot_longer(cols = columns_to_summarise) + dplyr::select(c(tidyselect::all_of(factors), tidyselect::all_of(columns_to_summarise))) %>% + tidyr::pivot_longer(cols = columns_to_summarise, values_transform = list(value = as.character)) data_book$import_data(data_tables = list(summary_margins_df = summary_margins_df)) summary_margins[[length(summary_margins) + 1]] <- data_book$calculate_summary(data_name = "summary_margins_df", columns_to_summarise = "value", summaries = summaries, factors = facts, store_results = FALSE, drop = drop, na.rm = na.rm, return_output = TRUE, weights = weights, result_names = result_names, percentage_type = percentage_type, perc_total_columns = perc_total_columns, perc_total_factors = perc_total_factors, perc_total_filter = perc_total_filter, perc_decimal = perc_decimal, margin_name = margin_name, additional_filter = additional_filter, perc_return_all = FALSE, ...) data_book$delete_dataframes(data_names = "summary_margins_df") } summary_margins <- plyr::ldply(summary_margins) - if (treat_columns_as_factor) { # remove "_value" in them for (col in 1:ncol(summary_margins)) { colnames(summary_margins)[col] <- sub("_value", "", colnames(summary_margins)[col]) } + summary_margins <- summary_margins %>% dplyr::mutate(dplyr::across(where(is.numeric), round, signif_fig)) summary_margins <- summary_margins %>% - tidyr::pivot_longer(cols = !factors, names_to = "summary", values_to = "value") + tidyr::pivot_longer(cols = !factors, names_to = "summary", values_to = "value", values_transform = list(value = as.character)) } else { for (col in 1:ncol(summary_margins)) { # TODO: if the colname is the same as a factor, then do nothing colnames(summary_margins)[col] <- sub("_value", "_all", colnames(summary_margins)[col]) } + summary_margins <- summary_margins %>% dplyr::mutate(dplyr::across(where(is.numeric), round, signif_fig)) summary_margins <- summary_margins %>% - tidyr::pivot_longer(cols = !factors, names_to = "summary-variable", values_to = "value") + tidyr::pivot_longer(cols = !factors, names_to = "summary-variable", values_to = "value", values_transform = list(value = as.character)) } } else { summary_margins <- NULL @@ -1455,8 +1461,7 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise dplyr::mutate_at(vars(-value), ~ forcats::as_factor(forcats::fct_relevel(., margin_name, after = Inf))) } } - shaped_cell_values <- shaped_cell_values %>% dplyr::mutate(value = round(value, signif_fig)) -if (treat_columns_as_factor){ + if (treat_columns_as_factor){ shaped_cell_values <- shaped_cell_values %>% dplyr::mutate(summary = as.factor(summary)) %>% dplyr::mutate(summary = forcats::fct_relevel(summary, summaries_display)) %>% dplyr::mutate(variable = as.factor(variable)) %>% dplyr::mutate(variable= forcats::fct_relevel(variable, columns_to_summarise)) @@ -1465,4 +1470,4 @@ if (store_table) { data_book$import_data(data_tables = list(shaped_cell_values = shaped_cell_values)) } return(shaped_cell_values) -}) +}) \ No newline at end of file From 1f7aac699458a985bac016b2dd4a5fd1870f2140 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Thu, 3 Mar 2022 13:24:59 +0000 Subject: [PATCH 32/32] Update summary_functions.R --- .../R/Backend_Components/summary_functions.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 37115361fb9..07fbc72a353 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -1456,6 +1456,13 @@ DataBook$set("public", "summary_table", function(data_name, columns_to_summarise margin_tables_all <- margin_tables_all %>% dplyr::mutate_at(vars(-value), ~ replace(., is.na(.), margin_name)) + for (i in factors){ + shaped_cell_values_levels <- levels(shaped_cell_values[[i]]) + margin_tables_all <- margin_tables_all %>% + dplyr::mutate_at(i, ~ forcats::fct_expand(., shaped_cell_values_levels), + i, ~ forcats::fct_relevel(., shaped_cell_values_levels)) + } + shaped_cell_values <- dplyr::bind_rows(shaped_cell_values, margin_tables_all) %>% dplyr::mutate_at(vars(-value), ~ replace(., is.na(.), margin_name)) %>% dplyr::mutate_at(vars(-value), ~ forcats::as_factor(forcats::fct_relevel(., margin_name, after = Inf))) @@ -1470,4 +1477,4 @@ if (store_table) { data_book$import_data(data_tables = list(shaped_cell_values = shaped_cell_values)) } return(shaped_cell_values) -}) \ No newline at end of file +})