From 21ca025230a5a43ea7f5771f93734f9cad8417a1 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Mon, 2 Dec 2024 16:17:57 +0000 Subject: [PATCH 01/13] Adding option to rename labels --- instat/static/InstatObject/R/data_object_R6.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 2bea3ede08..31bc20285a 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1011,6 +1011,25 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne self$data_changed <- TRUE self$variables_metadata_changed <- TRUE } + } else if (type == "rename_labels"){ + # to rename column labels. Here, instead of renaming a column name, we're giving new values in a column. + curr_metadata <- self$get_variables_metadata() + curr_col_names <- names(curr_data) + + new_metadata <- curr_metadata |> + dplyr::mutate( + dplyr::across( + {{ .cols }}, + ~ .fn(., ...) + ) + ) + if(self$column_selection_applied()) self$remove_current_column_selection() + new_label_names <- new_metadata[!("Name" %in% curr_col_names)]$label + for (i in seq_along(new_label_names)) { + self$append_to_variables_metadata(curr_col_names[i], property = "label", new_val = new_label_names[i]) + } + self$data_changed <- TRUE + self$variables_metadata_changed <- TRUE } }) From 1d34edd6c805c37379661c7403282df8d205bc44 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Wed, 4 Dec 2024 09:54:01 +0300 Subject: [PATCH 02/13] changes to the code --- instat/dlgName.Designer.vb | 32 +++++++++++++++++++++++++++----- instat/dlgName.vb | 22 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/instat/dlgName.Designer.vb b/instat/dlgName.Designer.vb index 343d0eee9b..222e51d490 100644 --- a/instat/dlgName.Designer.vb +++ b/instat/dlgName.Designer.vb @@ -71,6 +71,7 @@ Partial Class dlgName Me.ucrPnlOptions = New instat.UcrPanel() Me.ucrReceiverColumns = New instat.ucrReceiverMultiple() Me.ucrPnlSelectData = New instat.UcrPanel() + Me.rdoLabels = New System.Windows.Forms.RadioButton() Me.grpOptions.SuspendLayout() Me.SuspendLayout() ' @@ -109,7 +110,7 @@ Partial Class dlgName Me.rdoMultiple.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption Me.rdoMultiple.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.rdoMultiple.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.rdoMultiple.Location = New System.Drawing.Point(218, 10) + Me.rdoMultiple.Location = New System.Drawing.Point(178, 10) Me.rdoMultiple.Name = "rdoMultiple" Me.rdoMultiple.Size = New System.Drawing.Size(110, 28) Me.rdoMultiple.TabIndex = 2 @@ -128,7 +129,7 @@ Partial Class dlgName Me.rdoSingle.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption Me.rdoSingle.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.rdoSingle.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.rdoSingle.Location = New System.Drawing.Point(108, 10) + Me.rdoSingle.Location = New System.Drawing.Point(70, 10) Me.rdoSingle.Name = "rdoSingle" Me.rdoSingle.Size = New System.Drawing.Size(110, 28) Me.rdoSingle.TabIndex = 1 @@ -312,7 +313,7 @@ Partial Class dlgName Me.rdoRenameWith.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption Me.rdoRenameWith.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.rdoRenameWith.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.rdoRenameWith.Location = New System.Drawing.Point(328, 10) + Me.rdoRenameWith.Location = New System.Drawing.Point(286, 10) Me.rdoRenameWith.Name = "rdoRenameWith" Me.rdoRenameWith.Size = New System.Drawing.Size(110, 28) Me.rdoRenameWith.TabIndex = 13 @@ -429,9 +430,9 @@ Partial Class dlgName 'ucrPnlOptions ' Me.ucrPnlOptions.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink - Me.ucrPnlOptions.Location = New System.Drawing.Point(97, 2) + Me.ucrPnlOptions.Location = New System.Drawing.Point(62, 2) Me.ucrPnlOptions.Name = "ucrPnlOptions" - Me.ucrPnlOptions.Size = New System.Drawing.Size(355, 44) + Me.ucrPnlOptions.Size = New System.Drawing.Size(448, 44) Me.ucrPnlOptions.TabIndex = 0 ' 'ucrReceiverColumns @@ -455,12 +456,32 @@ Partial Class dlgName Me.ucrPnlSelectData.Size = New System.Drawing.Size(315, 51) Me.ucrPnlSelectData.TabIndex = 19 ' + 'rdoLabels + ' + Me.rdoLabels.Appearance = System.Windows.Forms.Appearance.Button + Me.rdoLabels.BackColor = System.Drawing.SystemColors.Control + Me.rdoLabels.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoLabels.FlatAppearance.BorderSize = 2 + Me.rdoLabels.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoLabels.FlatStyle = System.Windows.Forms.FlatStyle.Flat + Me.rdoLabels.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.rdoLabels.Location = New System.Drawing.Point(394, 10) + Me.rdoLabels.Name = "rdoLabels" + Me.rdoLabels.Size = New System.Drawing.Size(110, 28) + Me.rdoLabels.TabIndex = 22 + Me.rdoLabels.TabStop = True + Me.rdoLabels.Tag = "" + Me.rdoLabels.Text = "Labels With" + Me.rdoLabels.TextAlign = System.Drawing.ContentAlignment.MiddleCenter + Me.rdoLabels.UseVisualStyleBackColor = False + ' 'dlgName ' 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(545, 540) + Me.Controls.Add(Me.rdoLabels) Me.Controls.Add(Me.grdRenameColumns) Me.Controls.Add(Me.ucrChkIncludeVariable) Me.Controls.Add(Me.rdoRenameWith) @@ -527,4 +548,5 @@ Partial Class dlgName Friend WithEvents rdoSelectedColumn As RadioButton Friend WithEvents rdoWholeDataFrame As RadioButton Friend WithEvents ucrPnlSelectData As UcrPanel + Friend WithEvents rdoLabels As RadioButton End Class diff --git a/instat/dlgName.vb b/instat/dlgName.vb index b108de0f7e..b345413a36 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -83,6 +83,7 @@ Public Class dlgName ucrPnlOptions.AddRadioButton(rdoSingle, Chr(34) & "single" & Chr(34)) ucrPnlOptions.AddRadioButton(rdoMultiple, Chr(34) & "multiple" & Chr(34)) ucrPnlOptions.AddRadioButton(rdoRenameWith, Chr(34) & "rename_with" & Chr(34)) + ucrPnlOptions.AddRadioButton(rdoLabels, Chr(34) & "labels_with" & Chr(34)) ucrPnlOptions.SetRDefault(Chr(34) & "single" & Chr(34)) ucrNudAbbreviate.SetParameter(New RParameter("minlength", 10)) @@ -142,7 +143,7 @@ Public Class dlgName ucrPnlOptions.AddToLinkedControls({ucrReceiverName, ucrInputNewName, ucrInputVariableLabel}, {rdoSingle}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlOptions.AddToLinkedControls(ucrChkIncludeVariable, {rdoMultiple}, bNewLinkedHideIfParameterMissing:=True) - ucrPnlOptions.AddToLinkedControls({ucrPnlCase, ucrPnlSelectData}, {rdoRenameWith}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlOptions.AddToLinkedControls({ucrPnlCase, ucrPnlSelectData}, {rdoRenameWith, rdoLabels}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputCase, {rdoMakeCleanNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Snake") ucrPnlCase.AddToLinkedControls(ucrNudAbbreviate, {rdoAbbreviate}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="8") ucrPnlCase.AddToLinkedControls(ucrInputReplace, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) @@ -569,7 +570,7 @@ Public Class dlgName Private Sub ucrPnlOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlOptions.ControlValueChanged, ucrPnlCase.ControlValueChanged, ucrPnlSelectData.ControlValueChanged, ucrInputCase.ControlValueChanged, ucrNudAbbreviate.ControlValueChanged, ucrReceiverColumns.ControlValueChanged If rdoSingle.Checked Then ucrReceiverName.SetMeAsReceiver() - ElseIf rdoRenameWith.Checked Then + ElseIf rdoRenameWith.Checked OrElse rdoLabels.Checked Then ucrInputBy.Visible = rdoWholeDataFrame.Checked AndAlso rdoReplace.Checked ucrInputEdit.Visible = ucrInputBy.Visible ucrInputReplace.Visible = ucrInputBy.Visible @@ -584,12 +585,14 @@ Public Class dlgName End If End If ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) + ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) ucrSelectVariables.btnAdd.Visible = ucrSelectVariables.lstAvailableVariable.Visible ucrSelectVariables.btnDataOptions.Visible = ucrSelectVariables.lstAvailableVariable.Visible UpdateGrid() RemoveParameters() DialogueSize() RemovePattern() + AddTypeParm() End Sub Private Sub DialogueSize() @@ -660,8 +663,7 @@ Public Class dlgName Private Sub RemovePattern() If rdoWholeDataFrame.Checked Then - If rdoRenameWith.Checked AndAlso rdoReplace.Checked Then - clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) + If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) clsDefaultRFunction.RemoveParameterByName("label") @@ -687,7 +689,19 @@ Public Class dlgName End If End Sub + Private Sub AddTypeParm() + If rdoLabels.Checked Then + clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_labels" & Chr(34), iPosition:=1) + + ElseIf rdoRenameWith.Checked Then + clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) + Else + + End If + End Sub + Private Sub ucrInputEdit_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputEdit.ControlValueChanged, ucrInputBy.ControlValueChanged, ucrInputReplace.ControlValueChanged RemovePattern() + AddTypeParm() End Sub End Class From 8e3f2ae80cf1a854fa4f7543e31d37a912af96cc Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 4 Dec 2024 11:23:29 +0000 Subject: [PATCH 03/13] Update data_object_R6.R --- 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 31bc20285a..66b9678ae4 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1019,7 +1019,7 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne new_metadata <- curr_metadata |> dplyr::mutate( dplyr::across( - {{ .cols }}, + Name, ~ .fn(., ...) ) ) From 622805ac157c5dfb73c0275b2f1e2dc883a507f9 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 4 Dec 2024 11:36:52 +0000 Subject: [PATCH 04/13] Update data_object_R6.R --- instat/static/InstatObject/R/data_object_R6.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 66b9678ae4..9d148f4e61 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -1014,16 +1014,20 @@ DataSheet$set("public", "rename_column_in_data", function(curr_col_name = "", ne } else if (type == "rename_labels"){ # to rename column labels. Here, instead of renaming a column name, we're giving new values in a column. curr_metadata <- self$get_variables_metadata() - curr_col_names <- names(curr_data) - + curr_col_names <- names(curr_data %>% dplyr::select(.cols)) + + # create a new data frame containing the changes - but only apply to those that we actually plan to change for efficiency. new_metadata <- curr_metadata |> + dplyr::filter(Name %in% curr_col_names) %>% dplyr::mutate( dplyr::across( - Name, + label, ~ .fn(., ...) ) ) + if(self$column_selection_applied()) self$remove_current_column_selection() + # apply the changes new_label_names <- new_metadata[!("Name" %in% curr_col_names)]$label for (i in seq_along(new_label_names)) { self$append_to_variables_metadata(curr_col_names[i], property = "label", new_val = new_label_names[i]) From f4c86e9a5e2bc4cae5fe0f91d492e99deb24f2a6 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Wed, 4 Dec 2024 14:41:13 +0300 Subject: [PATCH 05/13] changes --- instat/dlgName.vb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index b345413a36..179e8a74dd 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -80,11 +80,17 @@ Public Class dlgName ucrInputVariableLabel.SetParameter(New RParameter("label", 3)) ucrPnlOptions.SetParameter(New RParameter("type", 4)) - ucrPnlOptions.AddRadioButton(rdoSingle, Chr(34) & "single" & Chr(34)) - ucrPnlOptions.AddRadioButton(rdoMultiple, Chr(34) & "multiple" & Chr(34)) - ucrPnlOptions.AddRadioButton(rdoRenameWith, Chr(34) & "rename_with" & Chr(34)) - ucrPnlOptions.AddRadioButton(rdoLabels, Chr(34) & "labels_with" & Chr(34)) - ucrPnlOptions.SetRDefault(Chr(34) & "single" & Chr(34)) + ucrPnlOptions.AddRadioButton(rdoSingle) + ucrPnlOptions.AddRadioButton(rdoMultiple) + ucrPnlOptions.AddRadioButton(rdoRenameWith) + ucrPnlOptions.AddRadioButton(rdoLabels) + ucrPnlOptions.AddParameterValuesCondition(rdoSingle, "name", "single") + ucrPnlOptions.AddParameterValuesCondition(rdoMultiple, "name", "multiple") + ucrPnlOptions.AddParameterValuesCondition(rdoRenameWith, "name", "rename") + ucrPnlOptions.AddParameterValuesCondition(rdoLabels, "name", "labels") + + + 'ucrPnlOptions.SetRDefault(Chr(34) & "single" & Chr(34)) ucrNudAbbreviate.SetParameter(New RParameter("minlength", 10)) ucrNudAbbreviate.SetMinMax(Integer.MinValue, Integer.MaxValue) @@ -183,6 +189,7 @@ Public Class dlgName clsDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsDummyFunction.AddParameter("checked", "whole", iPosition:=1) + clsDummyFunction.AddParameter("name", "single", iPosition:=2) clsDefaultRFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data") clsDefaultRFunction.AddParameter("type", Chr(34) & "single" & Chr(34), iPosition:=4) @@ -223,12 +230,12 @@ Public Class dlgName ucrPnlCase.SetRCode(clsDefaultRFunction, bReset) ucrInputReplace.SetRCode(clsDefaultRFunction, bReset) ucrChkIncludeVariable.SetRCode(clsDummyFunction, bReset) + ucrPnlSelectData.SetRCode(clsDummyFunction, bReset) + ucrPnlOptions.SetRCode(clsDummyFunction, bReset) End If ucrInputCase.SetRCode(clsDefaultRFunction, bReset) ucrNudAbbreviate.SetRCode(clsDefaultRFunction, bReset) - ucrPnlOptions.SetRCode(clsDefaultRFunction, bReset) ucrInputBy.SetRCode(clsDefaultRFunction, bReset) - ucrPnlSelectData.SetRCode(clsDummyFunction, bReset) End Sub Private Sub TestOKEnabled() @@ -584,8 +591,13 @@ Public Class dlgName End If End If End If - ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) - ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) + + ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse + (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) OrElse + (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) + + 'ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) + 'ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) ucrSelectVariables.btnAdd.Visible = ucrSelectVariables.lstAvailableVariable.Visible ucrSelectVariables.btnDataOptions.Visible = ucrSelectVariables.lstAvailableVariable.Visible UpdateGrid() From 088d3c1b3d3edda34c37448814a84c744aec165f Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Wed, 4 Dec 2024 16:09:40 +0300 Subject: [PATCH 06/13] changes to the code --- instat/dlgName.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 179e8a74dd..e7f0049245 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -189,7 +189,8 @@ Public Class dlgName clsDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsDummyFunction.AddParameter("checked", "whole", iPosition:=1) - clsDummyFunction.AddParameter("name", "single", iPosition:=2) + clsDummyFunction.AddParameter("name", "single", iPosition:=1) + clsDefaultRFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data") clsDefaultRFunction.AddParameter("type", Chr(34) & "single" & Chr(34), iPosition:=4) From fc4a9ad115b5473acd046f0f73ccf52272c3cfc4 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Fri, 6 Dec 2024 10:55:41 +0300 Subject: [PATCH 07/13] changes to the code --- instat/dlgName.vb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index e7f0049245..acaf499757 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -597,8 +597,6 @@ Public Class dlgName (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) OrElse (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) - 'ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoRenameWith.Checked AndAlso rdoSelectedColumn.Checked) - 'ucrSelectVariables.lstAvailableVariable.Visible = rdoSingle.Checked OrElse (rdoLabels.Checked AndAlso rdoSelectedColumn.Checked) ucrSelectVariables.btnAdd.Visible = ucrSelectVariables.lstAvailableVariable.Visible ucrSelectVariables.btnDataOptions.Visible = ucrSelectVariables.lstAvailableVariable.Visible UpdateGrid() @@ -708,8 +706,13 @@ Public Class dlgName ElseIf rdoRenameWith.Checked Then clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_with" & Chr(34), iPosition:=1) - Else + ElseIf rdoMultiple.Checked Then + clsDefaultRFunction.AddParameter("type", Chr(34) & "multiple" & Chr(34), iPosition:=1) + + ElseIf rdoSingle.Checked Then + + clsDefaultRFunction.AddParameter("type", Chr(34) & "single" & Chr(34), iPosition:=1) End If End Sub From 4f091a211674edd24f59db1494217daf3e67424e Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Wed, 11 Dec 2024 11:58:02 +0300 Subject: [PATCH 08/13] changes to the code --- instat/dlgName.Designer.vb | 24 +++++++++++++ instat/dlgName.vb | 72 +++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/instat/dlgName.Designer.vb b/instat/dlgName.Designer.vb index 222e51d490..cf7070ee6c 100644 --- a/instat/dlgName.Designer.vb +++ b/instat/dlgName.Designer.vb @@ -72,6 +72,8 @@ Partial Class dlgName Me.ucrReceiverColumns = New instat.ucrReceiverMultiple() Me.ucrPnlSelectData = New instat.UcrPanel() Me.rdoLabels = New System.Windows.Forms.RadioButton() + Me.cmdAddkeyboard = New System.Windows.Forms.Button() + Me.ucrChkIncludeRegularExpressions = New instat.ucrCheck() Me.grpOptions.SuspendLayout() Me.SuspendLayout() ' @@ -475,6 +477,24 @@ Partial Class dlgName Me.rdoLabels.TextAlign = System.Drawing.ContentAlignment.MiddleCenter Me.rdoLabels.UseVisualStyleBackColor = False ' + 'cmdAddkeyboard + ' + Me.cmdAddkeyboard.Location = New System.Drawing.Point(315, 315) + Me.cmdAddkeyboard.Name = "cmdAddkeyboard" + Me.cmdAddkeyboard.Size = New System.Drawing.Size(100, 23) + Me.cmdAddkeyboard.TabIndex = 35 + Me.cmdAddkeyboard.Text = "Add Keyboard" + Me.cmdAddkeyboard.UseVisualStyleBackColor = True + ' + 'ucrChkIncludeRegularExpressions + ' + Me.ucrChkIncludeRegularExpressions.AutoSize = True + Me.ucrChkIncludeRegularExpressions.Checked = False + Me.ucrChkIncludeRegularExpressions.Location = New System.Drawing.Point(71, 316) + Me.ucrChkIncludeRegularExpressions.Name = "ucrChkIncludeRegularExpressions" + Me.ucrChkIncludeRegularExpressions.Size = New System.Drawing.Size(239, 23) + Me.ucrChkIncludeRegularExpressions.TabIndex = 34 + ' 'dlgName ' Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!) @@ -502,6 +522,8 @@ Partial Class dlgName Me.Controls.Add(Me.rdoSelectedColumn) Me.Controls.Add(Me.rdoWholeDataFrame) Me.Controls.Add(Me.ucrPnlSelectData) + Me.Controls.Add(Me.cmdAddkeyboard) + Me.Controls.Add(Me.ucrChkIncludeRegularExpressions) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False @@ -549,4 +571,6 @@ Partial Class dlgName Friend WithEvents rdoWholeDataFrame As RadioButton Friend WithEvents ucrPnlSelectData As UcrPanel Friend WithEvents rdoLabels As RadioButton + Friend WithEvents cmdAddkeyboard As Button + Friend WithEvents ucrChkIncludeRegularExpressions As ucrCheck End Class diff --git a/instat/dlgName.vb b/instat/dlgName.vb index acaf499757..883ffc38a8 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -30,7 +30,7 @@ Public Class dlgName Private clsNewColNameDataframeFunction As New RFunction Private clsNewLabelDataframeFunction As New RFunction Private clsDummyFunction As New RFunction - Private clsStartwithFunction, clsEndswithFunction, clsMatchesFunction, clsContainsFunction As New RFunction + Private clsStartwithFunction, clsRegexFunction, clsEndswithFunction, clsMatchesFunction, clsContainsFunction As New RFunction Private WithEvents grdCurrentWorkSheet As Worksheet Private dctRowsNewNameChanged As New Dictionary(Of Integer, String) Private dctRowsNewLabelChanged As New Dictionary(Of Integer, String) @@ -147,12 +147,17 @@ Public Class dlgName ucrInputReplace.SetParameter(New RParameter("pattern", 2)) ucrInputReplace.SetLinkedDisplayControl(lblReplace) + ucrChkIncludeRegularExpressions.SetText("Include Regular Expressions") + + ucrChkIncludeRegularExpressions.SetParameter(New RParameter("check", 0)) + ucrChkIncludeRegularExpressions.SetValuesCheckedAndUnchecked(True, False) + ucrPnlOptions.AddToLinkedControls({ucrReceiverName, ucrInputNewName, ucrInputVariableLabel}, {rdoSingle}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlOptions.AddToLinkedControls(ucrChkIncludeVariable, {rdoMultiple}, bNewLinkedHideIfParameterMissing:=True) ucrPnlOptions.AddToLinkedControls({ucrPnlCase, ucrPnlSelectData}, {rdoRenameWith, rdoLabels}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputCase, {rdoMakeCleanNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Snake") ucrPnlCase.AddToLinkedControls(ucrNudAbbreviate, {rdoAbbreviate}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="8") - ucrPnlCase.AddToLinkedControls(ucrInputReplace, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlCase.AddToLinkedControls({ucrInputReplace, ucrChkIncludeRegularExpressions}, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputBy, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="") ucrPnlCase.AddToLinkedControls(ucrInputEdit, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Starts With") ucrPnlSelectData.AddToLinkedControls(ucrReceiverColumns, {rdoSelectedColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) @@ -178,6 +183,7 @@ Public Class dlgName clsEndswithFunction = New RFunction clsMatchesFunction = New RFunction clsContainsFunction = New RFunction + clsRegexFunction = New RFunction ucrSelectVariables.Reset() dctRowsNewNameChanged.Clear() @@ -189,8 +195,8 @@ Public Class dlgName clsDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsDummyFunction.AddParameter("checked", "whole", iPosition:=1) - clsDummyFunction.AddParameter("name", "single", iPosition:=1) - + clsDummyFunction.AddParameter("name", "single", iPosition:=2) + clsDummyFunction.AddParameter("check", False, iPosition:=3) clsDefaultRFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data") clsDefaultRFunction.AddParameter("type", Chr(34) & "single" & Chr(34), iPosition:=4) @@ -214,6 +220,12 @@ Public Class dlgName clsStartwithFunction.SetRCommand("starts_with") clsStartwithFunction.AddParameter("match", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=0) + clsRegexFunction.SetPackageName("stringr") + clsRegexFunction.SetRCommand("regex") + clsRegexFunction.AddParameter("ignore_case", "FALSE", bIncludeArgumentName:=False, iPosition:=3) + clsRegexFunction.AddParameter("multiline", "FALSE", iPosition:=4) + clsRegexFunction.AddParameter("comments", "FALSE", iPosition:=5) + ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultRFunction) End Sub @@ -227,6 +239,7 @@ Public Class dlgName ucrReceiverName.SetRCode(clsDefaultRFunction, bReset) ucrInputNewName.SetRCode(clsDefaultRFunction, bReset) ucrInputVariableLabel.SetRCode(clsDefaultRFunction, bReset) + ucrChkIncludeRegularExpressions.SetRCode(clsDummyFunction, bReset) If bReset Then ucrPnlCase.SetRCode(clsDefaultRFunction, bReset) ucrInputReplace.SetRCode(clsDefaultRFunction, bReset) @@ -641,10 +654,6 @@ Public Class dlgName MakeLabelColumnVisible() End Sub - Private Sub cmdAddkeyboard_Click(sender As Object, e As EventArgs) - sdgConstructRegexExpression.ShowDialog() - End Sub - Private Sub ucrSelectVariables_DataFrameChanged() Handles ucrSelectVariables.DataFrameChanged RemoveLabelsParams() UpdateGrid() @@ -673,23 +682,34 @@ Public Class dlgName End Sub Private Sub RemovePattern() + cmdAddkeyboard.Visible = False + If rdoWholeDataFrame.Checked Then If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) clsDefaultRFunction.RemoveParameterByName("label") clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) - Select Case ucrInputEdit.GetText - Case "Starts With" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) - Case "Ends With" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) - Case "Matches" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) - Case "Contains" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) - End Select + If ucrChkIncludeRegularExpressions.Checked Then + cmdAddkeyboard.Visible = True + clsDefaultRFunction.RemoveParameterByName(".cols") + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) + clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) + clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) + Else + clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + cmdAddkeyboard.Visible = False + Select Case ucrInputEdit.GetText + Case "Starts With" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) + Case "Ends With" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) + Case "Matches" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + Case "Contains" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + End Select + End If Else clsDefaultRFunction.RemoveParameterByName("pattern") clsDefaultRFunction.RemoveParameterByName("replacement") @@ -697,7 +717,9 @@ Public Class dlgName End If Else clsDefaultRFunction.AddParameter(".cols", ucrReceiverColumns.GetVariableNames, iPosition:=3) + clsDefaultRFunction.RemoveParameterByName("pattern") End If + End Sub Private Sub AddTypeParm() @@ -720,4 +742,14 @@ Public Class dlgName RemovePattern() AddTypeParm() End Sub + + Private Sub cmdAddkeyboard_Click(sender As Object, e As EventArgs) Handles cmdAddkeyboard.Click + sdgConstructRegexExpression.ShowDialog() + ucrInputReplace.SetName(sdgConstructRegexExpression.ucrReceiverForRegex.GetText()) + End Sub + + Private Sub ucrChkIncludeRegularExpressions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkIncludeRegularExpressions.ControlValueChanged + RemovePattern() + cmdAddkeyboard.Visible = If(ucrChkIncludeRegularExpressions.Checked, True, False) + End Sub End Class From 8db6d3c8b24e3ad090350ba1d5d1c1b0c5261783 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Wed, 11 Dec 2024 12:29:14 +0300 Subject: [PATCH 09/13] changes --- instat/dlgName.vb | 3 --- 1 file changed, 3 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 883ffc38a8..d419668a2a 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -89,9 +89,6 @@ Public Class dlgName ucrPnlOptions.AddParameterValuesCondition(rdoRenameWith, "name", "rename") ucrPnlOptions.AddParameterValuesCondition(rdoLabels, "name", "labels") - - 'ucrPnlOptions.SetRDefault(Chr(34) & "single" & Chr(34)) - ucrNudAbbreviate.SetParameter(New RParameter("minlength", 10)) ucrNudAbbreviate.SetMinMax(Integer.MinValue, Integer.MaxValue) From 5337369223dcb36bcd1b38b934eb8ad6274d9134 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Thu, 12 Dec 2024 11:54:03 +0300 Subject: [PATCH 10/13] changes --- instat/dlgName.vb | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index d419668a2a..ee1154a7ae 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -135,6 +135,8 @@ Public Class dlgName dctReplace.Add("Ends With", Chr(34) & "ends_with" & Chr(34)) dctReplace.Add("Matches", Chr(34) & "matches" & Chr(34)) dctReplace.Add("Contains", Chr(34) & "contains" & Chr(34)) + dctReplace.Add("Matches All", Chr(34) & "contains" & Chr(34)) + dctReplace.Add("Contains All", Chr(34) & "contains" & Chr(34)) ucrInputEdit.SetDropDownStyleAsNonEditable() ucrInputEdit.SetItems(dctReplace) @@ -154,11 +156,13 @@ Public Class dlgName ucrPnlOptions.AddToLinkedControls({ucrPnlCase, ucrPnlSelectData}, {rdoRenameWith, rdoLabels}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputCase, {rdoMakeCleanNames}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Snake") ucrPnlCase.AddToLinkedControls(ucrNudAbbreviate, {rdoAbbreviate}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="8") - ucrPnlCase.AddToLinkedControls({ucrInputReplace, ucrChkIncludeRegularExpressions}, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlCase.AddToLinkedControls(ucrInputReplace, {rdoReplace}, bNewLinkedHideIfParameterMissing:=True) ucrPnlCase.AddToLinkedControls(ucrInputBy, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="") ucrPnlCase.AddToLinkedControls(ucrInputEdit, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Starts With") ucrPnlSelectData.AddToLinkedControls(ucrReceiverColumns, {rdoSelectedColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrInputReplace.AddToLinkedControls(ucrChkIncludeRegularExpressions, {"Matches All", "Matches"}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrReceiverName.SetLinkedDisplayControl(lblCurrentName) ucrInputNewName.SetLinkedDisplayControl(lblName) ucrInputVariableLabel.SetLinkedDisplayControl(lblVariableLabel) @@ -694,17 +698,26 @@ Public Class dlgName clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) Else clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) cmdAddkeyboard.Visible = False Select Case ucrInputEdit.GetText Case "Starts With" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) Case "Ends With" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) Case "Matches" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) Case "Contains" clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + Case "Matches All" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) + Case "Contains All" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) End Select End If Else @@ -719,6 +732,22 @@ Public Class dlgName End Sub + Private Sub AddRegexPar() + + If ucrChkIncludeRegularExpressions.Checked Then + Select Case ucrInputEdit.GetText + Case "Contains All" + + Case "Contains" + + Case Else + End Select + Else + + End If + + End Sub + Private Sub AddTypeParm() If rdoLabels.Checked Then clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_labels" & Chr(34), iPosition:=1) From db934a05299f53bcd57a24ddb8ab6feebb81a268 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Thu, 12 Dec 2024 13:22:21 +0300 Subject: [PATCH 11/13] changes to the code --- instat/dlgName.vb | 112 ++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 49 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index ee1154a7ae..4840ee3f02 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -161,8 +161,6 @@ Public Class dlgName ucrPnlCase.AddToLinkedControls(ucrInputEdit, {rdoReplace}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:="Starts With") ucrPnlSelectData.AddToLinkedControls(ucrReceiverColumns, {rdoSelectedColumn}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrInputReplace.AddToLinkedControls(ucrChkIncludeRegularExpressions, {"Matches All", "Matches"}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrReceiverName.SetLinkedDisplayControl(lblCurrentName) ucrInputNewName.SetLinkedDisplayControl(lblName) ucrInputVariableLabel.SetLinkedDisplayControl(lblVariableLabel) @@ -618,6 +616,8 @@ Public Class dlgName DialogueSize() RemovePattern() AddTypeParm() + AddRegexPar() + SetRegexControlVisibility() End Sub Private Sub DialogueSize() @@ -683,69 +683,64 @@ Public Class dlgName End Sub Private Sub RemovePattern() - cmdAddkeyboard.Visible = False - If rdoWholeDataFrame.Checked Then If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then clsDefaultRFunction.RemoveParameterByName("label") clsDefaultRFunction.AddParameter("replacement", Chr(34) & ucrInputBy.GetText() & Chr(34), iPosition:=5) - If ucrChkIncludeRegularExpressions.Checked Then - cmdAddkeyboard.Visible = True - clsDefaultRFunction.RemoveParameterByName(".cols") - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) - clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) - clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) - Else - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - cmdAddkeyboard.Visible = False - Select Case ucrInputEdit.GetText - Case "Starts With" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - Case "Ends With" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - Case "Matches" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - Case "Contains" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) - Case "Matches All" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) - Case "Contains All" - clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) - clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) - End Select - End If + Select Case ucrInputEdit.GetText + Case "Starts With" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsStartwithFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + Case "Ends With" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsEndswithFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + Case "Matches" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + Case "Contains" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace", iPosition:=2) + Case "Matches All" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsMatchesFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) + Case "Contains All" + clsDefaultRFunction.AddParameter(".cols", clsRFunctionParameter:=clsContainsFunction, iPosition:=3) + clsDefaultRFunction.AddParameter(".fn", "stringr::str_replace_all", iPosition:=2) + End Select Else - clsDefaultRFunction.RemoveParameterByName("pattern") clsDefaultRFunction.RemoveParameterByName("replacement") clsDefaultRFunction.RemoveParameterByName(".cols") End If Else clsDefaultRFunction.AddParameter(".cols", ucrReceiverColumns.GetVariableNames, iPosition:=3) - clsDefaultRFunction.RemoveParameterByName("pattern") End If - End Sub Private Sub AddRegexPar() - - If ucrChkIncludeRegularExpressions.Checked Then - Select Case ucrInputEdit.GetText - Case "Contains All" - - Case "Contains" - - Case Else - End Select + If rdoWholeDataFrame.Checked Then + If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then + If ucrChkIncludeRegularExpressions.Checked Then + Select Case ucrInputEdit.GetText + Case "Matches All" + clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) + clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) + Case "Matches" + cmdAddkeyboard.Visible = True + clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) + clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) + Case Else + clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) + End Select + Else + clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) + End If + Else + clsDefaultRFunction.RemoveParameterByName("pattern") + End If Else - + clsDefaultRFunction.RemoveParameterByName("pattern") End If - End Sub Private Sub AddTypeParm() @@ -767,6 +762,8 @@ Public Class dlgName Private Sub ucrInputEdit_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputEdit.ControlValueChanged, ucrInputBy.ControlValueChanged, ucrInputReplace.ControlValueChanged RemovePattern() AddTypeParm() + AddRegexPar() + SetRegexControlVisibility() End Sub Private Sub cmdAddkeyboard_Click(sender As Object, e As EventArgs) Handles cmdAddkeyboard.Click @@ -776,6 +773,23 @@ Public Class dlgName Private Sub ucrChkIncludeRegularExpressions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkIncludeRegularExpressions.ControlValueChanged RemovePattern() - cmdAddkeyboard.Visible = If(ucrChkIncludeRegularExpressions.Checked, True, False) + AddRegexPar() + SetRegexControlVisibility() + End Sub + + Private Sub SetRegexControlVisibility() + ucrChkIncludeRegularExpressions.Visible = False + cmdAddkeyboard.Visible = False + + If rdoWholeDataFrame.Checked Then + If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then + Select Case ucrInputEdit.GetText + Case "Matches All", "Matches" + cmdAddkeyboard.Visible = If(ucrChkIncludeRegularExpressions.Checked, True, False) + ucrChkIncludeRegularExpressions.Visible = True + End Select + End If + End If End Sub + End Class From f9405dfc771e574aff289bfae46b3f3b2d8dbb88 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Thu, 12 Dec 2024 16:58:18 +0300 Subject: [PATCH 12/13] changes to the code --- instat/dlgName.vb | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 4840ee3f02..6d8c83a4ac 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -30,6 +30,7 @@ Public Class dlgName Private clsNewColNameDataframeFunction As New RFunction Private clsNewLabelDataframeFunction As New RFunction Private clsDummyFunction As New RFunction + Private clsFixedFunction As New RFunction Private clsStartwithFunction, clsRegexFunction, clsEndswithFunction, clsMatchesFunction, clsContainsFunction As New RFunction Private WithEvents grdCurrentWorkSheet As Worksheet Private dctRowsNewNameChanged As New Dictionary(Of Integer, String) @@ -183,6 +184,7 @@ Public Class dlgName clsMatchesFunction = New RFunction clsContainsFunction = New RFunction clsRegexFunction = New RFunction + clsFixedFunction = New RFunction ucrSelectVariables.Reset() dctRowsNewNameChanged.Clear() @@ -219,6 +221,9 @@ Public Class dlgName clsStartwithFunction.SetRCommand("starts_with") clsStartwithFunction.AddParameter("match", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=0) + clsFixedFunction.SetPackageName("stringr") + clsFixedFunction.SetRCommand("fixed") + clsRegexFunction.SetPackageName("stringr") clsRegexFunction.SetRCommand("regex") clsRegexFunction.AddParameter("ignore_case", "FALSE", bIncludeArgumentName:=False, iPosition:=3) @@ -682,6 +687,10 @@ Public Class dlgName End If End Sub + Private Function IsRegexApplicable() As Boolean + Return (ucrInputEdit.GetText = "Matches All" OrElse ucrInputEdit.GetText = "Matches") + End Function + Private Sub RemovePattern() If rdoWholeDataFrame.Checked Then If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then @@ -718,25 +727,19 @@ Public Class dlgName End Sub Private Sub AddRegexPar() - If rdoWholeDataFrame.Checked Then - If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then - If ucrChkIncludeRegularExpressions.Checked Then - Select Case ucrInputEdit.GetText - Case "Matches All" - clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) - clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) - Case "Matches" - cmdAddkeyboard.Visible = True - clsRegexFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText & Chr(34), bIncludeArgumentName:=False, iPosition:=1) - clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) - Case Else - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - End Select - Else - clsDefaultRFunction.AddParameter("pattern", Chr(34) & ucrInputReplace.GetText() & Chr(34), iPosition:=4) - End If + If rdoWholeDataFrame.Checked AndAlso (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then + Dim patternValue As String = Chr(34) & ucrInputReplace.GetText & Chr(34) + If ucrChkIncludeRegularExpressions.Checked AndAlso IsRegexApplicable() Then + clsRegexFunction.AddParameter("pattern", patternValue, bIncludeArgumentName:=False, iPosition:=1) + clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) Else - clsDefaultRFunction.RemoveParameterByName("pattern") + Select Case ucrInputEdit.GetText + Case "Contains", "Contains All" + clsFixedFunction.AddParameter("pattern", patternValue, bIncludeArgumentName:=False, iPosition:=1) + clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsFixedFunction, bIncludeArgumentName:=False, iPosition:=4) + Case Else + clsDefaultRFunction.AddParameter("pattern", patternValue, iPosition:=4) + End Select End If Else clsDefaultRFunction.RemoveParameterByName("pattern") From 309931d1fa9039184a811f0e10655eb25547f216 Mon Sep 17 00:00:00 2001 From: KWAMBAI VITALIS Date: Fri, 13 Dec 2024 10:15:48 +0300 Subject: [PATCH 13/13] changes to the code --- instat/dlgName.vb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/instat/dlgName.vb b/instat/dlgName.vb index 6d8c83a4ac..0be8141d4a 100644 --- a/instat/dlgName.vb +++ b/instat/dlgName.vb @@ -620,8 +620,8 @@ Public Class dlgName RemoveParameters() DialogueSize() RemovePattern() - AddTypeParm() - AddRegexPar() + ConfigureTypeParameter() + ConfigurePatternParameter() SetRegexControlVisibility() End Sub @@ -687,10 +687,6 @@ Public Class dlgName End If End Sub - Private Function IsRegexApplicable() As Boolean - Return (ucrInputEdit.GetText = "Matches All" OrElse ucrInputEdit.GetText = "Matches") - End Function - Private Sub RemovePattern() If rdoWholeDataFrame.Checked Then If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then @@ -726,10 +722,11 @@ Public Class dlgName End If End Sub - Private Sub AddRegexPar() + Private Sub ConfigurePatternParameter() If rdoWholeDataFrame.Checked AndAlso (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then Dim patternValue As String = Chr(34) & ucrInputReplace.GetText & Chr(34) - If ucrChkIncludeRegularExpressions.Checked AndAlso IsRegexApplicable() Then + If ucrChkIncludeRegularExpressions.Checked AndAlso (ucrInputEdit.GetText = "Matches All" OrElse ucrInputEdit.GetText = "Matches") Then + clsRegexFunction.AddParameter("pattern", patternValue, bIncludeArgumentName:=False, iPosition:=1) clsDefaultRFunction.AddParameter("pattern", clsRFunctionParameter:=clsRegexFunction, bIncludeArgumentName:=False, iPosition:=4) Else @@ -746,7 +743,7 @@ Public Class dlgName End If End Sub - Private Sub AddTypeParm() + Private Sub ConfigureTypeParameter() If rdoLabels.Checked Then clsDefaultRFunction.AddParameter("type", Chr(34) & "rename_labels" & Chr(34), iPosition:=1) @@ -764,8 +761,8 @@ Public Class dlgName Private Sub ucrInputEdit_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputEdit.ControlValueChanged, ucrInputBy.ControlValueChanged, ucrInputReplace.ControlValueChanged RemovePattern() - AddTypeParm() - AddRegexPar() + ConfigureTypeParameter() + ConfigurePatternParameter() SetRegexControlVisibility() End Sub @@ -776,7 +773,7 @@ Public Class dlgName Private Sub ucrChkIncludeRegularExpressions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkIncludeRegularExpressions.ControlValueChanged RemovePattern() - AddRegexPar() + ConfigurePatternParameter() SetRegexControlVisibility() End Sub @@ -784,15 +781,13 @@ Public Class dlgName ucrChkIncludeRegularExpressions.Visible = False cmdAddkeyboard.Visible = False - If rdoWholeDataFrame.Checked Then - If (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso rdoReplace.Checked Then - Select Case ucrInputEdit.GetText - Case "Matches All", "Matches" - cmdAddkeyboard.Visible = If(ucrChkIncludeRegularExpressions.Checked, True, False) - ucrChkIncludeRegularExpressions.Visible = True - End Select - End If + If rdoWholeDataFrame.Checked AndAlso + (rdoRenameWith.Checked OrElse rdoLabels.Checked) AndAlso + rdoReplace.Checked AndAlso + (ucrInputEdit.GetText = "Matches All" OrElse ucrInputEdit.GetText = "Matches") Then + + ucrChkIncludeRegularExpressions.Visible = True + cmdAddkeyboard.Visible = ucrChkIncludeRegularExpressions.Checked End If End Sub - End Class