From 876a580a5012ca5ef4897cc9fb8224919410b07b Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:47:21 +0100 Subject: [PATCH 01/30] Adding the loops function to the transform dialog --- instat/dlgTransform.Designer.vb | 55 ++++++++++++++++++++++++++++++++- instat/dlgTransform.vb | 52 ++++++++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/instat/dlgTransform.Designer.vb b/instat/dlgTransform.Designer.vb index c3df268c5ff..b0115e8bf16 100644 --- a/instat/dlgTransform.Designer.vb +++ b/instat/dlgTransform.Designer.vb @@ -108,6 +108,10 @@ Partial Class dlgTransform Me.ucrSelectorForRank = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrChkMissingLast = New instat.ucrCheck() Me.ucrChkDecreasing = New instat.ucrCheck() + Me.ucrPnlColumnSelectOptions = New instat.UcrPanel() + Me.rdoSingle = New System.Windows.Forms.RadioButton() + Me.rdoMultiple = New System.Windows.Forms.RadioButton() + Me.ucrNewColName = New instat.ucrSave() Me.grpTies.SuspendLayout() Me.grpMissingValues.SuspendLayout() Me.grpNumericOptions.SuspendLayout() @@ -894,7 +898,7 @@ Partial Class dlgTransform Me.ucrBase.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink Me.ucrBase.Location = New System.Drawing.Point(10, 392) Me.ucrBase.Name = "ucrBase" - Me.ucrBase.Size = New System.Drawing.Size(405, 52) + Me.ucrBase.Size = New System.Drawing.Size(408, 52) Me.ucrBase.TabIndex = 16 ' 'ucrSelectorForRank @@ -927,12 +931,57 @@ Partial Class dlgTransform Me.ucrChkDecreasing.Size = New System.Drawing.Size(100, 23) Me.ucrChkDecreasing.TabIndex = 12 ' + 'ucrPnlColumnSelectOptions + ' + Me.ucrPnlColumnSelectOptions.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrPnlColumnSelectOptions.Location = New System.Drawing.Point(237, 52) + Me.ucrPnlColumnSelectOptions.Name = "ucrPnlColumnSelectOptions" + Me.ucrPnlColumnSelectOptions.Size = New System.Drawing.Size(185, 29) + Me.ucrPnlColumnSelectOptions.TabIndex = 37 + ' + 'rdoSingle + ' + Me.rdoSingle.AutoSize = True + Me.rdoSingle.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.rdoSingle.Location = New System.Drawing.Point(255, 59) + Me.rdoSingle.Name = "rdoSingle" + Me.rdoSingle.Size = New System.Drawing.Size(54, 17) + Me.rdoSingle.TabIndex = 37 + Me.rdoSingle.TabStop = True + Me.rdoSingle.Text = "Single" + Me.rdoSingle.UseVisualStyleBackColor = True + ' + 'rdoMultiple + ' + Me.rdoMultiple.AutoSize = True + Me.rdoMultiple.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.rdoMultiple.Location = New System.Drawing.Point(321, 60) + Me.rdoMultiple.Name = "rdoMultiple" + Me.rdoMultiple.Size = New System.Drawing.Size(61, 17) + Me.rdoMultiple.TabIndex = 68 + Me.rdoMultiple.TabStop = True + Me.rdoMultiple.Text = "Multiple" + Me.rdoMultiple.UseVisualStyleBackColor = True + ' + 'ucrNewColName + ' + Me.ucrNewColName.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrNewColName.Location = New System.Drawing.Point(10, 368) + Me.ucrNewColName.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5) + Me.ucrNewColName.Name = "ucrNewColName" + Me.ucrNewColName.Size = New System.Drawing.Size(331, 22) + Me.ucrNewColName.TabIndex = 69 + ' 'dlgTransform ' 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(440, 445) + Me.Controls.Add(Me.ucrNewColName) + Me.Controls.Add(Me.rdoMultiple) + Me.Controls.Add(Me.rdoSingle) + Me.Controls.Add(Me.ucrPnlColumnSelectOptions) Me.Controls.Add(Me.grpNumericOptions) Me.Controls.Add(Me.grpNonNegative) Me.Controls.Add(Me.grpTies) @@ -1050,4 +1099,8 @@ Partial Class dlgTransform Friend WithEvents ucrInputLogicOperations As ucrInputComboBox Friend WithEvents rdoLogical As RadioButton Friend WithEvents ucrPnlNumericOptions As UcrPanel + Friend WithEvents rdoMultiple As RadioButton + Friend WithEvents rdoSingle As RadioButton + Friend WithEvents ucrPnlColumnSelectOptions As UcrPanel + Friend WithEvents ucrNewColName As ucrSave End Class diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index e81ca5dccb9..84cba455a22 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -49,6 +49,7 @@ Public Class dlgTransform Private clsConstantDummyFunction As New RFunction Private clsNumericDummyFunction As New RFunction Private clsNonNegativeDummyFunction As New RFunction + Private clsGetColSelectionNamesFunction As New RFunction Private clsPreviewTextFunction As New RCodeStructure Private clsBooleanOperator As New ROperator Private clsIsNAFunction As New RFunction @@ -77,17 +78,22 @@ Public Class dlgTransform Dim dctAddValues As New Dictionary(Of String, String) Dim dctPowerValues As New Dictionary(Of String, String) + ucrPnlTransformOptions.AddRadioButton(rdoRank) ucrPnlTransformOptions.AddRadioButton(rdoNumeric) ucrPnlTransformOptions.AddRadioButton(rdoSort) ucrPnlTransformOptions.AddRadioButton(rdoNonNegative) ucrPnlTransformOptions.AddRadioButton(rdoScale) + ucrPnlColumnSelectOptions.AddRadioButton(rdoSingle) + ucrPnlColumnSelectOptions.AddRadioButton(rdoMultiple) ucrPnlTransformOptions.AddParameterValuesCondition(rdoRank, "check", "rank") ucrPnlTransformOptions.AddParameterValuesCondition(rdoNumeric, "check", "numeric") ucrPnlTransformOptions.AddParameterValuesCondition(rdoSort, "check", "sort") ucrPnlTransformOptions.AddParameterValuesCondition(rdoNonNegative, "check", "non-negative") ucrPnlTransformOptions.AddParameterValuesCondition(rdoScale, "check", "scale") + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoSingle, "check", "single") + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoMultiple, "check", "multiple") ucrReceiverRank.SetParameter(New RParameter("x", 0)) ucrReceiverRank.Selector = ucrSelectorForRank @@ -147,6 +153,7 @@ Public Class dlgTransform ucrPnlNonNegative.AddParameterValuesCondition(rdoNaturalLog, "check", "log") ucrPnlNonNegative.AddParameterValuesCondition(rdoPower, "check", "power") + ucrPnlColumnSelectOptions.AddToLinkedControls(ucrNewColName, {rdoMultiple}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudSignifDigits, {rdoSignificantDigits}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudRoundOfDigits, {rdoRoundOf}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudLagLeadPosition, {rdoLead}, bNewLinkedHideIfParameterMissing:=True) @@ -289,6 +296,12 @@ Public Class dlgTransform ucrChkPreview.AddParameterValuesCondition(True, "preview", "FALSE") ucrChkPreview.AddParameterValuesCondition(False, "preview", "TRUE") + 'ucrNewColName + ucrNewColName.SetIsComboBox() + ucrNewColName.SetSaveTypeAsColumn() + ucrNewColName.SetDataFrameSelector(ucrSelectorForRank.ucrAvailableDataFrames) + ucrNewColName.SetLabelText("New Column:") + ucrNewColName.setLinkedReceiver(ucrReceiverRank) ucrChkOmitNA.SetText("Omit NA") ucrChkOmitNA.SetParameter(New RParameter("na.rm", 1)) @@ -333,11 +346,17 @@ Public Class dlgTransform clsBooleanOperator = New ROperator clsIsNAFunction = New RFunction clsRemoveLabelsFunction = New RFunction + clsGetColSelectionNamesFunction = New RFunction + ucrSelectorForRank.Reset() ucrReceiverRank.SetMeAsReceiver() ucrSaveNew.Reset() + ucrNewColName.Reset() ucrInputLogicOperations.SetText("==") + rdoSingle.Checked = True + ucrNewColName.Visible = False + rdoMultiple.Checked = ucrNewColName.Visible clsConstantDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsConstantDummyFunction.AddParameter("preview", "TRUE", iPosition:=1) @@ -350,6 +369,8 @@ Public Class dlgTransform clsSortFunction.AddParameter("decreasing", "TRUE", iPosition:=1) clsSortFunction.AddParameter("na.last", "TRUE", iPosition:=2) + clsGetColSelectionNamesFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_selected_column_names") + clsRoundFunction.SetRCommand("round") clsSignifFunction.SetRCommand("signif") @@ -439,6 +460,7 @@ Public Class dlgTransform Private Sub SetRCodeForControls(bReset As Boolean) bResetRCode = False + ucrReceiverRank.AddAdditionalCodeParameterPair(clsSortFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=1) ucrReceiverRank.AddAdditionalCodeParameterPair(clsRoundFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=2) ucrReceiverRank.AddAdditionalCodeParameterPair(clsSignifFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=3) @@ -455,7 +477,9 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinFunction, New RParameter("x", 0), iAdditionalPairNo:=13) ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanOperator, New RParameter("x", 0), iAdditionalPairNo:=14) ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAFunction, New RParameter("x", 0), iAdditionalPairNo:=15) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, New RParameter("x", 0), iAdditionalPairNo:=16) ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) + ucrSelectorForRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, ucrSelectorForRank.GetParameter, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) @@ -496,6 +520,8 @@ Public Class dlgTransform ucrPnlNonNegative.SetRCode(clsNonNegativeDummyFunction, bReset) ucrChkOmitNA.SetRCode(clsMeanFunction, bReset) ucrChkPreview.SetRCode(clsConstantDummyFunction, bReset) + + bResetRCode = True End Sub @@ -512,8 +538,14 @@ Public Class dlgTransform End Sub Private Sub NewDefaultName() - If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then - ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) + If rdoSingle.Checked Then + If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then + ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) + End If + ElseIf rdoMultiple.Checked Then + If (Not ucrNewColName.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then + ucrNewColName.SetName(ucrReceiverRank.GetVariableNames(bWithQuotes:=False) & "_transformed") + End If End If End Sub @@ -524,13 +556,25 @@ Public Class dlgTransform ucrChkEditPreview.Checked = False End Sub - Private Sub ucrPnlTransformOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlTransformOptions.ControlValueChanged, ucrPnlNumericOptions.ControlValueChanged, ucrInputLogicalValues.ControlValueChanged, + Private Sub ucrPnlTransformOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlTransformOptions.ControlValueChanged, ucrPnlNumericOptions.ControlValueChanged, ucrPnlColumnSelectOptions.ControlValueChanged, ucrInputLogicalValues.ControlValueChanged, ucrPnlNonNegative.ControlValueChanged, ucrPnlMissingValues.ControlValueChanged, ucrPnlTies.ControlValueChanged, ucrChkPreview.ControlValueChanged, ucrReceiverRank.ControlValueChanged, ucrNudDiffLag.ControlValueChanged, ucrNudLagLeadPosition.ControlValueChanged, ucrNudLagPosition.ControlValueChanged, ucrNudRoundOfDigits.ControlValueChanged, ucrNudSignifDigits.ControlValueChanged, ucrInputPower.ControlValueChanged, ucrInputMultiply.ControlValueChanged, ucrInputDivide.ControlValueChanged, ucrInputConstant.ControlValueChanged, ucrInputAdd.ControlValueChanged, ucrChkOmitNA.ControlValueChanged, ucrInputLogicOperations.ControlValueChanged, ucrChkAddConstant.ControlValueChanged, ucrChkMissingLast.ControlValueChanged, ucrChkDecreasing.ControlValueChanged, ucrChkDivide.ControlValueChanged, ucrChkAdd.ControlValueChanged, ucrChkMultiply.ControlValueChanged, ucrChkSubtract.ControlValueChanged If bResetRCode Then ucrBase.clsRsyntax.ClearCodes() + If rdoMultiple.Checked Then + clsDummyTransformFunction.AddParameter("check", "select", iPosition:=0) + ucrSelectorForRank.SetItemType("column_selection") + ucrReceiverRank.strSelectorHeading = "Column selections" + ElseIf rdoSingle.Checked Then + clsDummyTransformFunction.AddParameter("check", "variable", iPosition:=0) + ucrReceiverRank.bUseFilteredData = False + ucrReceiverRank.SetParameterIsRFunction() + ucrSelectorForRank.SetItemType("column") + ucrReceiverRank.strSelectorHeading = "Numerics" + + End If If rdoRank.Checked Then clsPreviewTextFunction = clsRankFunction.Clone clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) @@ -722,7 +766,7 @@ Public Class dlgTransform End Sub Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverRank.ControlContentsChanged, ucrSaveNew.ControlContentsChanged, - ucrPnlTransformOptions.ControlContentsChanged, ucrPnlNumericOptions.ControlContentsChanged, ucrPnlNonNegative.ControlContentsChanged, ucrChkDivide.ControlContentsChanged, + ucrPnlTransformOptions.ControlContentsChanged, ucrPnlNumericOptions.ControlContentsChanged, ucrPnlColumnSelectOptions.ControlContentsChanged, ucrPnlNonNegative.ControlContentsChanged, ucrChkDivide.ControlContentsChanged, ucrChkMultiply.ControlContentsChanged, ucrChkSubtract.ControlContentsChanged, ucrChkAdd.ControlContentsChanged, ucrChkPreview.ControlContentsChanged, ucrChkAddConstant.ControlContentsChanged, ucrInputPower.ControlContentsChanged, ucrInputPreview.ControlContentsChanged, ucrInputLogicalValues.ControlContentsChanged, ucrInputLogicOperations.ControlContentsChanged TestOKEnabled() From c6977bd5b8ef5011d6c4adea3bd813b11fe5d6e0 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:13:06 +0100 Subject: [PATCH 02/30] Changing the label names to alternate between column and select --- instat/dlgTransform.vb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 84cba455a22..f85ba0a4c6d 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -567,12 +567,14 @@ Public Class dlgTransform clsDummyTransformFunction.AddParameter("check", "select", iPosition:=0) ucrSelectorForRank.SetItemType("column_selection") ucrReceiverRank.strSelectorHeading = "Column selections" + lblSelectColumns.Text = "Select:" ElseIf rdoSingle.Checked Then clsDummyTransformFunction.AddParameter("check", "variable", iPosition:=0) ucrReceiverRank.bUseFilteredData = False ucrReceiverRank.SetParameterIsRFunction() ucrSelectorForRank.SetItemType("column") ucrReceiverRank.strSelectorHeading = "Numerics" + lblSelectColumns.Text = "Column:" End If If rdoRank.Checked Then From 0fe69456d81f9786e954ec41d8cb9c8cf67b0599 Mon Sep 17 00:00:00 2001 From: Barbra2020 Date: Thu, 14 Mar 2024 17:38:41 +0300 Subject: [PATCH 03/30] changes made --- instat/dlgTransform.vb | 375 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 351 insertions(+), 24 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index f85ba0a4c6d..6fc220edba9 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -20,30 +20,69 @@ Public Class dlgTransform Public bFirstLoad As Boolean = True Private bReset As Boolean = True Private clsRankFunction As New RFunction + Private clsRankColsFunction As New RFunction + Private clsSortFunction As New RFunction + Private clsSortColsFunction As New RFunction + Private clsRoundFunction As New RFunction + Private clsRoundColsFunction As New RFunction + Private clsSignifFunction As New RFunction + Private clsSignifColsFunction As New RFunction + Private clsLagFunction As New RFunction + Private clsLagColsFunction As New RFunction + Private clsLeadFunction As New RFunction + Private clsLeadColsFunction As New RFunction + Private clsDiffFunction As New RFunction + Private clsDiffColsFunction As New RFunction + Private clsConcDiffFunction As New RFunction + Private clsConcDiffColsFunction As New RFunction + Private clsReplicateFunction As New RFunction + Private clsReplicateColsFunction As New RFunction + Private clsMeanFunction As New RFunction + Private clsMeanColsFunction As New RFunction + Private clsStandardDevFunction As New RFunction + Private clsStandardDevColsFunction As New RFunction + Private clsSubtractOperator As New ROperator Private clsDivisionOperator As New ROperator + Private clsDivisionColsOperator As New ROperator + Private clsSquarerootFunction As New RFunction + Private clsSquarerootColsFunction As New RFunction + Private clsAddConstantOperator As New ROperator Private clsNaturalLogFunction As New RFunction + Private clsNaturalLogColsFunction As New RFunction + Private clsLogBase10Function As New RFunction + Private clsLogBase10ColsFunction As New RFunction + Private clsRemoveLabelsFunction As New RFunction Private clsPowerOperator As New ROperator + Private clsPowerColsOperator As New ROperator + Private clsScaleSubtractOperator As New ROperator Private clsScaleMultiplyOperator As New ROperator Private clsScaleDivideOperator As New ROperator + Private clsScaleAddOperator As New ROperator + Private clsScaleAddColsOperator As New ROperator + Private clsScaleMeanFunction As New RFunction + Private clsScaleMeanColsFunction As New RFunction + Private clsScaleMinFunction As New RFunction + Private clsScaleMinColsFunction As New RFunction + Private clsPreviewOperator As New ROperator Private clsDummyTransformFunction As New RFunction Private clsConstantDummyFunction As New RFunction @@ -52,7 +91,18 @@ Public Class dlgTransform Private clsGetColSelectionNamesFunction As New RFunction Private clsPreviewTextFunction As New RCodeStructure Private clsBooleanOperator As New ROperator + Private clsBooleanColsOperator As New ROperator + Private clsAddColumnsFunction As New RFunction Private clsIsNAFunction As New RFunction + Private clsGetDataFrameFunction As New RFunction + Private clsColumnsFunction As New RFunction + Private clsPasteFunction As New RFunction + Private clsMutateFunction As New RFunction + Private clsAcrossFunction As New RFunction + Private clsEverythingFunction As New RFunction + Private clsPipeOperator As New ROperator + Private clsTildaOperator As New ROperator + Private clsAssignOperator As New ROperator Private bResetRCode As Boolean = True Private Sub dlgRank_Load(sender As Object, e As EventArgs) Handles MyBase.Load @@ -84,6 +134,7 @@ Public Class dlgTransform ucrPnlTransformOptions.AddRadioButton(rdoSort) ucrPnlTransformOptions.AddRadioButton(rdoNonNegative) ucrPnlTransformOptions.AddRadioButton(rdoScale) + ucrPnlColumnSelectOptions.AddRadioButton(rdoSingle) ucrPnlColumnSelectOptions.AddRadioButton(rdoMultiple) @@ -92,8 +143,9 @@ Public Class dlgTransform ucrPnlTransformOptions.AddParameterValuesCondition(rdoSort, "check", "sort") ucrPnlTransformOptions.AddParameterValuesCondition(rdoNonNegative, "check", "non-negative") ucrPnlTransformOptions.AddParameterValuesCondition(rdoScale, "check", "scale") - ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoSingle, "check", "single") - ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoMultiple, "check", "multiple") + + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoSingle, "checked", "single") + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoMultiple, "checked", "multiple") ucrReceiverRank.SetParameter(New RParameter("x", 0)) ucrReceiverRank.Selector = ucrSelectorForRank @@ -153,7 +205,7 @@ Public Class dlgTransform ucrPnlNonNegative.AddParameterValuesCondition(rdoNaturalLog, "check", "log") ucrPnlNonNegative.AddParameterValuesCondition(rdoPower, "check", "power") - ucrPnlColumnSelectOptions.AddToLinkedControls(ucrNewColName, {rdoMultiple}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + 'ucrPnlColumnSelectOptions.AddToLinkedControls(ucrNewColName, {rdoMultiple}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudSignifDigits, {rdoSignificantDigits}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudRoundOfDigits, {rdoRoundOf}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudLagLeadPosition, {rdoLead}, bNewLinkedHideIfParameterMissing:=True) @@ -347,7 +399,27 @@ Public Class dlgTransform clsIsNAFunction = New RFunction clsRemoveLabelsFunction = New RFunction clsGetColSelectionNamesFunction = New RFunction - + clsGetDataFrameFunction = New RFunction + clsMutateFunction = New RFunction + clsAcrossFunction = New RFunction + clsEverythingFunction = New RFunction + clsPipeOperator = New ROperator + clsTildaOperator = New ROperator + clsRoundColsFunction = New RFunction + clsRankColsFunction = New RFunction + clsSortColsFunction = New RFunction + clsSignifColsFunction = New RFunction + clsLagColsFunction = New RFunction + clsLeadColsFunction = New RFunction + clsLeadColsFunction = New RFunction + clsConcDiffColsFunction = New RFunction + clsReplicateColsFunction = New RFunction + clsStandardDevColsFunction = New RFunction + clsBooleanColsOperator = New ROperator + clsAddColumnsFunction = New RFunction + clsPasteFunction = New RFunction + clsColumnsFunction = New RFunction + clsAssignOperator = New ROperator ucrSelectorForRank.Reset() ucrReceiverRank.SetMeAsReceiver() @@ -446,16 +518,132 @@ Public Class dlgTransform clsBooleanOperator.SetOperation("==") clsIsNAFunction.SetRCommand("is.na") + clsRankColsFunction.SetRCommand("~rank") + clsRankColsFunction.AddParameter("na.last", Chr(34) & "keep" & Chr(34), iPosition:=2) + clsRankColsFunction.AddParameter("ties.method", Chr(34) & "average" & Chr(34), iPosition:=3) + + clsSortColsFunction.SetRCommand("~sort") + clsSortColsFunction.AddParameter("decreasing", "TRUE", iPosition:=1) + clsSortColsFunction.AddParameter("na.last", "TRUE", iPosition:=2) + + clsRoundColsFunction.SetRCommand("~round") + + clsSignifColsFunction.SetRCommand("~signif") + + clsLagColsFunction.SetPackageName("~dplyr") + clsLagColsFunction.SetRCommand("lag") + + clsLeadColsFunction.SetPackageName("~dplyr") + clsLeadColsFunction.SetRCommand("lead") + + clsDiffColsFunction.SetRCommand("~diff") + clsDiffColsFunction.AddParameter("lag", "1", iPosition:=1) + + clsReplicateColsFunction.SetRCommand("~rep") + clsReplicateColsFunction.AddParameter("x", "NA", iPosition:=0) + + 'clsConcDiffFunction.SetRCommand("c") + 'clsConcDiffFunction.AddParameter("y", clsRFunctionParameter:=clsReplicateFunction, iPosition:=0, bIncludeArgumentName:=False) + 'clsConcDiffFunction.AddParameter("x", clsRFunctionParameter:=clsDiffFunction, iPosition:=1, bIncludeArgumentName:=False) + + clsMeanColsFunction.SetRCommand("~mean") + clsMeanColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) + + clsStandardDevColsFunction.SetRCommand("~sd") + clsStandardDevColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) + + clsSubtractOperator.SetOperation("-") + clsSubtractOperator.AddParameter("y", clsRFunctionParameter:=clsMeanFunction, iPosition:=1) + + clsDivisionOperator.SetOperation("/") + clsDivisionOperator.AddParameter("x", clsROperatorParameter:=clsSubtractOperator, iPosition:=0) + clsDivisionOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevFunction, iPosition:=1) + + clsSquarerootFunction.SetRCommand("sqrt") + + clsAddConstantOperator.SetOperation("+") + clsAddConstantOperator.AddParameter("c", "0", iPosition:=1) + + clsNaturalLogFunction.SetRCommand("log") + + clsLogBase10Function.SetRCommand("log10") + + clsPowerColsOperator.SetOperation("^") + clsPowerColsOperator.AddParameter("y", "1", iPosition:=1) + clsPowerColsOperator.bSpaceAroundOperation = False + + clsScaleMeanColsFunction.SetRCommand("~mean") + clsScaleMeanColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) + + clsScaleMinColsFunction.SetRCommand("~min") + clsScaleMinColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) + + clsScaleSubtractOperator.SetOperation("-") + clsScaleSubtractOperator.AddParameter("u", "0", iPosition:=1) + + clsScaleMultiplyOperator.SetOperation("*") + clsScaleMultiplyOperator.AddParameter("x", clsROperatorParameter:=clsScaleSubtractOperator, iPosition:=0) + clsScaleMultiplyOperator.AddParameter("y", "1", iPosition:=1) + + clsScaleDivideOperator.SetOperation("/") + clsScaleDivideOperator.AddParameter("x", clsROperatorParameter:=clsScaleMultiplyOperator, iPosition:=0) + clsScaleDivideOperator.AddParameter("z", "1", iPosition:=1) + clsScaleDivideOperator.bBrackets = False + + clsScaleAddColsOperator.SetOperation("+") + clsScaleAddColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleDivideOperator, iPosition:=0) + clsScaleAddColsOperator.AddParameter("v", "0", iPosition:=1) + clsScaleAddColsOperator.bBrackets = False + + clsBooleanColsOperator.SetOperation("==") + + + clsGetDataFrameFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") + + clsMutateFunction.SetPackageName("dplyr") + clsMutateFunction.SetRCommand("mutate") + + clsEverythingFunction.SetRCommand("everything") + clsEverythingFunction.AddParameter("dot", ".", bIncludeArgumentName:=False, iPosition:=0) + + clsAcrossFunction.SetPackageName("dplyr") + clsAcrossFunction.SetRCommand("across") + clsAcrossFunction.AddParameter("every", clsRFunctionParameter:=clsEverythingFunction, bIncludeArgumentName:=False, iPosition:=0) + + clsTildaOperator.SetOperation("~") + + clsPipeOperator.SetOperation("%>%") + clsPipeOperator.AddParameter("left", clsRFunctionParameter:=clsGetDataFrameFunction, iPosition:=0) + clsPipeOperator.AddParameter("right", clsRFunctionParameter:=clsMutateFunction, iPosition:=1) + clsPipeOperator.SetAssignTo("col") + clsRemoveLabelsFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$append_to_variables_metadata") clsRemoveLabelsFunction.AddParameter("property", Chr(34) & "labels" & Chr(34), iPosition:=2) clsRemoveLabelsFunction.AddParameter("new_val", Chr(34) & Chr(34), iPosition:=3) clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) + clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) + clsColumnsFunction.SetRCommand("colnames") + clsColumnsFunction.AddParameter("col_data", "col",, bIncludeArgumentName:=False) + + clsPasteFunction.SetRCommand("paste0") + clsPasteFunction.AddParameter("data", clsRFunctionParameter:=clsColumnsFunction, iPosition:=0, bIncludeArgumentName:=False) + + clsAssignOperator.SetOperation("<-") + clsAssignOperator.AddParameter("left", clsRFunctionParameter:=clsColumnsFunction, iPosition:=0) + clsAssignOperator.AddParameter("right", clsRFunctionParameter:=clsPasteFunction, iPosition:=1) + + + clsAddColumnsFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data") + clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + clsAddColumnsFunction.AddParameter("before", "FALSE", iPosition:=2) + + + 'ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) End Sub Private Sub SetRCodeForControls(bReset As Boolean) @@ -480,6 +668,7 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, New RParameter("x", 0), iAdditionalPairNo:=16) ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) ucrSelectorForRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, ucrSelectorForRank.GetParameter, iAdditionalPairNo:=1) + ucrNudRoundOfDigits.AddAdditionalCodeParameterPair(clsRoundColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) @@ -496,8 +685,10 @@ Public Class dlgTransform ucrSaveNew.AddAdditionalRCode(clsPreviewOperator, iAdditionalPairNo:=13) ucrSaveNew.AddAdditionalRCode(clsBooleanOperator, iAdditionalPairNo:=14) ucrSaveNew.AddAdditionalRCode(clsIsNAFunction, iAdditionalPairNo:=15) + 'ucrSaveNew.AddAdditionalRCode(clsPipeOperator, iAdditionalPairNo:=16) ucrPnlTransformOptions.SetRCode(clsDummyTransformFunction, bReset) + ucrPnlColumnSelectOptions.SetRCode(clsDummyTransformFunction, bReset) ucrReceiverRank.SetRCode(clsRankFunction, bReset) ucrChkDecreasing.SetRCode(clsSortFunction, bReset) ucrChkMissingLast.SetRCode(clsSortFunction, bReset) @@ -538,13 +729,27 @@ Public Class dlgTransform End Sub Private Sub NewDefaultName() + Dim strColNames As String + If rdoNumeric.Checked Then + strColNames = "Numeric" + ElseIf rdoNonNegative.Checked Then + strColNames = "NonNumeric" + ElseIf rdoRank.Checked Then + strColNames = "Rank" + ElseIf rdoScale.Checked Then + strColNames = "sort" + ElseIf rdoScale.Checked Then + strColNames = "scale" + End If If rdoSingle.Checked Then If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) End If ElseIf rdoMultiple.Checked Then - If (Not ucrNewColName.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then - ucrNewColName.SetName(ucrReceiverRank.GetVariableNames(bWithQuotes:=False) & "_transformed") + If Not ucrReceiverRank.IsEmpty Then + clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & strColNames & Chr(34), iPosition:=1, bIncludeArgumentName:=False) + + clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If End If End Sub @@ -556,27 +761,17 @@ Public Class dlgTransform ucrChkEditPreview.Checked = False End Sub - Private Sub ucrPnlTransformOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlTransformOptions.ControlValueChanged, ucrPnlNumericOptions.ControlValueChanged, ucrPnlColumnSelectOptions.ControlValueChanged, ucrInputLogicalValues.ControlValueChanged, + Private Sub ucrPnlTransformOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlTransformOptions.ControlValueChanged, ucrPnlNumericOptions.ControlValueChanged, ucrInputLogicalValues.ControlValueChanged, ucrPnlNonNegative.ControlValueChanged, ucrPnlMissingValues.ControlValueChanged, ucrPnlTies.ControlValueChanged, ucrChkPreview.ControlValueChanged, ucrReceiverRank.ControlValueChanged, ucrNudDiffLag.ControlValueChanged, ucrNudLagLeadPosition.ControlValueChanged, - ucrNudLagPosition.ControlValueChanged, ucrNudRoundOfDigits.ControlValueChanged, ucrNudSignifDigits.ControlValueChanged, ucrInputPower.ControlValueChanged, ucrInputMultiply.ControlValueChanged, + ucrNudLagPosition.ControlValueChanged, ucrNudRoundOfDigits.ControlValueChanged, ucrNudSignifDigits.ControlValueChanged, ucrInputPower.ControlValueChanged, ucrInputMultiply.ControlValueChanged, ucrPnlColumnSelectOptions.ControlValueChanged, ucrInputDivide.ControlValueChanged, ucrInputConstant.ControlValueChanged, ucrInputAdd.ControlValueChanged, ucrChkOmitNA.ControlValueChanged, ucrInputLogicOperations.ControlValueChanged, ucrChkAddConstant.ControlValueChanged, ucrChkMissingLast.ControlValueChanged, ucrChkDecreasing.ControlValueChanged, ucrChkDivide.ControlValueChanged, ucrChkAdd.ControlValueChanged, ucrChkMultiply.ControlValueChanged, ucrChkSubtract.ControlValueChanged - If bResetRCode Then - ucrBase.clsRsyntax.ClearCodes() - If rdoMultiple.Checked Then - clsDummyTransformFunction.AddParameter("check", "select", iPosition:=0) - ucrSelectorForRank.SetItemType("column_selection") - ucrReceiverRank.strSelectorHeading = "Column selections" - lblSelectColumns.Text = "Select:" - ElseIf rdoSingle.Checked Then - clsDummyTransformFunction.AddParameter("check", "variable", iPosition:=0) - ucrReceiverRank.bUseFilteredData = False - ucrReceiverRank.SetParameterIsRFunction() - ucrSelectorForRank.SetItemType("column") - ucrReceiverRank.strSelectorHeading = "Numerics" - lblSelectColumns.Text = "Column:" - End If + ucrBase.clsRsyntax.ClearCodes() + + If rdoSingle.Checked Then + + ' If bResetRCode Then If rdoRank.Checked Then clsPreviewTextFunction = clsRankFunction.Clone clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) @@ -670,13 +865,135 @@ Public Class dlgTransform ucrBase.clsRsyntax.SetBaseROperator(clsScaleAddOperator) ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) End If + 'End If + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) + + clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) + ucrReceiverRank.bUseFilteredData = False + ucrReceiverRank.SetParameterIsRFunction() + ucrSelectorForRank.SetItemType("column") + ucrReceiverRank.strSelectorHeading = "Numerics" + lblSelectColumns.Text = "Column:" + Else + LoopsParameters() + ucrBase.clsRsyntax.ClearCodes() + + ucrBase.clsRsyntax.SetBaseROperator(clsPipeOperator) + ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 0) + ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 1) + + clsDummyTransformFunction.AddParameter("checked", "multiple", iPosition:=1) + ucrSelectorForRank.SetItemType("column_selection") + ucrReceiverRank.strSelectorHeading = "Column selections" + lblSelectColumns.Text = "Select:" End If + SetPreviewText() UpdateNonNegativeParameters() NewDefaultName() ResetPreview() End Sub + Private Sub LoopsParameters() + 'ucrBase.clsRsyntax.SetBaseROperator(clsPipeOperator) + If rdoRank.Checked Then + clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) + clsPreviewTextFunction = clsRankColsFunction.Clone + clsRankColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("right", clsRFunctionParameter:=clsRankColsFunction, iPosition:=1) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsRankColsFunction, bIncludeArgumentName:=False, iPosition:=1) + ElseIf rdoSort.Checked Then + clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) + clsPreviewTextFunction = clsSortColsFunction.Clone + clsSortColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("left", clsRFunctionParameter:=clsSortColsFunction, iPosition:=0) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSortColsFunction, bIncludeArgumentName:=False, iPosition:=1) + ElseIf rdoNumeric.Checked Then + clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) + If rdoRoundOf.Checked Then + clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) + + clsRoundColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("round", clsRFunctionParameter:=clsRoundColsFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsRoundColsFunction, bIncludeArgumentName:=False) + ElseIf rdoSignificantDigits.Checked Then + clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) + + clsSignifColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsSignifColsFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSignifColsFunction, bIncludeArgumentName:=False) + ElseIf rdoLag.Checked Then + clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) + + clsLagColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLagColsFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLagColsFunction, bIncludeArgumentName:=False) + ElseIf rdoLead.Checked Then + clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) + + clsLeadColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLeadColsFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLeadColsFunction, bIncludeArgumentName:=False) + ElseIf rdoDifference.Checked Then + clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) + + clsConcDiffColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsConcDiffColsFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsConcDiffColsFunction, bIncludeArgumentName:=False) + ElseIf rdoStandardize.Checked Then + clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) + + clsDivisionColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsDivisionColsOperator, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsDivisionColsOperator, bIncludeArgumentName:=False) + ElseIf rdoLogical.Checked Then + clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) + clsBooleanColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsBooleanColsOperator, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsBooleanColsOperator, bIncludeArgumentName:=False) + End If + ElseIf rdoNonNegative.Checked Then + clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) + If rdoSquareRoot.Checked Then + clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) + + clsSquarerootColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsSquarerootFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSquarerootColsFunction, bIncludeArgumentName:=False) + ElseIf rdoPower.Checked Then + clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) + + clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) + + clsPowerColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsPowerOperator, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsPowerColsOperator, bIncludeArgumentName:=False) + ElseIf rdoLogToBase10.Checked Then + clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) + + + clsLogBase10ColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLogBase10Function, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLogBase10ColsFunction, bIncludeArgumentName:=False) + ElseIf rdoNaturalLog.Checked Then + clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) + + clsNaturalLogColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsNaturalLogFunction, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsNaturalLogColsFunction, bIncludeArgumentName:=False) + End If + ElseIf rdoScale.Checked Then + clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) + + clsScaleAddColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsScaleAddOperator, iPosition:=1, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) + End If + + clsMutateFunction.AddParameter("var", clsRFunctionParameter:=clsAcrossFunction, bIncludeArgumentName:=False, iPosition:=0) + End Sub + Private Sub SetPreviewText() clsPreviewTextFunction.RemoveAssignTo() If Not ucrReceiverRank.IsEmpty Then @@ -773,4 +1090,14 @@ Public Class dlgTransform ucrChkAddConstant.ControlContentsChanged, ucrInputPower.ControlContentsChanged, ucrInputPreview.ControlContentsChanged, ucrInputLogicalValues.ControlContentsChanged, ucrInputLogicOperations.ControlContentsChanged TestOKEnabled() End Sub + + Private Sub ucrPnlColumnSelectOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlColumnSelectOptions.ControlValueChanged, ucrReceiverRank.ControlValueChanged, ucrSelectorForRank.ControlValueChanged + + clsGetDataFrameFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.strCurrentDataFrame & Chr(34), iPosition:=0, bIncludeArgumentName:=False) + clsGetDataFrameFunction.AddParameter("column_selection_name ", ucrReceiverRank.GetVariableNames, iPosition:=1) + clsGetDataFrameFunction.SetAssignTo(ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text) + + clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + + End Sub End Class \ No newline at end of file From 2cdab1187b3edec5017dc7da425606c6e6814775 Mon Sep 17 00:00:00 2001 From: Barbra2020 Date: Fri, 15 Mar 2024 14:03:46 +0300 Subject: [PATCH 04/30] changes --- instat/dlgTransform.vb | 69 ++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 6fc220edba9..9c4d4a34bee 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -53,13 +53,17 @@ Public Class dlgTransform Private clsStandardDevColsFunction As New RFunction Private clsSubtractOperator As New ROperator + Private clsSubtractColsOperator As New ROperator + Private clsDivisionOperator As New ROperator + Private clsDivisionColsOperator As New ROperator Private clsSquarerootFunction As New RFunction Private clsSquarerootColsFunction As New RFunction Private clsAddConstantOperator As New ROperator + Private clsAddConstantColsOperator As New ROperator Private clsNaturalLogFunction As New RFunction Private clsNaturalLogColsFunction As New RFunction @@ -205,7 +209,7 @@ Public Class dlgTransform ucrPnlNonNegative.AddParameterValuesCondition(rdoNaturalLog, "check", "log") ucrPnlNonNegative.AddParameterValuesCondition(rdoPower, "check", "power") - 'ucrPnlColumnSelectOptions.AddToLinkedControls(ucrNewColName, {rdoMultiple}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlColumnSelectOptions.AddToLinkedControls(ucrSaveNew, {rdoSingle}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudSignifDigits, {rdoSignificantDigits}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudRoundOfDigits, {rdoRoundOf}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudLagLeadPosition, {rdoLead}, bNewLinkedHideIfParameterMissing:=True) @@ -380,6 +384,7 @@ Public Class dlgTransform clsDivisionOperator = New ROperator clsSquarerootFunction = New RFunction clsAddConstantOperator = New ROperator + clsAddConstantColsOperator = New ROperator clsNaturalLogFunction = New RFunction clsLogBase10Function = New RFunction clsPowerOperator = New ROperator @@ -542,9 +547,9 @@ Public Class dlgTransform clsReplicateColsFunction.SetRCommand("~rep") clsReplicateColsFunction.AddParameter("x", "NA", iPosition:=0) - 'clsConcDiffFunction.SetRCommand("c") - 'clsConcDiffFunction.AddParameter("y", clsRFunctionParameter:=clsReplicateFunction, iPosition:=0, bIncludeArgumentName:=False) - 'clsConcDiffFunction.AddParameter("x", clsRFunctionParameter:=clsDiffFunction, iPosition:=1, bIncludeArgumentName:=False) + clsConcDiffColsFunction.SetRCommand("c") + clsConcDiffColsFunction.AddParameter("y", clsRFunctionParameter:=clsReplicateColsFunction, iPosition:=0, bIncludeArgumentName:=False) + clsConcDiffColsFunction.AddParameter("x", clsRFunctionParameter:=clsDiffColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsMeanColsFunction.SetRCommand("~mean") clsMeanColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) @@ -552,21 +557,21 @@ Public Class dlgTransform clsStandardDevColsFunction.SetRCommand("~sd") clsStandardDevColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) - clsSubtractOperator.SetOperation("-") - clsSubtractOperator.AddParameter("y", clsRFunctionParameter:=clsMeanFunction, iPosition:=1) + clsSubtractColsOperator.SetOperation("-") + clsSubtractColsOperator.AddParameter("y", clsRFunctionParameter:=clsMeanColsFunction, iPosition:=1) - clsDivisionOperator.SetOperation("/") - clsDivisionOperator.AddParameter("x", clsROperatorParameter:=clsSubtractOperator, iPosition:=0) - clsDivisionOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevFunction, iPosition:=1) + clsDivisionColsOperator.SetOperation("/") + clsDivisionColsOperator.AddParameter("x", clsROperatorParameter:=clsSubtractColsOperator, iPosition:=0) + clsDivisionColsOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevColsFunction, iPosition:=1) clsSquarerootFunction.SetRCommand("sqrt") - clsAddConstantOperator.SetOperation("+") - clsAddConstantOperator.AddParameter("c", "0", iPosition:=1) + clsAddConstantColsOperator.SetOperation("+") + clsAddConstantColsOperator.AddParameter("c", "0", iPosition:=1) - clsNaturalLogFunction.SetRCommand("log") + clsNaturalLogColsFunction.SetRCommand("log") - clsLogBase10Function.SetRCommand("log10") + clsLogBase10ColsFunction.SetRCommand("~log10") clsPowerColsOperator.SetOperation("^") clsPowerColsOperator.AddParameter("y", "1", iPosition:=1) @@ -617,7 +622,6 @@ Public Class dlgTransform clsPipeOperator.AddParameter("right", clsRFunctionParameter:=clsMutateFunction, iPosition:=1) clsPipeOperator.SetAssignTo("col") - clsRemoveLabelsFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$append_to_variables_metadata") clsRemoveLabelsFunction.AddParameter("property", Chr(34) & "labels" & Chr(34), iPosition:=2) clsRemoveLabelsFunction.AddParameter("new_val", Chr(34) & Chr(34), iPosition:=3) @@ -659,6 +663,13 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsSubtractOperator, New RParameter("x", 0), iAdditionalPairNo:=8) ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevFunction, New RParameter("x", 0), iAdditionalPairNo:=9) ucrNudDiffLag.AddAdditionalCodeParameterPair(clsReplicateFunction, New RParameter("times", 1), iAdditionalPairNo:=1) + ucrNudDiffLag.AddAdditionalCodeParameterPair(clsReplicateColsFunction, New RParameter("times", 1), iAdditionalPairNo:=2) + ucrNudDiffLag.AddAdditionalCodeParameterPair(clsDiffColsFunction, New RParameter("times", 1), iAdditionalPairNo:=3) + ucrNudLagLeadPosition.AddAdditionalCodeParameterPair(clsLeadColsFunction, New RParameter("n", 1), iAdditionalPairNo:=1) + ucrNudLagPosition.AddAdditionalCodeParameterPair(clsLagColsFunction, New RParameter("lag", 1), iAdditionalPairNo:=1) + ucrNudSignifDigits.AddAdditionalCodeParameterPair(clsSignifColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) + ucrInputPower.AddAdditionalCodeParameterPair(clsPowerColsOperator, New RParameter("y", 1), iAdditionalPairNo:=1) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsAddConstantOperator, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=10) ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleSubtractOperator, New RParameter("x", 0), iAdditionalPairNo:=11) ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMeanFunction, New RParameter("x", 0), iAdditionalPairNo:=12) @@ -666,6 +677,8 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanOperator, New RParameter("x", 0), iAdditionalPairNo:=14) ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAFunction, New RParameter("x", 0), iAdditionalPairNo:=15) ucrReceiverRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, New RParameter("x", 0), iAdditionalPairNo:=16) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsLeadColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=17) + ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) ucrSelectorForRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, ucrSelectorForRank.GetParameter, iAdditionalPairNo:=1) ucrNudRoundOfDigits.AddAdditionalCodeParameterPair(clsRoundColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) @@ -878,10 +891,10 @@ Public Class dlgTransform Else LoopsParameters() ucrBase.clsRsyntax.ClearCodes() - - ucrBase.clsRsyntax.SetBaseROperator(clsPipeOperator) - ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 0) - ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 1) + ucrBase.clsRsyntax.SetAssignTo("col") + ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) + ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) + ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) clsDummyTransformFunction.AddParameter("checked", "multiple", iPosition:=1) ucrSelectorForRank.SetItemType("column_selection") @@ -944,7 +957,9 @@ Public Class dlgTransform ElseIf rdoStandardize.Checked Then clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) - clsDivisionColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsMeanColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsStandardDevColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsDivisionColsOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsDivisionColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogical.Checked Then @@ -1019,10 +1034,18 @@ Public Class dlgTransform Private Sub UpdateConstantParameter() If ucrChkAddConstant.Checked Then - clsSquarerootFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) - clsPowerOperator.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) - clsLogBase10Function.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) - clsNaturalLogFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) + If rdoSingle.Checked Then + clsSquarerootFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) + clsPowerOperator.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) + clsLogBase10Function.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) + clsNaturalLogFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantOperator, iPosition:=0) + Else + clsSquarerootColsFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantColsOperator, iPosition:=0) + clsPowerColsOperator.AddParameter("x", clsROperatorParameter:=clsAddConstantColsOperator, iPosition:=0) + clsLogBase10ColsFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantColsOperator, iPosition:=0) + clsNaturalLogColsFunction.AddParameter("x", clsROperatorParameter:=clsAddConstantColsOperator, iPosition:=0) + End If + End If If bResetRCode Then If ucrChkAddConstant.Checked Then From 23c3add10d425bb0e157eb7a1bb8eb92d3e47525 Mon Sep 17 00:00:00 2001 From: Barbra2020 Date: Mon, 18 Mar 2024 12:24:22 +0300 Subject: [PATCH 05/30] changes --- instat/dlgTransform.vb | 307 +++++++++++++++++++++++++---------------- 1 file changed, 187 insertions(+), 120 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 9c4d4a34bee..3d673e4e3de 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -75,6 +75,8 @@ Public Class dlgTransform Private clsPowerColsOperator As New ROperator Private clsScaleSubtractOperator As New ROperator + Private clsScaleSubtractColsOperator As New ROperator + Private clsScaleMultiplyOperator As New ROperator Private clsScaleDivideOperator As New ROperator @@ -98,6 +100,8 @@ Public Class dlgTransform Private clsBooleanColsOperator As New ROperator Private clsAddColumnsFunction As New RFunction Private clsIsNAFunction As New RFunction + Private clsIsNAColsFunction As New RFunction + Private clsGetDataFrameFunction As New RFunction Private clsColumnsFunction As New RFunction Private clsPasteFunction As New RFunction @@ -148,8 +152,8 @@ Public Class dlgTransform ucrPnlTransformOptions.AddParameterValuesCondition(rdoNonNegative, "check", "non-negative") ucrPnlTransformOptions.AddParameterValuesCondition(rdoScale, "check", "scale") - ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoSingle, "checked", "single") - ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoMultiple, "checked", "multiple") + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoSingle, "col", "single") + ucrPnlColumnSelectOptions.AddParameterValuesCondition(rdoMultiple, "col", "multiple") ucrReceiverRank.SetParameter(New RParameter("x", 0)) ucrReceiverRank.Selector = ucrSelectorForRank @@ -425,6 +429,7 @@ Public Class dlgTransform clsPasteFunction = New RFunction clsColumnsFunction = New RFunction clsAssignOperator = New ROperator + clsIsNAColsFunction = New RFunction ucrSelectorForRank.Reset() ucrReceiverRank.SetMeAsReceiver() @@ -601,6 +606,7 @@ Public Class dlgTransform clsScaleAddColsOperator.bBrackets = False clsBooleanColsOperator.SetOperation("==") + clsIsNAColsFunction.SetRCommand("is.na") clsGetDataFrameFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") @@ -627,7 +633,8 @@ Public Class dlgTransform clsRemoveLabelsFunction.AddParameter("new_val", Chr(34) & Chr(34), iPosition:=3) clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) - clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) + clsDummyTransformFunction.AddParameter("col", "single", iPosition:=1) + clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) @@ -678,10 +685,30 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAFunction, New RParameter("x", 0), iAdditionalPairNo:=15) ucrReceiverRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, New RParameter("x", 0), iAdditionalPairNo:=16) ucrReceiverRank.AddAdditionalCodeParameterPair(clsLeadColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=17) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsSortColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=18) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsRoundColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=19) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsSignifColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=20) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsLagColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=21) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsLeadColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=22) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsDiffColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=23) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=24) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=25) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, New RParameter("x", 0), iAdditionalPairNo:=26) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsRankColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=27) + + ucrReceiverRank.AddAdditionalCodeParameterPair(clsAddConstantColsOperator, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=28) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=29) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=30) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinColsFunction, New RParameter("x", 0), iAdditionalPairNo:=31) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 0), iAdditionalPairNo:=32) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAColsFunction, New RParameter("x", 0), iAdditionalPairNo:=33) + ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) ucrSelectorForRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, ucrSelectorForRank.GetParameter, iAdditionalPairNo:=1) ucrNudRoundOfDigits.AddAdditionalCodeParameterPair(clsRoundColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) + ucrChkOmitNA.AddAdditionalCodeParameterPair(clsMeanColsFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=2) + ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=3) ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) @@ -737,7 +764,7 @@ Public Class dlgTransform ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) End If Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) End If End Sub @@ -781,127 +808,127 @@ Public Class dlgTransform ucrChkMissingLast.ControlValueChanged, ucrChkDecreasing.ControlValueChanged, ucrChkDivide.ControlValueChanged, ucrChkAdd.ControlValueChanged, ucrChkMultiply.ControlValueChanged, ucrChkSubtract.ControlValueChanged ucrBase.clsRsyntax.ClearCodes() + If bResetRCode Then - If rdoSingle.Checked Then + If rdoSingle.Checked Then - ' If bResetRCode Then - If rdoRank.Checked Then - clsPreviewTextFunction = clsRankFunction.Clone - clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsRankFunction) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoSort.Checked Then - clsPreviewTextFunction = clsSortFunction.Clone - clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsSortFunction) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNumeric.Checked Then - clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) - If rdoRoundOf.Checked Then - clsPreviewTextFunction = clsRoundFunction.Clone - clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) - ElseIf rdoSignificantDigits.Checked Then - clsPreviewTextFunction = clsSignifFunction.Clone - clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsSignifFunction) - ElseIf rdoLag.Checked Then - clsPreviewTextFunction = clsLagFunction.Clone - clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLagFunction) - ElseIf rdoLead.Checked Then - clsPreviewTextFunction = clsLeadFunction.Clone - clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLeadFunction) - ElseIf rdoDifference.Checked Then - clsPreviewTextFunction = clsConcDiffFunction.Clone - clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsConcDiffFunction) - ElseIf rdoStandardize.Checked Then - clsPreviewTextFunction = clsDivisionOperator.Clone - clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) - ucrBase.clsRsyntax.SetBaseROperator(clsDivisionOperator) - ElseIf rdoLogical.Checked Then - clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) - clsPreviewTextFunction = clsBooleanOperator.Clone - ucrBase.clsRsyntax.SetBaseROperator(clsBooleanOperator) - Select Case ucrInputLogicOperations.GetText - Case "==" - clsBooleanOperator.SetOperation("==") - Case "<" - clsBooleanOperator.SetOperation("<") - Case "<=" - clsBooleanOperator.SetOperation("<=") - Case ">" - clsBooleanOperator.SetOperation(">") - Case ">=" - clsBooleanOperator.SetOperation(">=") - Case "!=" - clsBooleanOperator.SetOperation("!=") - Case "%in%" - clsBooleanOperator.SetOperation("%in%") - Case "is.na" - clsIsNAFunction.SetRCommand("is.na") - clsPreviewTextFunction = clsIsNAFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) - Case "!is.na" - clsIsNAFunction.SetRCommand("!is.na") - clsPreviewTextFunction = clsIsNAFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) - End Select - End If - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNonNegative.Checked Then - UpdateConstantParameter() - clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) - If rdoSquareRoot.Checked Then - clsPreviewTextFunction = clsSquarerootFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsSquarerootFunction) - clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) - ElseIf rdoPower.Checked Then - clsPreviewTextFunction = clsPowerOperator.Clone - clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) - ucrBase.clsRsyntax.SetBaseROperator(clsPowerOperator) - ElseIf rdoLogToBase10.Checked Then - clsPreviewTextFunction = clsLogBase10Function.Clone - clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLogBase10Function) - ElseIf rdoNaturalLog.Checked Then - clsPreviewTextFunction = clsNaturalLogFunction.Clone - clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsNaturalLogFunction) + If rdoRank.Checked Then + clsPreviewTextFunction = clsRankFunction.Clone + clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsRankFunction) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoSort.Checked Then + clsPreviewTextFunction = clsSortFunction.Clone + clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsSortFunction) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoNumeric.Checked Then + clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) + If rdoRoundOf.Checked Then + clsPreviewTextFunction = clsRoundFunction.Clone + clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) + ElseIf rdoSignificantDigits.Checked Then + clsPreviewTextFunction = clsSignifFunction.Clone + clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsSignifFunction) + ElseIf rdoLag.Checked Then + clsPreviewTextFunction = clsLagFunction.Clone + clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLagFunction) + ElseIf rdoLead.Checked Then + clsPreviewTextFunction = clsLeadFunction.Clone + clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLeadFunction) + ElseIf rdoDifference.Checked Then + clsPreviewTextFunction = clsConcDiffFunction.Clone + clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsConcDiffFunction) + ElseIf rdoStandardize.Checked Then + clsPreviewTextFunction = clsDivisionOperator.Clone + clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) + ucrBase.clsRsyntax.SetBaseROperator(clsDivisionOperator) + ElseIf rdoLogical.Checked Then + clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) + clsPreviewTextFunction = clsBooleanOperator.Clone + ucrBase.clsRsyntax.SetBaseROperator(clsBooleanOperator) + Select Case ucrInputLogicOperations.GetText + Case "==" + clsBooleanOperator.SetOperation("==") + Case "<" + clsBooleanOperator.SetOperation("<") + Case "<=" + clsBooleanOperator.SetOperation("<=") + Case ">" + clsBooleanOperator.SetOperation(">") + Case ">=" + clsBooleanOperator.SetOperation(">=") + Case "!=" + clsBooleanOperator.SetOperation("!=") + Case "%in%" + clsBooleanOperator.SetOperation("%in%") + Case "is.na" + clsIsNAFunction.SetRCommand("is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + Case "!is.na" + clsIsNAFunction.SetRCommand("!is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + End Select + End If + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoNonNegative.Checked Then + UpdateConstantParameter() + clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) + If rdoSquareRoot.Checked Then + clsPreviewTextFunction = clsSquarerootFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsSquarerootFunction) + clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) + ElseIf rdoPower.Checked Then + clsPreviewTextFunction = clsPowerOperator.Clone + clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) + ucrBase.clsRsyntax.SetBaseROperator(clsPowerOperator) + ElseIf rdoLogToBase10.Checked Then + clsPreviewTextFunction = clsLogBase10Function.Clone + clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLogBase10Function) + ElseIf rdoNaturalLog.Checked Then + clsPreviewTextFunction = clsNaturalLogFunction.Clone + clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsNaturalLogFunction) + End If + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoScale.Checked Then + clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) + clsPreviewTextFunction = clsScaleAddOperator.Clone + ucrBase.clsRsyntax.SetBaseROperator(clsScaleAddOperator) + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) End If - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoScale.Checked Then - clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) - clsPreviewTextFunction = clsScaleAddOperator.Clone - ucrBase.clsRsyntax.SetBaseROperator(clsScaleAddOperator) - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + 'End If + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) + + 'clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) + 'ucrReceiverRank.bUseFilteredData = False + 'ucrReceiverRank.SetParameterIsRFunction() + 'ucrSelectorForRank.SetItemType("column") + 'ucrReceiverRank.strSelectorHeading = "Numerics" + 'lblSelectColumns.Text = "Column:" + Else + LoopsParameters() + ucrBase.clsRsyntax.ClearCodes() + ucrBase.clsRsyntax.SetAssignTo("col") + ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) + ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) + ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) + + 'clsDummyTransformFunction.AddParameter("checked", "multiple", iPosition:=1) + 'ucrSelectorForRank.SetItemType("column_selection") + 'ucrReceiverRank.strSelectorHeading = "Column selections" + 'lblSelectColumns.Text = "Select:" End If - 'End If - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) - - clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) - ucrReceiverRank.bUseFilteredData = False - ucrReceiverRank.SetParameterIsRFunction() - ucrSelectorForRank.SetItemType("column") - ucrReceiverRank.strSelectorHeading = "Numerics" - lblSelectColumns.Text = "Column:" - Else - LoopsParameters() - ucrBase.clsRsyntax.ClearCodes() - ucrBase.clsRsyntax.SetAssignTo("col") - ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) - ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) - ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) - - clsDummyTransformFunction.AddParameter("checked", "multiple", iPosition:=1) - ucrSelectorForRank.SetItemType("column_selection") - ucrReceiverRank.strSelectorHeading = "Column selections" - lblSelectColumns.Text = "Select:" End If - SetPreviewText() UpdateNonNegativeParameters() NewDefaultName() @@ -967,7 +994,34 @@ Public Class dlgTransform clsBooleanColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsBooleanColsOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsBooleanColsOperator, bIncludeArgumentName:=False) + Select Case ucrInputLogicOperations.GetText + Case "==" + clsBooleanColsOperator.SetOperation("==") + Case "<" + clsBooleanColsOperator.SetOperation("<") + Case "<=" + clsBooleanColsOperator.SetOperation("<=") + Case ">" + clsBooleanColsOperator.SetOperation(">") + Case ">=" + clsBooleanColsOperator.SetOperation(">=") + Case "!=" + clsBooleanColsOperator.SetOperation("!=") + Case "%in%" + clsBooleanColsOperator.SetOperation("%in%") + Case "is.na" + clsIsNAColsFunction.SetRCommand("is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + Case "!is.na" + clsIsNAFunction.SetRCommand("!is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + End Select End If + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + + ElseIf rdoNonNegative.Checked Then clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) If rdoSquareRoot.Checked Then @@ -1122,5 +1176,18 @@ Public Class dlgTransform clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + If rdoMultiple.Checked Then + clsDummyTransformFunction.AddParameter("col", "multiple", iPosition:=0) + ucrSelectorForRank.SetItemType("column_selection") + ucrReceiverRank.strSelectorHeading = "Column selections" + lblSelectColumns.Text = "Select:" + ElseIf rdoSingle.Checked Then + clsDummyTransformFunction.AddParameter("col", "single", iPosition:=0) + 'ucrReceiverRank.bUseFilteredData = False + 'ucrReceiverRank.SetParameterIsRFunction() + ucrSelectorForRank.SetItemType("column") + ucrReceiverRank.strSelectorHeading = "Numerics" + lblSelectColumns.Text = "Column:" + End If End Sub End Class \ No newline at end of file From 7d93a20a39ea12fcdc6219ae6a82d169e231f1ac Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:47:37 +0100 Subject: [PATCH 06/30] Code Changes --- instat/dlgTransform.vb | 314 +++++++++++++++++------------------------ 1 file changed, 128 insertions(+), 186 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 3d673e4e3de..d444cef62be 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -20,74 +20,54 @@ Public Class dlgTransform Public bFirstLoad As Boolean = True Private bReset As Boolean = True Private clsRankFunction As New RFunction - Private clsRankColsFunction As New RFunction - Private clsSortFunction As New RFunction - Private clsSortColsFunction As New RFunction - Private clsRoundFunction As New RFunction - Private clsRoundColsFunction As New RFunction - Private clsSignifFunction As New RFunction - Private clsSignifColsFunction As New RFunction - Private clsLagFunction As New RFunction - Private clsLagColsFunction As New RFunction - Private clsLeadFunction As New RFunction - Private clsLeadColsFunction As New RFunction - Private clsDiffFunction As New RFunction - Private clsDiffColsFunction As New RFunction - Private clsConcDiffFunction As New RFunction - Private clsConcDiffColsFunction As New RFunction - Private clsReplicateFunction As New RFunction - Private clsReplicateColsFunction As New RFunction - Private clsMeanFunction As New RFunction - Private clsMeanColsFunction As New RFunction - Private clsStandardDevFunction As New RFunction - Private clsStandardDevColsFunction As New RFunction - Private clsSubtractOperator As New ROperator - Private clsSubtractColsOperator As New ROperator - Private clsDivisionOperator As New ROperator Private clsDivisionColsOperator As New ROperator - Private clsSquarerootFunction As New RFunction + Private clsSubtractColsOperator As New ROperator Private clsSquarerootColsFunction As New RFunction - Private clsAddConstantOperator As New ROperator Private clsAddConstantColsOperator As New ROperator Private clsNaturalLogFunction As New RFunction Private clsNaturalLogColsFunction As New RFunction - + Private clsLagColsFunction As New RFunction + Private clsRankColsFunction As New RFunction Private clsLogBase10Function As New RFunction Private clsLogBase10ColsFunction As New RFunction + Private clsStandardDevColsFunction As New RFunction + Private clsMeanColsFunction As New RFunction + Private clsReplicateColsFunction As New RFunction + Private clsConcDiffColsFunction As New RFunction + Private clsDiffColsFunction As New RFunction + Private clsLeadColsFunction As New RFunction + Private clsSignifColsFunction As New RFunction + Private clsRoundColsFunction As New RFunction + Private clsSortColsFunction As New RFunction + Private clsPowerColsOperator As New ROperator + Private clsScaleSubtractColsOperator As New ROperator + Private clsScaleAddColsOperator As New ROperator + Private clsScaleMeanColsFunction As New RFunction + Private clsScaleMinColsFunction As New RFunction Private clsRemoveLabelsFunction As New RFunction Private clsPowerOperator As New ROperator - Private clsPowerColsOperator As New ROperator - Private clsScaleSubtractOperator As New ROperator - Private clsScaleSubtractColsOperator As New ROperator - Private clsScaleMultiplyOperator As New ROperator Private clsScaleDivideOperator As New ROperator - Private clsScaleAddOperator As New ROperator - Private clsScaleAddColsOperator As New ROperator - Private clsScaleMeanFunction As New RFunction - Private clsScaleMeanColsFunction As New RFunction - Private clsScaleMinFunction As New RFunction - Private clsScaleMinColsFunction As New RFunction Private clsPreviewOperator As New ROperator Private clsDummyTransformFunction As New RFunction @@ -569,12 +549,12 @@ Public Class dlgTransform clsDivisionColsOperator.AddParameter("x", clsROperatorParameter:=clsSubtractColsOperator, iPosition:=0) clsDivisionColsOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevColsFunction, iPosition:=1) - clsSquarerootFunction.SetRCommand("sqrt") + clsSquarerootColsFunction.SetRCommand("~sqrt") clsAddConstantColsOperator.SetOperation("+") clsAddConstantColsOperator.AddParameter("c", "0", iPosition:=1) - clsNaturalLogColsFunction.SetRCommand("log") + clsNaturalLogColsFunction.SetRCommand("~log") clsLogBase10ColsFunction.SetRCommand("~log10") @@ -709,7 +689,10 @@ Public Class dlgTransform ucrNudRoundOfDigits.AddAdditionalCodeParameterPair(clsRoundColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) ucrChkOmitNA.AddAdditionalCodeParameterPair(clsMeanColsFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=2) ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=3) - + ucrPnlTies.AddAdditionalCodeParameterPair(clsRankColsFunction, New RParameter("ties.method", 1), iAdditionalPairNo:=1) + ucrPnlMissingValues.AddAdditionalCodeParameterPair(clsRankColsFunction, New RParameter("na.last", 2), iAdditionalPairNo:=1) + ucrChkMissingLast.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("na.last", 1), iAdditionalPairNo:=1) + ucrChkDecreasing.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("decreasing", 2), iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) ucrSaveNew.AddAdditionalRCode(clsSignifFunction, iAdditionalPairNo:=3) @@ -725,11 +708,9 @@ Public Class dlgTransform ucrSaveNew.AddAdditionalRCode(clsPreviewOperator, iAdditionalPairNo:=13) ucrSaveNew.AddAdditionalRCode(clsBooleanOperator, iAdditionalPairNo:=14) ucrSaveNew.AddAdditionalRCode(clsIsNAFunction, iAdditionalPairNo:=15) - 'ucrSaveNew.AddAdditionalRCode(clsPipeOperator, iAdditionalPairNo:=16) ucrPnlTransformOptions.SetRCode(clsDummyTransformFunction, bReset) ucrPnlColumnSelectOptions.SetRCode(clsDummyTransformFunction, bReset) - ucrReceiverRank.SetRCode(clsRankFunction, bReset) ucrChkDecreasing.SetRCode(clsSortFunction, bReset) ucrChkMissingLast.SetRCode(clsSortFunction, bReset) ucrSaveNew.SetRCode(clsRoundFunction, bReset) @@ -752,7 +733,9 @@ Public Class dlgTransform ucrChkOmitNA.SetRCode(clsMeanFunction, bReset) ucrChkPreview.SetRCode(clsConstantDummyFunction, bReset) - + If bReset Then + ucrReceiverRank.SetRCode(clsRankFunction, bReset) + End If bResetRCode = True End Sub @@ -769,25 +752,13 @@ Public Class dlgTransform End Sub Private Sub NewDefaultName() - Dim strColNames As String - If rdoNumeric.Checked Then - strColNames = "Numeric" - ElseIf rdoNonNegative.Checked Then - strColNames = "NonNumeric" - ElseIf rdoRank.Checked Then - strColNames = "Rank" - ElseIf rdoScale.Checked Then - strColNames = "sort" - ElseIf rdoScale.Checked Then - strColNames = "scale" - End If If rdoSingle.Checked Then If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) End If ElseIf rdoMultiple.Checked Then If Not ucrReceiverRank.IsEmpty Then - clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & strColNames & Chr(34), iPosition:=1, bIncludeArgumentName:=False) + clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & "transformed" & Chr(34), iPosition:=1, bIncludeArgumentName:=False) clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If @@ -808,127 +779,117 @@ Public Class dlgTransform ucrChkMissingLast.ControlValueChanged, ucrChkDecreasing.ControlValueChanged, ucrChkDivide.ControlValueChanged, ucrChkAdd.ControlValueChanged, ucrChkMultiply.ControlValueChanged, ucrChkSubtract.ControlValueChanged ucrBase.clsRsyntax.ClearCodes() - If bResetRCode Then + 'If bResetRCode Then - If rdoSingle.Checked Then + If rdoSingle.Checked Then - If rdoRank.Checked Then - clsPreviewTextFunction = clsRankFunction.Clone - clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsRankFunction) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoSort.Checked Then - clsPreviewTextFunction = clsSortFunction.Clone - clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsSortFunction) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNumeric.Checked Then - clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) - If rdoRoundOf.Checked Then - clsPreviewTextFunction = clsRoundFunction.Clone - clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) - ElseIf rdoSignificantDigits.Checked Then - clsPreviewTextFunction = clsSignifFunction.Clone - clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsSignifFunction) - ElseIf rdoLag.Checked Then - clsPreviewTextFunction = clsLagFunction.Clone - clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLagFunction) - ElseIf rdoLead.Checked Then - clsPreviewTextFunction = clsLeadFunction.Clone - clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLeadFunction) - ElseIf rdoDifference.Checked Then - clsPreviewTextFunction = clsConcDiffFunction.Clone - clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsConcDiffFunction) - ElseIf rdoStandardize.Checked Then - clsPreviewTextFunction = clsDivisionOperator.Clone - clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) - ucrBase.clsRsyntax.SetBaseROperator(clsDivisionOperator) - ElseIf rdoLogical.Checked Then - clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) - clsPreviewTextFunction = clsBooleanOperator.Clone - ucrBase.clsRsyntax.SetBaseROperator(clsBooleanOperator) - Select Case ucrInputLogicOperations.GetText - Case "==" - clsBooleanOperator.SetOperation("==") - Case "<" - clsBooleanOperator.SetOperation("<") - Case "<=" - clsBooleanOperator.SetOperation("<=") - Case ">" - clsBooleanOperator.SetOperation(">") - Case ">=" - clsBooleanOperator.SetOperation(">=") - Case "!=" - clsBooleanOperator.SetOperation("!=") - Case "%in%" - clsBooleanOperator.SetOperation("%in%") - Case "is.na" - clsIsNAFunction.SetRCommand("is.na") - clsPreviewTextFunction = clsIsNAFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) - Case "!is.na" - clsIsNAFunction.SetRCommand("!is.na") - clsPreviewTextFunction = clsIsNAFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) - End Select - End If - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNonNegative.Checked Then - UpdateConstantParameter() - clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) - If rdoSquareRoot.Checked Then - clsPreviewTextFunction = clsSquarerootFunction.Clone - ucrBase.clsRsyntax.SetBaseRFunction(clsSquarerootFunction) - clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) - ElseIf rdoPower.Checked Then - clsPreviewTextFunction = clsPowerOperator.Clone - clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) - ucrBase.clsRsyntax.SetBaseROperator(clsPowerOperator) - ElseIf rdoLogToBase10.Checked Then - clsPreviewTextFunction = clsLogBase10Function.Clone - clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsLogBase10Function) - ElseIf rdoNaturalLog.Checked Then - clsPreviewTextFunction = clsNaturalLogFunction.Clone - clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) - ucrBase.clsRsyntax.SetBaseRFunction(clsNaturalLogFunction) - End If - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoScale.Checked Then - clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) - clsPreviewTextFunction = clsScaleAddOperator.Clone - ucrBase.clsRsyntax.SetBaseROperator(clsScaleAddOperator) - ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + If rdoRank.Checked Then + clsPreviewTextFunction = clsRankFunction.Clone + clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsRankFunction) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoSort.Checked Then + clsPreviewTextFunction = clsSortFunction.Clone + clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsSortFunction) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoNumeric.Checked Then + clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) + If rdoRoundOf.Checked Then + clsPreviewTextFunction = clsRoundFunction.Clone + clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) + ElseIf rdoSignificantDigits.Checked Then + clsPreviewTextFunction = clsSignifFunction.Clone + clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsSignifFunction) + ElseIf rdoLag.Checked Then + clsPreviewTextFunction = clsLagFunction.Clone + clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLagFunction) + ElseIf rdoLead.Checked Then + clsPreviewTextFunction = clsLeadFunction.Clone + clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLeadFunction) + ElseIf rdoDifference.Checked Then + clsPreviewTextFunction = clsConcDiffFunction.Clone + clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsConcDiffFunction) + ElseIf rdoStandardize.Checked Then + clsPreviewTextFunction = clsDivisionOperator.Clone + clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) + ucrBase.clsRsyntax.SetBaseROperator(clsDivisionOperator) + ElseIf rdoLogical.Checked Then + clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) + clsPreviewTextFunction = clsBooleanOperator.Clone + ucrBase.clsRsyntax.SetBaseROperator(clsBooleanOperator) + Select Case ucrInputLogicOperations.GetText + Case "==" + clsBooleanOperator.SetOperation("==") + Case "<" + clsBooleanOperator.SetOperation("<") + Case "<=" + clsBooleanOperator.SetOperation("<=") + Case ">" + clsBooleanOperator.SetOperation(">") + Case ">=" + clsBooleanOperator.SetOperation(">=") + Case "!=" + clsBooleanOperator.SetOperation("!=") + Case "%in%" + clsBooleanOperator.SetOperation("%in%") + Case "is.na" + clsIsNAFunction.SetRCommand("is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + Case "!is.na" + clsIsNAFunction.SetRCommand("!is.na") + clsPreviewTextFunction = clsIsNAFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsIsNAFunction) + End Select End If - 'End If - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) - ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) - - 'clsDummyTransformFunction.AddParameter("checked", "single", iPosition:=1) - 'ucrReceiverRank.bUseFilteredData = False - 'ucrReceiverRank.SetParameterIsRFunction() - 'ucrSelectorForRank.SetItemType("column") - 'ucrReceiverRank.strSelectorHeading = "Numerics" - 'lblSelectColumns.Text = "Column:" - Else - LoopsParameters() + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoNonNegative.Checked Then + UpdateConstantParameter() + clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) + If rdoSquareRoot.Checked Then + clsPreviewTextFunction = clsSquarerootFunction.Clone + ucrBase.clsRsyntax.SetBaseRFunction(clsSquarerootFunction) + clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) + ElseIf rdoPower.Checked Then + clsPreviewTextFunction = clsPowerOperator.Clone + clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) + ucrBase.clsRsyntax.SetBaseROperator(clsPowerOperator) + ElseIf rdoLogToBase10.Checked Then + clsPreviewTextFunction = clsLogBase10Function.Clone + clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsLogBase10Function) + ElseIf rdoNaturalLog.Checked Then + clsPreviewTextFunction = clsNaturalLogFunction.Clone + clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) + ucrBase.clsRsyntax.SetBaseRFunction(clsNaturalLogFunction) + End If + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + ElseIf rdoScale.Checked Then + clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) + clsPreviewTextFunction = clsScaleAddOperator.Clone + ucrBase.clsRsyntax.SetBaseROperator(clsScaleAddOperator) + ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) + End If + + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) + ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) + Else + LoopsParameters() ucrBase.clsRsyntax.ClearCodes() ucrBase.clsRsyntax.SetAssignTo("col") ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) - 'clsDummyTransformFunction.AddParameter("checked", "multiple", iPosition:=1) - 'ucrSelectorForRank.SetItemType("column_selection") - 'ucrReceiverRank.strSelectorHeading = "Column selections" - 'lblSelectColumns.Text = "Select:" - End If + End If + 'End If SetPreviewText() UpdateNonNegativeParameters() NewDefaultName() @@ -936,50 +897,40 @@ Public Class dlgTransform End Sub Private Sub LoopsParameters() - 'ucrBase.clsRsyntax.SetBaseROperator(clsPipeOperator) If rdoRank.Checked Then clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) clsPreviewTextFunction = clsRankColsFunction.Clone clsRankColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("right", clsRFunctionParameter:=clsRankColsFunction, iPosition:=1) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsRankColsFunction, bIncludeArgumentName:=False, iPosition:=1) ElseIf rdoSort.Checked Then clsDummyTransformFunction.AddParameter("check", "sort", iPosition:=0) clsPreviewTextFunction = clsSortColsFunction.Clone clsSortColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("left", clsRFunctionParameter:=clsSortColsFunction, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSortColsFunction, bIncludeArgumentName:=False, iPosition:=1) ElseIf rdoNumeric.Checked Then clsDummyTransformFunction.AddParameter("check", "numeric", iPosition:=0) If rdoRoundOf.Checked Then clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) - clsRoundColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("round", clsRFunctionParameter:=clsRoundColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsRoundColsFunction, bIncludeArgumentName:=False) ElseIf rdoSignificantDigits.Checked Then clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) clsSignifColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsSignifColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSignifColsFunction, bIncludeArgumentName:=False) ElseIf rdoLag.Checked Then clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) clsLagColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLagColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLagColsFunction, bIncludeArgumentName:=False) ElseIf rdoLead.Checked Then clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) clsLeadColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLeadColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLeadColsFunction, bIncludeArgumentName:=False) ElseIf rdoDifference.Checked Then clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) - clsConcDiffColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsConcDiffColsFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsConcDiffColsFunction, bIncludeArgumentName:=False) ElseIf rdoStandardize.Checked Then clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) @@ -987,12 +938,10 @@ Public Class dlgTransform clsMeanColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsStandardDevColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsDivisionColsOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsDivisionColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogical.Checked Then clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) clsBooleanColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsBooleanColsOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsBooleanColsOperator, bIncludeArgumentName:=False) Select Case ucrInputLogicOperations.GetText Case "==" @@ -1028,7 +977,6 @@ Public Class dlgTransform clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) clsSquarerootColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsSquarerootFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSquarerootColsFunction, bIncludeArgumentName:=False) ElseIf rdoPower.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) @@ -1036,27 +984,23 @@ Public Class dlgTransform clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) clsPowerColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsPowerOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsPowerColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogToBase10.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) clsLogBase10ColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsLogBase10Function, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLogBase10ColsFunction, bIncludeArgumentName:=False) ElseIf rdoNaturalLog.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) clsNaturalLogColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsRFunctionParameter:=clsNaturalLogFunction, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsNaturalLogColsFunction, bIncludeArgumentName:=False) End If ElseIf rdoScale.Checked Then clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) clsScaleAddColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - 'clsTildaOperator.AddParameter("sig", clsROperatorParameter:=clsScaleAddOperator, iPosition:=1, bIncludeArgumentName:=False) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) End If @@ -1183,8 +1127,6 @@ Public Class dlgTransform lblSelectColumns.Text = "Select:" ElseIf rdoSingle.Checked Then clsDummyTransformFunction.AddParameter("col", "single", iPosition:=0) - 'ucrReceiverRank.bUseFilteredData = False - 'ucrReceiverRank.SetParameterIsRFunction() ucrSelectorForRank.SetItemType("column") ucrReceiverRank.strSelectorHeading = "Numerics" lblSelectColumns.Text = "Column:" From c9eac72364b668abe1cbbf7bf423cd3961adea80 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:12:14 +0100 Subject: [PATCH 07/30] Code Changes --- instat/dlgTransform.vb | 57 +++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index d444cef62be..4d95a922d81 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -526,13 +526,13 @@ Public Class dlgTransform clsLeadColsFunction.SetPackageName("~dplyr") clsLeadColsFunction.SetRCommand("lead") - clsDiffColsFunction.SetRCommand("~diff") + clsDiffColsFunction.SetRCommand("diff") clsDiffColsFunction.AddParameter("lag", "1", iPosition:=1) - clsReplicateColsFunction.SetRCommand("~rep") + clsReplicateColsFunction.SetRCommand("rep") clsReplicateColsFunction.AddParameter("x", "NA", iPosition:=0) - clsConcDiffColsFunction.SetRCommand("c") + clsConcDiffColsFunction.SetRCommand("~c") clsConcDiffColsFunction.AddParameter("y", clsRFunctionParameter:=clsReplicateColsFunction, iPosition:=0, bIncludeArgumentName:=False) clsConcDiffColsFunction.AddParameter("x", clsRFunctionParameter:=clsDiffColsFunction, iPosition:=1, bIncludeArgumentName:=False) @@ -559,7 +559,6 @@ Public Class dlgTransform clsLogBase10ColsFunction.SetRCommand("~log10") clsPowerColsOperator.SetOperation("^") - clsPowerColsOperator.AddParameter("y", "1", iPosition:=1) clsPowerColsOperator.bSpaceAroundOperation = False clsScaleMeanColsFunction.SetRCommand("~mean") @@ -651,7 +650,7 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevFunction, New RParameter("x", 0), iAdditionalPairNo:=9) ucrNudDiffLag.AddAdditionalCodeParameterPair(clsReplicateFunction, New RParameter("times", 1), iAdditionalPairNo:=1) ucrNudDiffLag.AddAdditionalCodeParameterPair(clsReplicateColsFunction, New RParameter("times", 1), iAdditionalPairNo:=2) - ucrNudDiffLag.AddAdditionalCodeParameterPair(clsDiffColsFunction, New RParameter("times", 1), iAdditionalPairNo:=3) + ucrNudDiffLag.AddAdditionalCodeParameterPair(clsDiffColsFunction, New RParameter("lag", 1), iAdditionalPairNo:=3) ucrNudLagLeadPosition.AddAdditionalCodeParameterPair(clsLeadColsFunction, New RParameter("n", 1), iAdditionalPairNo:=1) ucrNudLagPosition.AddAdditionalCodeParameterPair(clsLagColsFunction, New RParameter("lag", 1), iAdditionalPairNo:=1) ucrNudSignifDigits.AddAdditionalCodeParameterPair(clsSignifColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) @@ -693,6 +692,8 @@ Public Class dlgTransform ucrPnlMissingValues.AddAdditionalCodeParameterPair(clsRankColsFunction, New RParameter("na.last", 2), iAdditionalPairNo:=1) ucrChkMissingLast.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("na.last", 1), iAdditionalPairNo:=1) ucrChkDecreasing.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("decreasing", 2), iAdditionalPairNo:=1) + ucrInputLogicalValues.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 1), iAdditionalPairNo:=1) + ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) ucrSaveNew.AddAdditionalRCode(clsSignifFunction, iAdditionalPairNo:=3) @@ -732,7 +733,7 @@ Public Class dlgTransform ucrPnlNonNegative.SetRCode(clsNonNegativeDummyFunction, bReset) ucrChkOmitNA.SetRCode(clsMeanFunction, bReset) ucrChkPreview.SetRCode(clsConstantDummyFunction, bReset) - + ucrInputLogicalValues.SetRCode(clsBooleanOperator, bReset) If bReset Then ucrReceiverRank.SetRCode(clsRankFunction, bReset) End If @@ -741,13 +742,21 @@ Public Class dlgTransform Private Sub TestOKEnabled() If rdoNumeric.Checked AndAlso rdoLogical.Checked Then - If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete AndAlso Not ucrInputLogicalValues.IsEmpty) + If rdoSingle.Checked Then + If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete AndAlso Not ucrInputLogicalValues.IsEmpty) + Else + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) + End If + ElseIf rdoMultiple.Checked Then + If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso Not ucrInputLogicalValues.IsEmpty) + Else + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) + End If Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) End If - Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) End If End Sub @@ -930,7 +939,7 @@ Public Class dlgTransform clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLeadColsFunction, bIncludeArgumentName:=False) ElseIf rdoDifference.Checked Then clsNumericDummyFunction.AddParameter("check", "diff", iPosition:=0) - clsConcDiffColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsDiffColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsConcDiffColsFunction, bIncludeArgumentName:=False) ElseIf rdoStandardize.Checked Then clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) @@ -941,7 +950,7 @@ Public Class dlgTransform clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsDivisionColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogical.Checked Then clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) - clsBooleanColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsBooleanColsOperator.AddParameter("x", "~.x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsBooleanColsOperator, bIncludeArgumentName:=False) Select Case ucrInputLogicOperations.GetText Case "==" @@ -979,11 +988,11 @@ Public Class dlgTransform clsSquarerootColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSquarerootColsFunction, bIncludeArgumentName:=False) ElseIf rdoPower.Checked Then - clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) + clsPowerColsOperator.AddParameter("y", ucrInputPower.GetText, iPosition:=1) - clsPowerColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsPowerColsOperator.AddParameter("x", "~.", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsPowerColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogToBase10.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) @@ -1087,11 +1096,19 @@ Public Class dlgTransform SetPreviewText() End Sub - Private Sub ucrInputLogicalValues_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLogicalValues.ControlValueChanged - If Not ucrInputLogicalValues.IsEmpty Then - clsBooleanOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) - Else - clsBooleanOperator.RemoveParameterByName("right") + Private Sub ucrInputLogicalValues_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLogicalValues.ControlValueChanged, ucrInputLogicOperations.ControlValueChanged + If rdoSingle.Checked Then + If Not ucrInputLogicalValues.IsEmpty Then + clsBooleanOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) + Else + clsBooleanOperator.RemoveParameterByName("right") + End If + ElseIf rdoMultiple.Checked Then + If Not ucrInputLogicalValues.IsEmpty Then + clsBooleanColsOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) + Else + clsBooleanColsOperator.RemoveParameterByName("right") + End If End If End Sub From bbf332eb7122316a64920b5df2d7711080d60654 Mon Sep 17 00:00:00 2001 From: Barbra2020 Date: Wed, 20 Mar 2024 14:13:48 +0300 Subject: [PATCH 08/30] changes to the code --- instat/dlgTransform.vb | 97 ++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 31 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 4d95a922d81..baf11d2ff71 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -64,7 +64,9 @@ Public Class dlgTransform Private clsPowerOperator As New ROperator Private clsScaleSubtractOperator As New ROperator Private clsScaleMultiplyOperator As New ROperator + Private clsScaleMultiplyColsOperator As New ROperator Private clsScaleDivideOperator As New ROperator + Private clsScaleDivideColsOperator As New ROperator Private clsScaleAddOperator As New ROperator Private clsScaleMeanFunction As New RFunction Private clsScaleMinFunction As New RFunction @@ -375,6 +377,7 @@ Public Class dlgTransform clsScaleAddOperator = New ROperator clsScaleDivideOperator = New ROperator clsScaleMultiplyOperator = New ROperator + clsScaleMultiplyColsOperator = New ROperator clsScaleSubtractOperator = New ROperator clsPreviewOperator = New ROperator clsScaleMeanFunction = New RFunction @@ -536,18 +539,20 @@ Public Class dlgTransform clsConcDiffColsFunction.AddParameter("y", clsRFunctionParameter:=clsReplicateColsFunction, iPosition:=0, bIncludeArgumentName:=False) clsConcDiffColsFunction.AddParameter("x", clsRFunctionParameter:=clsDiffColsFunction, iPosition:=1, bIncludeArgumentName:=False) - clsMeanColsFunction.SetRCommand("~mean") + clsMeanColsFunction.SetRCommand("mean") clsMeanColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) - clsStandardDevColsFunction.SetRCommand("~sd") + clsStandardDevColsFunction.SetRCommand("sd") clsStandardDevColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) clsSubtractColsOperator.SetOperation("-") + clsSubtractColsOperator.AddParameter("left", "~.x", iPosition:=0) clsSubtractColsOperator.AddParameter("y", clsRFunctionParameter:=clsMeanColsFunction, iPosition:=1) clsDivisionColsOperator.SetOperation("/") clsDivisionColsOperator.AddParameter("x", clsROperatorParameter:=clsSubtractColsOperator, iPosition:=0) clsDivisionColsOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevColsFunction, iPosition:=1) + clsDivisionColsOperator.bBrackets = False clsSquarerootColsFunction.SetRCommand("~sqrt") @@ -567,20 +572,21 @@ Public Class dlgTransform clsScaleMinColsFunction.SetRCommand("~min") clsScaleMinColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) - clsScaleSubtractOperator.SetOperation("-") - clsScaleSubtractOperator.AddParameter("u", "0", iPosition:=1) + clsScaleSubtractColsOperator.SetOperation("-") + clsScaleSubtractColsOperator.AddParameter("u", "0", iPosition:=1) - clsScaleMultiplyOperator.SetOperation("*") - clsScaleMultiplyOperator.AddParameter("x", clsROperatorParameter:=clsScaleSubtractOperator, iPosition:=0) - clsScaleMultiplyOperator.AddParameter("y", "1", iPosition:=1) + clsScaleMultiplyColsOperator.SetOperation("*") + clsScaleMultiplyColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleSubtractColsOperator, iPosition:=0) + clsScaleMultiplyColsOperator.AddParameter("y", "1", iPosition:=1) + clsScaleMultiplyColsOperator.bBrackets = False - clsScaleDivideOperator.SetOperation("/") - clsScaleDivideOperator.AddParameter("x", clsROperatorParameter:=clsScaleMultiplyOperator, iPosition:=0) - clsScaleDivideOperator.AddParameter("z", "1", iPosition:=1) - clsScaleDivideOperator.bBrackets = False + clsScaleDivideColsOperator.SetOperation("/") + clsScaleDivideColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleMultiplyColsOperator, iPosition:=0) + clsScaleDivideColsOperator.AddParameter("z", "1", iPosition:=1) + clsScaleDivideColsOperator.bBrackets = False clsScaleAddColsOperator.SetOperation("+") - clsScaleAddColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleDivideOperator, iPosition:=0) + clsScaleAddColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleDivideColsOperator, iPosition:=0) clsScaleAddColsOperator.AddParameter("v", "0", iPosition:=1) clsScaleAddColsOperator.bBrackets = False @@ -671,16 +677,16 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsLeadColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=22) ucrReceiverRank.AddAdditionalCodeParameterPair(clsDiffColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=23) ucrReceiverRank.AddAdditionalCodeParameterPair(clsMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=24) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=25) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, New RParameter("x", 0), iAdditionalPairNo:=26) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsRankColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=27) + 'ucrReceiverRank.AddAdditionalCodeParameterPair(clsSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=25) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, New RParameter("x", 0), iAdditionalPairNo:=25) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsRankColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=26) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsAddConstantColsOperator, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=28) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=29) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=30) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinColsFunction, New RParameter("x", 0), iAdditionalPairNo:=31) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 0), iAdditionalPairNo:=32) - ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAColsFunction, New RParameter("x", 0), iAdditionalPairNo:=33) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsAddConstantColsOperator, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=27) + 'ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=28) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=28) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinColsFunction, New RParameter("x", 0), iAdditionalPairNo:=29) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 0), iAdditionalPairNo:=30) + ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAColsFunction, New RParameter("x", 0), iAdditionalPairNo:=31) ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) @@ -692,7 +698,12 @@ Public Class dlgTransform ucrPnlMissingValues.AddAdditionalCodeParameterPair(clsRankColsFunction, New RParameter("na.last", 2), iAdditionalPairNo:=1) ucrChkMissingLast.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("na.last", 1), iAdditionalPairNo:=1) ucrChkDecreasing.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("decreasing", 2), iAdditionalPairNo:=1) - ucrInputLogicalValues.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 1), iAdditionalPairNo:=1) + 'ucrInputLogicalValues.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 1), iAdditionalPairNo:=1) + ucrInputMultiply.AddAdditionalCodeParameterPair(clsScaleMultiplyColsOperator, New RParameter("y", 1), iAdditionalPairNo:=1) + ucrInputDivide.AddAdditionalCodeParameterPair(clsScaleDivideColsOperator, New RParameter("z", 1), iAdditionalPairNo:=1) + ucrInputAdd.AddAdditionalCodeParameterPair(clsScaleAddColsOperator, New RParameter("v", 1), iAdditionalPairNo:=1) + ucrInputSubtract.AddAdditionalCodeParameterPair(clsScaleSubtractColsOperator, New RParameter("u", 1), iAdditionalPairNo:=1) + ucrInputConstant.AddAdditionalCodeParameterPair(clsAddConstantColsOperator, New RParameter("c", 1), iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLeadFunction, iAdditionalPairNo:=1) ucrSaveNew.AddAdditionalRCode(clsLagFunction, iAdditionalPairNo:=2) @@ -733,7 +744,7 @@ Public Class dlgTransform ucrPnlNonNegative.SetRCode(clsNonNegativeDummyFunction, bReset) ucrChkOmitNA.SetRCode(clsMeanFunction, bReset) ucrChkPreview.SetRCode(clsConstantDummyFunction, bReset) - ucrInputLogicalValues.SetRCode(clsBooleanOperator, bReset) + 'ucrInputLogicalValues.SetRCode(clsBooleanOperator, bReset) If bReset Then ucrReceiverRank.SetRCode(clsRankFunction, bReset) End If @@ -752,7 +763,7 @@ Public Class dlgTransform If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso Not ucrInputLogicalValues.IsEmpty) Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) End If Else ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) @@ -890,11 +901,11 @@ Public Class dlgTransform ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) Else LoopsParameters() - ucrBase.clsRsyntax.ClearCodes() - ucrBase.clsRsyntax.SetAssignTo("col") - ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) - ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) - ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) + ucrBase.clsRsyntax.ClearCodes() + ucrBase.clsRsyntax.SetAssignTo("col") + ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) + ucrBase.clsRsyntax.AddToAfterCodes(clsAssignOperator, 1) + ucrBase.clsRsyntax.AddToAfterCodes(clsAddColumnsFunction, 2) End If @@ -903,6 +914,7 @@ Public Class dlgTransform UpdateNonNegativeParameters() NewDefaultName() ResetPreview() + AddRemoveLogicalValues() End Sub Private Sub LoopsParameters() @@ -1009,7 +1021,7 @@ Public Class dlgTransform ElseIf rdoScale.Checked Then clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) - clsScaleAddColsOperator.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) + clsScaleSubtractColsOperator.AddParameter("left", "~.x", iPosition:=0) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) End If @@ -1094,21 +1106,43 @@ Public Class dlgTransform Private Sub ucrInputLogicalValues_TextChanged(sender As Object, e As EventArgs) Handles ucrInputLogicalValues.TextChanged SetPreviewText() + AddRemoveLogicalValues() + End Sub + + Private Sub ucrInputLogicalValues_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLogicalValues.ControlValueChanged + 'If rdoSingle.Checked Then + ' If Not ucrInputLogicalValues.IsEmpty Then + ' clsBooleanOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) + ' Else + ' clsBooleanOperator.RemoveParameterByName("right") + ' End If + 'ElseIf rdoMultiple.Checked Then + ' If Not ucrInputLogicalValues.IsEmpty Then + ' clsBooleanColsOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) + ' Else + ' clsBooleanColsOperator.RemoveParameterByName("right") + ' End If + 'End If + AddRemoveLogicalValues() End Sub - Private Sub ucrInputLogicalValues_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLogicalValues.ControlValueChanged, ucrInputLogicOperations.ControlValueChanged + Private Sub AddRemoveLogicalValues() If rdoSingle.Checked Then If Not ucrInputLogicalValues.IsEmpty Then clsBooleanOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) Else clsBooleanOperator.RemoveParameterByName("right") End If + clsBooleanColsOperator.RemoveParameterByName("right") + ElseIf rdoMultiple.Checked Then If Not ucrInputLogicalValues.IsEmpty Then clsBooleanColsOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) Else clsBooleanColsOperator.RemoveParameterByName("right") End If + clsBooleanOperator.RemoveParameterByName("right") + End If End Sub @@ -1148,5 +1182,6 @@ Public Class dlgTransform ucrReceiverRank.strSelectorHeading = "Numerics" lblSelectColumns.Text = "Column:" End If + AddRemoveLogicalValues() End Sub End Class \ No newline at end of file From e7647712847abe7738a7d4a148d95762f634974b Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:01:56 +0100 Subject: [PATCH 09/30] Fixed the preview issue and scale operator issue --- instat/dlgTransform.Designer.vb | 12 ---- instat/dlgTransform.vb | 97 ++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/instat/dlgTransform.Designer.vb b/instat/dlgTransform.Designer.vb index b0115e8bf16..0650f55b907 100644 --- a/instat/dlgTransform.Designer.vb +++ b/instat/dlgTransform.Designer.vb @@ -111,7 +111,6 @@ Partial Class dlgTransform Me.ucrPnlColumnSelectOptions = New instat.UcrPanel() Me.rdoSingle = New System.Windows.Forms.RadioButton() Me.rdoMultiple = New System.Windows.Forms.RadioButton() - Me.ucrNewColName = New instat.ucrSave() Me.grpTies.SuspendLayout() Me.grpMissingValues.SuspendLayout() Me.grpNumericOptions.SuspendLayout() @@ -963,22 +962,12 @@ Partial Class dlgTransform Me.rdoMultiple.Text = "Multiple" Me.rdoMultiple.UseVisualStyleBackColor = True ' - 'ucrNewColName - ' - Me.ucrNewColName.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink - Me.ucrNewColName.Location = New System.Drawing.Point(10, 368) - Me.ucrNewColName.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5) - Me.ucrNewColName.Name = "ucrNewColName" - Me.ucrNewColName.Size = New System.Drawing.Size(331, 22) - Me.ucrNewColName.TabIndex = 69 - ' 'dlgTransform ' 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(440, 445) - Me.Controls.Add(Me.ucrNewColName) Me.Controls.Add(Me.rdoMultiple) Me.Controls.Add(Me.rdoSingle) Me.Controls.Add(Me.ucrPnlColumnSelectOptions) @@ -1102,5 +1091,4 @@ Partial Class dlgTransform Friend WithEvents rdoMultiple As RadioButton Friend WithEvents rdoSingle As RadioButton Friend WithEvents ucrPnlColumnSelectOptions As UcrPanel - Friend WithEvents ucrNewColName As ucrSave End Class diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index baf11d2ff71..8ccb377a1a5 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -195,7 +195,7 @@ Public Class dlgTransform ucrPnlNonNegative.AddParameterValuesCondition(rdoNaturalLog, "check", "log") ucrPnlNonNegative.AddParameterValuesCondition(rdoPower, "check", "power") - ucrPnlColumnSelectOptions.AddToLinkedControls(ucrSaveNew, {rdoSingle}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlColumnSelectOptions.AddToLinkedControls(ucrChkPreview, {rdoSingle}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudSignifDigits, {rdoSignificantDigits}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudRoundOfDigits, {rdoRoundOf}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlNumericOptions.AddToLinkedControls(ucrNudLagLeadPosition, {rdoLead}, bNewLinkedHideIfParameterMissing:=True) @@ -299,6 +299,8 @@ Public Class dlgTransform ucrInputSubtract.AddQuotesIfUnrecognised = False ucrChkSubtract.SetText("Subtract") + ucrChkSubtract.AddParameterValuesCondition(True, "subtract", "True") + ucrChkSubtract.AddParameterValuesCondition(False, "subtract", "False") ucrInputMultiply.SetParameter(New RParameter("y", 1)) dctMultiplyValues.Add("1", "1") @@ -312,6 +314,8 @@ Public Class dlgTransform ucrInputMultiply.AddQuotesIfUnrecognised = False ucrChkMultiply.SetText("Multiply") + ucrChkMultiply.AddParameterValuesCondition(True, "multiple", "True") + ucrChkMultiply.AddParameterValuesCondition(False, "multiple", "False") ucrInputDivide.SetParameter(New RParameter("z", 1)) dctDivideValues.Add("1", "1") @@ -324,6 +328,8 @@ Public Class dlgTransform ucrInputDivide.AddQuotesIfUnrecognised = False ucrChkDivide.SetText("Divide") + ucrChkDivide.AddParameterValuesCondition(True, "divide", "True") + ucrChkDivide.AddParameterValuesCondition(False, "divide", "False") ucrInputAdd.SetParameter(New RParameter("v", 1)) dctAddValues.Add("0", "0") @@ -333,18 +339,13 @@ Public Class dlgTransform ucrInputAdd.AddQuotesIfUnrecognised = False ucrChkAdd.SetText("Add") + ucrChkAdd.AddParameterValuesCondition(True, "add", "True") + ucrChkAdd.AddParameterValuesCondition(False, "add", "False") ucrChkPreview.SetText("Preview") ucrChkPreview.AddParameterValuesCondition(True, "preview", "FALSE") ucrChkPreview.AddParameterValuesCondition(False, "preview", "TRUE") - 'ucrNewColName - ucrNewColName.SetIsComboBox() - ucrNewColName.SetSaveTypeAsColumn() - ucrNewColName.SetDataFrameSelector(ucrSelectorForRank.ucrAvailableDataFrames) - ucrNewColName.SetLabelText("New Column:") - ucrNewColName.setLinkedReceiver(ucrReceiverRank) - ucrChkOmitNA.SetText("Omit NA") ucrChkOmitNA.SetParameter(New RParameter("na.rm", 1)) ucrChkOmitNA.SetValuesCheckedAndUnchecked("TRUE", "FALSE") @@ -417,11 +418,8 @@ Public Class dlgTransform ucrSelectorForRank.Reset() ucrReceiverRank.SetMeAsReceiver() ucrSaveNew.Reset() - ucrNewColName.Reset() ucrInputLogicOperations.SetText("==") rdoSingle.Checked = True - ucrNewColName.Visible = False - rdoMultiple.Checked = ucrNewColName.Visible clsConstantDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsConstantDummyFunction.AddParameter("preview", "TRUE", iPosition:=1) @@ -593,7 +591,6 @@ Public Class dlgTransform clsBooleanColsOperator.SetOperation("==") clsIsNAColsFunction.SetRCommand("is.na") - clsGetDataFrameFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame") clsMutateFunction.SetPackageName("dplyr") @@ -621,6 +618,11 @@ Public Class dlgTransform clsDummyTransformFunction.AddParameter("col", "single", iPosition:=1) clsNumericDummyFunction.AddParameter("check", "round", iPosition:=0) + clsNumericDummyFunction.AddParameter("multiple", "False", iPosition:=1) + clsNumericDummyFunction.AddParameter("divide", "False", iPosition:=2) + clsNumericDummyFunction.AddParameter("add", "False", iPosition:=3) + clsNumericDummyFunction.AddParameter("subtract", "False", iPosition:=4) + clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) clsColumnsFunction.SetRCommand("colnames") @@ -638,8 +640,6 @@ Public Class dlgTransform clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsAddColumnsFunction.AddParameter("before", "FALSE", iPosition:=2) - - 'ucrBase.clsRsyntax.SetBaseRFunction(clsRoundFunction) End Sub Private Sub SetRCodeForControls(bReset As Boolean) @@ -677,18 +677,15 @@ Public Class dlgTransform ucrReceiverRank.AddAdditionalCodeParameterPair(clsLeadColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=22) ucrReceiverRank.AddAdditionalCodeParameterPair(clsDiffColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=23) ucrReceiverRank.AddAdditionalCodeParameterPair(clsMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=24) - 'ucrReceiverRank.AddAdditionalCodeParameterPair(clsSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=25) ucrReceiverRank.AddAdditionalCodeParameterPair(clsStandardDevColsFunction, New RParameter("x", 0), iAdditionalPairNo:=25) ucrReceiverRank.AddAdditionalCodeParameterPair(clsRankColsFunction, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=26) ucrReceiverRank.AddAdditionalCodeParameterPair(clsAddConstantColsOperator, ucrReceiverRank.GetParameter(), iAdditionalPairNo:=27) - 'ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleSubtractColsOperator, New RParameter("x", 0), iAdditionalPairNo:=28) ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMeanColsFunction, New RParameter("x", 0), iAdditionalPairNo:=28) ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinColsFunction, New RParameter("x", 0), iAdditionalPairNo:=29) ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 0), iAdditionalPairNo:=30) ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAColsFunction, New RParameter("x", 0), iAdditionalPairNo:=31) - ucrChkOmitNA.AddAdditionalCodeParameterPair(clsStandardDevFunction, ucrChkOmitNA.GetParameter(), iAdditionalPairNo:=1) ucrSelectorForRank.AddAdditionalCodeParameterPair(clsGetColSelectionNamesFunction, ucrSelectorForRank.GetParameter, iAdditionalPairNo:=1) ucrNudRoundOfDigits.AddAdditionalCodeParameterPair(clsRoundColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1) @@ -698,7 +695,6 @@ Public Class dlgTransform ucrPnlMissingValues.AddAdditionalCodeParameterPair(clsRankColsFunction, New RParameter("na.last", 2), iAdditionalPairNo:=1) ucrChkMissingLast.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("na.last", 1), iAdditionalPairNo:=1) ucrChkDecreasing.AddAdditionalCodeParameterPair(clsSortColsFunction, New RParameter("decreasing", 2), iAdditionalPairNo:=1) - 'ucrInputLogicalValues.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 1), iAdditionalPairNo:=1) ucrInputMultiply.AddAdditionalCodeParameterPair(clsScaleMultiplyColsOperator, New RParameter("y", 1), iAdditionalPairNo:=1) ucrInputDivide.AddAdditionalCodeParameterPair(clsScaleDivideColsOperator, New RParameter("z", 1), iAdditionalPairNo:=1) ucrInputAdd.AddAdditionalCodeParameterPair(clsScaleAddColsOperator, New RParameter("v", 1), iAdditionalPairNo:=1) @@ -744,9 +740,13 @@ Public Class dlgTransform ucrPnlNonNegative.SetRCode(clsNonNegativeDummyFunction, bReset) ucrChkOmitNA.SetRCode(clsMeanFunction, bReset) ucrChkPreview.SetRCode(clsConstantDummyFunction, bReset) - 'ucrInputLogicalValues.SetRCode(clsBooleanOperator, bReset) + If bReset Then ucrReceiverRank.SetRCode(clsRankFunction, bReset) + ucrChkDivide.SetRCode(clsNumericDummyFunction, bReset) + ucrChkAdd.SetRCode(clsNumericDummyFunction, bReset) + ucrChkMultiply.SetRCode(clsNumericDummyFunction, bReset) + ucrChkSubtract.SetRCode(clsNumericDummyFunction, bReset) End If bResetRCode = True End Sub @@ -777,8 +777,10 @@ Public Class dlgTransform ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) End If ElseIf rdoMultiple.Checked Then - If Not ucrReceiverRank.IsEmpty Then - clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & "transformed" & Chr(34), iPosition:=1, bIncludeArgumentName:=False) + If Not ucrReceiverRank.IsEmpty AndAlso (Not ucrSaveNew.bUserTyped) Then + Dim strDataframeName As String = ucrReceiverRank.GetVariableNames(bWithQuotes:=False) + ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) + clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & strDataframeName & Chr(34), iPosition:=1, bIncludeArgumentName:=False) clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If @@ -799,8 +801,6 @@ Public Class dlgTransform ucrChkMissingLast.ControlValueChanged, ucrChkDecreasing.ControlValueChanged, ucrChkDivide.ControlValueChanged, ucrChkAdd.ControlValueChanged, ucrChkMultiply.ControlValueChanged, ucrChkSubtract.ControlValueChanged ucrBase.clsRsyntax.ClearCodes() - 'If bResetRCode Then - If rdoSingle.Checked Then If rdoRank.Checked Then @@ -909,7 +909,6 @@ Public Class dlgTransform End If - 'End If SetPreviewText() UpdateNonNegativeParameters() NewDefaultName() @@ -1110,19 +1109,6 @@ Public Class dlgTransform End Sub Private Sub ucrInputLogicalValues_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInputLogicalValues.ControlValueChanged - 'If rdoSingle.Checked Then - ' If Not ucrInputLogicalValues.IsEmpty Then - ' clsBooleanOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) - ' Else - ' clsBooleanOperator.RemoveParameterByName("right") - ' End If - 'ElseIf rdoMultiple.Checked Then - ' If Not ucrInputLogicalValues.IsEmpty Then - ' clsBooleanColsOperator.AddParameter("right", ucrInputLogicalValues.GetText, iPosition:=1) - ' Else - ' clsBooleanColsOperator.RemoveParameterByName("right") - ' End If - 'End If AddRemoveLogicalValues() End Sub @@ -1164,7 +1150,6 @@ Public Class dlgTransform End Sub Private Sub ucrPnlColumnSelectOptions_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlColumnSelectOptions.ControlValueChanged, ucrReceiverRank.ControlValueChanged, ucrSelectorForRank.ControlValueChanged - clsGetDataFrameFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.strCurrentDataFrame & Chr(34), iPosition:=0, bIncludeArgumentName:=False) clsGetDataFrameFunction.AddParameter("column_selection_name ", ucrReceiverRank.GetVariableNames, iPosition:=1) clsGetDataFrameFunction.SetAssignTo(ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text) @@ -1184,4 +1169,40 @@ Public Class dlgTransform End If AddRemoveLogicalValues() End Sub + + Private Sub ucrChkMultiply_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkMultiply.ControlValueChanged, ucrInputMultiply.ControlValueChanged + If ucrChkMultiply.Checked AndAlso Not ucrInputMultiply.IsEmpty Then + clsScaleMultiplyColsOperator.AddParameter("y", ucrInputMultiply.GetText, iPosition:=1) + + Else + clsScaleMultiplyColsOperator.RemoveParameterByName("y") + End If + End Sub + + Private Sub ucrChkAdd_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkAdd.ControlValueChanged, ucrInputAdd.ControlValueChanged + If ucrChkAdd.Checked AndAlso Not ucrInputAdd.IsEmpty Then + clsScaleAddColsOperator.AddParameter("v", ucrInputAdd.GetText, iPosition:=1) + + Else + clsScaleAddColsOperator.RemoveParameterByName("v") + End If + End Sub + + Private Sub ucrChkSubtract_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSubtract.ControlValueChanged, ucrInputSubtract.ControlValueChanged + If ucrChkSubtract.Checked AndAlso Not ucrInputSubtract.IsEmpty Then + clsScaleSubtractColsOperator.AddParameter("u", ucrInputSubtract.GetText, iPosition:=1) + + Else + clsScaleSubtractColsOperator.RemoveParameterByName("u") + End If + End Sub + + Private Sub ucrChkDivide_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkDivide.ControlValueChanged, ucrInputDivide.ControlValueChanged + If ucrChkDivide.Checked AndAlso Not ucrInputDivide.IsEmpty Then + clsScaleDivideColsOperator.AddParameter("z", ucrInputDivide.GetText, iPosition:=1) + + Else + clsScaleDivideColsOperator.RemoveParameterByName("z") + End If + End Sub End Class \ No newline at end of file From 31a723770ebd8ea6c5f24ecc3ab6ebb457cf6602 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:08:34 +0100 Subject: [PATCH 10/30] Changing the label text for ucrSave when switch between single and multiple recevier --- instat/dlgTransform.vb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 8ccb377a1a5..ad07416567b 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -773,10 +773,12 @@ Public Class dlgTransform Private Sub NewDefaultName() If rdoSingle.Checked Then + ucrSaveNew.SetLabelText("New Column Name:") If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) End If ElseIf rdoMultiple.Checked Then + ucrSaveNew.SetLabelText("Suffix Name:") If Not ucrReceiverRank.IsEmpty AndAlso (Not ucrSaveNew.bUserTyped) Then Dim strDataframeName As String = ucrReceiverRank.GetVariableNames(bWithQuotes:=False) ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) From b03f5ed0bf399c399f4acd2b570b110114e6101d Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:06:17 +0100 Subject: [PATCH 11/30] Code Changes --- instat/dlgTransform.vb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index ad07416567b..79e1ad6fe20 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -721,7 +721,7 @@ Public Class dlgTransform ucrPnlColumnSelectOptions.SetRCode(clsDummyTransformFunction, bReset) ucrChkDecreasing.SetRCode(clsSortFunction, bReset) ucrChkMissingLast.SetRCode(clsSortFunction, bReset) - ucrSaveNew.SetRCode(clsRoundFunction, bReset) + ucrPnlTies.SetRCode(clsRankFunction, bReset) ucrPnlMissingValues.SetRCode(clsRankFunction, bReset) ucrNudRoundOfDigits.SetRCode(clsRoundFunction, bReset) @@ -747,6 +747,7 @@ Public Class dlgTransform ucrChkAdd.SetRCode(clsNumericDummyFunction, bReset) ucrChkMultiply.SetRCode(clsNumericDummyFunction, bReset) ucrChkSubtract.SetRCode(clsNumericDummyFunction, bReset) + ucrSaveNew.SetRCode(clsRoundFunction, bReset) End If bResetRCode = True End Sub @@ -779,11 +780,9 @@ Public Class dlgTransform End If ElseIf rdoMultiple.Checked Then ucrSaveNew.SetLabelText("Suffix Name:") + ucrSaveNew.btnColumnPosition.Visible = False If Not ucrReceiverRank.IsEmpty AndAlso (Not ucrSaveNew.bUserTyped) Then - Dim strDataframeName As String = ucrReceiverRank.GetVariableNames(bWithQuotes:=False) ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) - clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & strDataframeName & Chr(34), iPosition:=1, bIncludeArgumentName:=False) - clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If End If @@ -1141,6 +1140,8 @@ Public Class dlgTransform Private Sub ucrSaveNew_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSaveNew.ControlValueChanged If ucrSaveNew.GetText <> "" AndAlso ucrSaveNew.IsComplete() Then clsRemoveLabelsFunction.AddParameter("col_names", Chr(34) & ucrSaveNew.GetText & Chr(34), iPosition:=1) + clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & ucrSaveNew.GetText & Chr(34), iPosition:=1, bIncludeArgumentName:=False) + End If End Sub From f2142bc60a691b2c2f1c5322c41d707dfedc4fa2 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:16:07 +0100 Subject: [PATCH 12/30] code Changes --- instat/dlgTransform.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 79e1ad6fe20..30c868bd016 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -782,7 +782,7 @@ Public Class dlgTransform ucrSaveNew.SetLabelText("Suffix Name:") ucrSaveNew.btnColumnPosition.Visible = False If Not ucrReceiverRank.IsEmpty AndAlso (Not ucrSaveNew.bUserTyped) Then - ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) + clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If End If From 56db3d4a55d0392741588e94198ffc15aff2ebf3 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:32:17 +0100 Subject: [PATCH 13/30] Code changes to TestOk --- instat/dlgTransform.vb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 30c868bd016..18a169332fc 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -754,21 +754,14 @@ Public Class dlgTransform Private Sub TestOKEnabled() If rdoNumeric.Checked AndAlso rdoLogical.Checked Then - If rdoSingle.Checked Then - If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete AndAlso Not ucrInputLogicalValues.IsEmpty) - Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) - End If - ElseIf rdoMultiple.Checked Then - If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso Not ucrInputLogicalValues.IsEmpty) - Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) - End If + If Not ucrInputLogicOperations.GetText = "is.na" AndAlso Not ucrInputLogicOperations.GetText = "!is.na" Then + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete AndAlso Not ucrInputLogicalValues.IsEmpty) Else - ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty() AndAlso ucrSaveNew.IsComplete) End If + + Else + ucrBase.OKEnabled(Not ucrReceiverRank.IsEmpty()) End If End Sub From 83b1bfdf17e0d74d83267d74a56c9b5791ecb174 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 10:16:30 +0100 Subject: [PATCH 14/30] Change made --- instat/dlgClimograph.Designer.vb | 283 ++++++++++++++++++++++++++++++- 1 file changed, 282 insertions(+), 1 deletion(-) diff --git a/instat/dlgClimograph.Designer.vb b/instat/dlgClimograph.Designer.vb index cff96c37a9b..241a4a22a6c 100644 --- a/instat/dlgClimograph.Designer.vb +++ b/instat/dlgClimograph.Designer.vb @@ -22,13 +22,273 @@ Partial Class dlgClimograph 'Ne la modifiez pas à l'aide de l'éditeur de code. _ Private Sub InitializeComponent() + Me.ucrReceiverAbsolute = New instat.ucrReceiverSingle() + Me.lblAbsolute = New System.Windows.Forms.Label() + Me.ucrInputStation = New instat.ucrInputComboBox() + Me.ucr1stFactorReceiver = New instat.ucrReceiverSingle() + Me.lblFacetBy = New System.Windows.Forms.Label() + Me.ucrReceiverRain = New instat.ucrReceiverSingle() + Me.lblRain = New System.Windows.Forms.Label() + Me.ucrReceiverMaxtem = New instat.ucrReceiverSingle() + Me.lblMaxtem = New System.Windows.Forms.Label() + Me.ucrReceiverMintemp = New instat.ucrReceiverSingle() + Me.lblMintem = New System.Windows.Forms.Label() + Me.rdoClimograph = New System.Windows.Forms.RadioButton() + Me.rdoWalterLieth = New System.Windows.Forms.RadioButton() + Me.ucrPnlClimograph = New instat.UcrPanel() + Me.ucrBase = New instat.ucrButtons() + Me.ucrSave = New instat.ucrSave() + Me.ucrReceiverMonth = New instat.ucrReceiverSingle() + Me.lblMonth = New System.Windows.Forms.Label() + Me.ucrSelectorClimograph = New instat.ucrSelectorByDataFrameAddRemove() Me.SuspendLayout() ' + 'ucrReceiverAbsolute + ' + Me.ucrReceiverAbsolute.AutoSize = True + Me.ucrReceiverAbsolute.frmParent = Me + Me.ucrReceiverAbsolute.Location = New System.Drawing.Point(267, 280) + Me.ucrReceiverAbsolute.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverAbsolute.Name = "ucrReceiverAbsolute" + Me.ucrReceiverAbsolute.Selector = Nothing + Me.ucrReceiverAbsolute.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverAbsolute.strNcFilePath = "" + Me.ucrReceiverAbsolute.TabIndex = 77 + Me.ucrReceiverAbsolute.ucrSelector = Nothing + ' + 'lblAbsolute + ' + Me.lblAbsolute.AutoSize = True + Me.lblAbsolute.Location = New System.Drawing.Point(267, 264) + Me.lblAbsolute.Name = "lblAbsolute" + Me.lblAbsolute.Size = New System.Drawing.Size(111, 13) + Me.lblAbsolute.TabIndex = 76 + Me.lblAbsolute.Text = "Temperature min, min:" + ' + 'ucrInputStation + ' + Me.ucrInputStation.AddQuotesIfUnrecognised = True + Me.ucrInputStation.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrInputStation.GetSetSelectedIndex = -1 + Me.ucrInputStation.IsReadOnly = False + Me.ucrInputStation.Location = New System.Drawing.Point(379, 68) + Me.ucrInputStation.Name = "ucrInputStation" + Me.ucrInputStation.Size = New System.Drawing.Size(86, 21) + Me.ucrInputStation.TabIndex = 65 + ' + 'ucr1stFactorReceiver + ' + Me.ucr1stFactorReceiver.AutoSize = True + Me.ucr1stFactorReceiver.frmParent = Me + Me.ucr1stFactorReceiver.Location = New System.Drawing.Point(267, 68) + Me.ucr1stFactorReceiver.Margin = New System.Windows.Forms.Padding(0) + Me.ucr1stFactorReceiver.Name = "ucr1stFactorReceiver" + Me.ucr1stFactorReceiver.Selector = Nothing + Me.ucr1stFactorReceiver.Size = New System.Drawing.Size(109, 26) + Me.ucr1stFactorReceiver.strNcFilePath = "" + Me.ucr1stFactorReceiver.TabIndex = 64 + Me.ucr1stFactorReceiver.ucrSelector = Nothing + ' + 'lblFacetBy + ' + Me.lblFacetBy.AutoSize = True + Me.lblFacetBy.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.lblFacetBy.Location = New System.Drawing.Point(267, 53) + Me.lblFacetBy.Name = "lblFacetBy" + Me.lblFacetBy.Size = New System.Drawing.Size(43, 13) + Me.lblFacetBy.TabIndex = 63 + Me.lblFacetBy.Tag = "" + Me.lblFacetBy.Text = "Station:" + ' + 'ucrReceiverRain + ' + Me.ucrReceiverRain.AutoSize = True + Me.ucrReceiverRain.frmParent = Me + Me.ucrReceiverRain.Location = New System.Drawing.Point(267, 150) + Me.ucrReceiverRain.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverRain.Name = "ucrReceiverRain" + Me.ucrReceiverRain.Selector = Nothing + Me.ucrReceiverRain.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverRain.strNcFilePath = "" + Me.ucrReceiverRain.TabIndex = 69 + Me.ucrReceiverRain.ucrSelector = Nothing + ' + 'lblRain + ' + Me.lblRain.AutoSize = True + Me.lblRain.Location = New System.Drawing.Point(267, 134) + Me.lblRain.Name = "lblRain" + Me.lblRain.Size = New System.Drawing.Size(48, 13) + Me.lblRain.TabIndex = 68 + Me.lblRain.Text = "RainFall:" + ' + 'ucrReceiverMaxtem + ' + Me.ucrReceiverMaxtem.AutoSize = True + Me.ucrReceiverMaxtem.frmParent = Me + Me.ucrReceiverMaxtem.Location = New System.Drawing.Point(267, 193) + Me.ucrReceiverMaxtem.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverMaxtem.Name = "ucrReceiverMaxtem" + Me.ucrReceiverMaxtem.Selector = Nothing + Me.ucrReceiverMaxtem.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverMaxtem.strNcFilePath = "" + Me.ucrReceiverMaxtem.TabIndex = 71 + Me.ucrReceiverMaxtem.ucrSelector = Nothing + ' + 'lblMaxtem + ' + Me.lblMaxtem.AutoSize = True + Me.lblMaxtem.Location = New System.Drawing.Point(267, 177) + Me.lblMaxtem.Name = "lblMaxtem" + Me.lblMaxtem.Size = New System.Drawing.Size(93, 13) + Me.lblMaxtem.TabIndex = 70 + Me.lblMaxtem.Text = "Temperature Max:" + ' + 'ucrReceiverMintemp + ' + Me.ucrReceiverMintemp.AutoSize = True + Me.ucrReceiverMintemp.frmParent = Me + Me.ucrReceiverMintemp.Location = New System.Drawing.Point(267, 234) + Me.ucrReceiverMintemp.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverMintemp.Name = "ucrReceiverMintemp" + Me.ucrReceiverMintemp.Selector = Nothing + Me.ucrReceiverMintemp.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverMintemp.strNcFilePath = "" + Me.ucrReceiverMintemp.TabIndex = 73 + Me.ucrReceiverMintemp.ucrSelector = Nothing + ' + 'lblMintem + ' + Me.lblMintem.AutoSize = True + Me.lblMintem.Location = New System.Drawing.Point(267, 218) + Me.lblMintem.Name = "lblMintem" + Me.lblMintem.Size = New System.Drawing.Size(90, 13) + Me.lblMintem.TabIndex = 72 + Me.lblMintem.Text = "Temperature Min:" + ' + 'rdoClimograph + ' + Me.rdoClimograph.Appearance = System.Windows.Forms.Appearance.Button + Me.rdoClimograph.BackColor = System.Drawing.SystemColors.Control + Me.rdoClimograph.Enabled = False + Me.rdoClimograph.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoClimograph.FlatAppearance.BorderSize = 2 + Me.rdoClimograph.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoClimograph.FlatStyle = System.Windows.Forms.FlatStyle.Flat + Me.rdoClimograph.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.rdoClimograph.Location = New System.Drawing.Point(195, 13) + Me.rdoClimograph.Name = "rdoClimograph" + Me.rdoClimograph.Size = New System.Drawing.Size(119, 28) + Me.rdoClimograph.TabIndex = 62 + Me.rdoClimograph.TabStop = True + Me.rdoClimograph.Tag = "" + Me.rdoClimograph.Text = "Ordinary Climograph" + Me.rdoClimograph.TextAlign = System.Drawing.ContentAlignment.MiddleCenter + Me.rdoClimograph.UseVisualStyleBackColor = False + ' + 'rdoWalterLieth + ' + Me.rdoWalterLieth.Appearance = System.Windows.Forms.Appearance.Button + Me.rdoWalterLieth.BackColor = System.Drawing.SystemColors.Control + Me.rdoWalterLieth.FlatAppearance.BorderColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoWalterLieth.FlatAppearance.BorderSize = 2 + Me.rdoWalterLieth.FlatAppearance.CheckedBackColor = System.Drawing.SystemColors.ActiveCaption + Me.rdoWalterLieth.FlatStyle = System.Windows.Forms.FlatStyle.Flat + Me.rdoWalterLieth.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.rdoWalterLieth.Location = New System.Drawing.Point(117, 13) + Me.rdoWalterLieth.Name = "rdoWalterLieth" + Me.rdoWalterLieth.Size = New System.Drawing.Size(80, 28) + Me.rdoWalterLieth.TabIndex = 61 + Me.rdoWalterLieth.TabStop = True + Me.rdoWalterLieth.Tag = "" + Me.rdoWalterLieth.Text = "Walter Lieth" + Me.rdoWalterLieth.TextAlign = System.Drawing.ContentAlignment.MiddleCenter + Me.rdoWalterLieth.UseVisualStyleBackColor = False + ' + 'ucrPnlClimograph + ' + Me.ucrPnlClimograph.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrPnlClimograph.Location = New System.Drawing.Point(107, 5) + Me.ucrPnlClimograph.Name = "ucrPnlClimograph" + Me.ucrPnlClimograph.Size = New System.Drawing.Size(236, 41) + Me.ucrPnlClimograph.TabIndex = 60 + ' + 'ucrBase + ' + Me.ucrBase.AutoSize = True + Me.ucrBase.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrBase.Location = New System.Drawing.Point(12, 332) + Me.ucrBase.Name = "ucrBase" + Me.ucrBase.Size = New System.Drawing.Size(408, 52) + Me.ucrBase.TabIndex = 75 + ' + 'ucrSave + ' + Me.ucrSave.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink + Me.ucrSave.Location = New System.Drawing.Point(12, 305) + Me.ucrSave.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5) + Me.ucrSave.Name = "ucrSave" + Me.ucrSave.Size = New System.Drawing.Size(282, 24) + Me.ucrSave.TabIndex = 74 + ' + 'ucrReceiverMonth + ' + Me.ucrReceiverMonth.AutoSize = True + Me.ucrReceiverMonth.frmParent = Me + Me.ucrReceiverMonth.Location = New System.Drawing.Point(267, 109) + Me.ucrReceiverMonth.Margin = New System.Windows.Forms.Padding(0) + Me.ucrReceiverMonth.Name = "ucrReceiverMonth" + Me.ucrReceiverMonth.Selector = Nothing + Me.ucrReceiverMonth.Size = New System.Drawing.Size(120, 20) + Me.ucrReceiverMonth.strNcFilePath = "" + Me.ucrReceiverMonth.TabIndex = 67 + Me.ucrReceiverMonth.ucrSelector = Nothing + ' + 'lblMonth + ' + Me.lblMonth.AutoSize = True + Me.lblMonth.Location = New System.Drawing.Point(267, 93) + Me.lblMonth.Name = "lblMonth" + Me.lblMonth.Size = New System.Drawing.Size(40, 13) + Me.lblMonth.TabIndex = 66 + Me.lblMonth.Text = "Month:" + ' + 'ucrSelectorClimograph + ' + Me.ucrSelectorClimograph.AutoSize = True + Me.ucrSelectorClimograph.bDropUnusedFilterLevels = False + Me.ucrSelectorClimograph.bShowHiddenColumns = False + Me.ucrSelectorClimograph.bUseCurrentFilter = True + Me.ucrSelectorClimograph.Location = New System.Drawing.Point(11, 48) + Me.ucrSelectorClimograph.Margin = New System.Windows.Forms.Padding(0) + Me.ucrSelectorClimograph.Name = "ucrSelectorClimograph" + Me.ucrSelectorClimograph.Size = New System.Drawing.Size(213, 183) + Me.ucrSelectorClimograph.TabIndex = 59 + ' 'dlgClimograph ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(428, 450) + Me.ClientSize = New System.Drawing.Size(477, 388) + Me.Controls.Add(Me.ucrReceiverAbsolute) + Me.Controls.Add(Me.lblAbsolute) + Me.Controls.Add(Me.ucrInputStation) + Me.Controls.Add(Me.ucr1stFactorReceiver) + Me.Controls.Add(Me.lblFacetBy) + Me.Controls.Add(Me.ucrReceiverRain) + Me.Controls.Add(Me.lblRain) + Me.Controls.Add(Me.ucrReceiverMaxtem) + Me.Controls.Add(Me.lblMaxtem) + Me.Controls.Add(Me.ucrReceiverMintemp) + Me.Controls.Add(Me.lblMintem) + Me.Controls.Add(Me.rdoClimograph) + Me.Controls.Add(Me.rdoWalterLieth) + Me.Controls.Add(Me.ucrPnlClimograph) + Me.Controls.Add(Me.ucrBase) + Me.Controls.Add(Me.ucrSave) + Me.Controls.Add(Me.ucrReceiverMonth) + Me.Controls.Add(Me.lblMonth) + Me.Controls.Add(Me.ucrSelectorClimograph) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow Me.MaximizeBox = False Me.MinimizeBox = False @@ -36,6 +296,27 @@ Partial Class dlgClimograph Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Climograph" Me.ResumeLayout(False) + Me.PerformLayout() End Sub + + Friend WithEvents ucrReceiverAbsolute As ucrReceiverSingle + Friend WithEvents lblAbsolute As Label + Friend WithEvents ucrInputStation As ucrInputComboBox + Friend WithEvents ucr1stFactorReceiver As ucrReceiverSingle + Friend WithEvents lblFacetBy As Label + Friend WithEvents ucrReceiverRain As ucrReceiverSingle + Friend WithEvents lblRain As Label + Friend WithEvents ucrReceiverMaxtem As ucrReceiverSingle + Friend WithEvents lblMaxtem As Label + Friend WithEvents ucrReceiverMintemp As ucrReceiverSingle + Friend WithEvents lblMintem As Label + Friend WithEvents rdoClimograph As RadioButton + Friend WithEvents rdoWalterLieth As RadioButton + Friend WithEvents ucrPnlClimograph As UcrPanel + Friend WithEvents ucrBase As ucrButtons + Friend WithEvents ucrSave As ucrSave + Friend WithEvents ucrReceiverMonth As ucrReceiverSingle + Friend WithEvents lblMonth As Label + Friend WithEvents ucrSelectorClimograph As ucrSelectorByDataFrameAddRemove End Class From 32c384f9d69fcddf69da381a5d1efb1ff34079ab Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 10:22:02 +0100 Subject: [PATCH 15/30] change made --- instat/dlgClimograph.vb | 357 ++++++++++++++++++++++++++++++++++++- instat/frmMain.Designer.vb | 5 +- 2 files changed, 357 insertions(+), 5 deletions(-) diff --git a/instat/dlgClimograph.vb b/instat/dlgClimograph.vb index 26752c99347..97d6da1aebd 100644 --- a/instat/dlgClimograph.vb +++ b/instat/dlgClimograph.vb @@ -1,3 +1,358 @@ -Public Class dlgClimograph +' R- Instat +' Copyright (C) 2015-2017 +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License +' along with this program. If not, see . +Imports instat.Translations + +Public Class dlgClimograph + Private bFirstload As Boolean = True + Private bReset As Boolean = True + Private clsGgwalterliethFunction, clsDummyFunction As RFunction + Private clsBaseOperator As New ROperator + Private ReadOnly strFacetWrap As String = "Facet Wrap" + Private ReadOnly strFacetRow As String = "Facet Row" + Private ReadOnly strFacetCol As String = "Facet Column" + Private ReadOnly strNone As String = "None" + Private clsFacetFunction As New RFunction + Private clsGroupByFunction As New RFunction + Private clsFacetOperator As New ROperator + Private clsFacetRowOp As New ROperator + Private clsFacetColOp As New ROperator + Private clsPipeOperator As New ROperator + Private bUpdateComboOptions As Boolean = True + Private bUpdatingParameters As Boolean = False + + Private Sub dlgClimograph_Load(sender As Object, e As EventArgs) Handles MyBase.Load + If bFirstload Then + InitialiseDialog() + bFirstload = False + End If + If bReset Then + SetDefaults() + End If + SetRCodeForControls(bReset) + bReset = False + TestOKEnabled() + autoTranslate(Me) + End Sub + + Private Sub InitialiseDialog() + ucrBase.iHelpTopicID = 432 + + ucrSelectorClimograph.SetParameter(New RParameter("data", 0)) + ucrSelectorClimograph.SetParameterIsrfunction() + + ucrPnlClimograph.AddRadioButton(rdoClimograph) + ucrPnlClimograph.AddRadioButton(rdoWalterLieth) + ucrPnlClimograph.AddParameterValuesCondition(rdoWalterLieth, "checked", "WalterLieth") + ucrPnlClimograph.AddParameterValuesCondition(rdoClimograph, "checked", "Climograph") + + ucrReceiverMonth.SetParameter(New RParameter("month", 1)) + ucrReceiverMonth.SetParameterIsString() + ucrReceiverMonth.Selector = ucrSelectorClimograph + ucrReceiverMonth.SetClimaticType("month") + ucrReceiverMonth.bAutoFill = True + ucrReceiverMonth.strSelectorHeading = "Month Variables" + ucrReceiverMonth.SetLinkedDisplayControl(lblMonth) + + ucrReceiverRain.SetParameter(New RParameter("p_mes", 3)) + ucrReceiverRain.SetParameterIsString() + ucrReceiverRain.Selector = ucrSelectorClimograph + ucrReceiverRain.SetClimaticType("rain") + ucrReceiverRain.bAutoFill = True + ucrReceiverRain.strSelectorHeading = "Rain Variables" + ucrReceiverRain.SetLinkedDisplayControl(lblRain) + + ucrReceiverMaxtem.SetParameter(New RParameter("tm_max", 4)) + ucrReceiverMaxtem.SetParameterIsString() + ucrReceiverMaxtem.Selector = ucrSelectorClimograph + ucrReceiverMaxtem.SetClimaticType("temp_max") + ucrReceiverMaxtem.bAutoFill = True + ucrReceiverMaxtem.strSelectorHeading = "Variables" + ucrReceiverMaxtem.SetLinkedDisplayControl(lblMaxtem) + + ucrReceiverMintemp.SetParameter(New RParameter("tm_min", 5)) + ucrReceiverMintemp.SetParameterIsString() + ucrReceiverMintemp.Selector = ucrSelectorClimograph + ucrReceiverMintemp.SetClimaticType("temp_min") + ucrReceiverMintemp.bAutoFill = True + ucrReceiverMintemp.strSelectorHeading = "Variables" + ucrReceiverMintemp.SetLinkedDisplayControl(lblMintem) + + ucr1stFactorReceiver.SetParameter(New RParameter("station")) + ucr1stFactorReceiver.Selector = ucrSelectorClimograph + ucr1stFactorReceiver.SetIncludedDataTypes({"factor"}) + ucr1stFactorReceiver.strSelectorHeading = "Factors" + ucr1stFactorReceiver.bWithQuotes = False + ucr1stFactorReceiver.SetParameterIsString() + ucr1stFactorReceiver.SetValuesToIgnore({"."}) + + ucrInputStation.SetItems({strFacetWrap, strFacetRow, strFacetCol, strNone}) + ucrInputStation.SetDropDownStyleAsNonEditable() + + ucrReceiverAbsolute.SetParameter(New RParameter("ta_min", 6)) + ucrReceiverAbsolute.SetParameterIsString() + ucrReceiverAbsolute.Selector = ucrSelectorClimograph + ucrReceiverAbsolute.strSelectorHeading = "Variables" + ucrReceiverAbsolute.SetLinkedDisplayControl(lblAbsolute) + + ucrSave.SetPrefix("wl_graph") + ucrSave.SetIsComboBox() + ucrSave.SetSaveTypeAsGraph() + ucrSave.SetCheckBoxText("Save") + ucrSave.SetDataFrameSelector(ucrSelectorClimograph.ucrAvailableDataFrames) + ucrSave.SetAssignToIfUncheckedValue("last_graph") + End Sub + + Private Sub SetDefaults() + clsGgwalterliethFunction = New RFunction + clsBaseOperator = New ROperator + clsDummyFunction = New RFunction + clsGroupByFunction = New RFunction + clsPipeOperator = New ROperator + + clsFacetFunction = New RFunction + clsFacetOperator = New ROperator + clsFacetRowOp = New ROperator + clsFacetColOp = New ROperator + + ucrSelectorClimograph.Reset() + ucrSave.Reset() + + ucrInputStation.SetName(strFacetWrap) + ucrInputStation.bUpdateRCodeFromControl = True + + ucrReceiverMonth.SetMeAsReceiver() + + clsDummyFunction.AddParameter("checked", "WalterLieth", iPosition:=0) + + clsPipeOperator.SetOperation("%>%") + SetPipeAssignTo() + + clsGgwalterliethFunction.SetRCommand("ggwalter_lieth") + + clsFacetFunction.SetPackageName("ggplot2") + clsFacetRowOp.SetOperation("+") + clsFacetRowOp.bBrackets = False + clsFacetColOp.SetOperation("+") + clsFacetColOp.bBrackets = False + clsFacetOperator.SetOperation("~") + clsFacetOperator.bForceIncludeOperation = True + clsFacetOperator.bBrackets = False + clsFacetFunction.AddParameter("facets", clsROperatorParameter:=clsFacetOperator, iPosition:=0) + + clsGroupByFunction.SetPackageName("dplyr") + clsGroupByFunction.SetRCommand("group_by") + + clsBaseOperator.SetOperation("+") + clsBaseOperator.AddParameter("ggwalter_lieth", clsRFunctionParameter:=clsGgwalterliethFunction, iPosition:=0) + + ucrBase.clsRsyntax.SetBaseROperator(clsBaseOperator) + End Sub + + Private Sub SetRCodeForControls(bReset) + ucrSelectorClimograph.SetRCode(clsGgwalterliethFunction, bReset) + ucrPnlClimograph.SetRCode(clsDummyFunction, bReset) + ucrReceiverMonth.SetRCode(clsGgwalterliethFunction, bReset) + ucrReceiverRain.SetRCode(clsGgwalterliethFunction, bReset) + ucrReceiverMintemp.SetRCode(clsGgwalterliethFunction, bReset) + ucrReceiverMaxtem.SetRCode(clsGgwalterliethFunction, bReset) + ucrReceiverAbsolute.SetRCode(clsGgwalterliethFunction, bReset) + ucrSave.SetRCode(clsBaseOperator, bReset) + If bReset Then + AutoFacetStation() + End If + End Sub + + Private Sub TestOKEnabled() + If rdoWalterLieth.Checked AndAlso ((Not ucrReceiverAbsolute.IsEmpty AndAlso Not ucrReceiverMaxtem.IsEmpty AndAlso Not ucrReceiverMintemp.IsEmpty AndAlso Not ucrReceiverMonth.IsEmpty AndAlso Not ucrReceiverRain.IsEmpty) OrElse Not ucrSave.IsComplete) Then + ucrBase.OKEnabled(True) + Else + ucrBase.OKEnabled(False) + End If + End Sub + + Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset + SetDefaults() + SetRCodeForControls(True) + UpdateParameters() + TestOKEnabled() + End Sub + + Private Sub ucrInput_ControlValueChanged(ucrChangedControl As ucrInputComboBox) Handles ucrInputStation.ControlValueChanged + If Not bUpdateComboOptions Then + Exit Sub + End If + Dim strChangedText As String = ucrChangedControl.GetText() + If strChangedText <> strNone Then + If Not strChangedText = strFacetCol AndAlso Not strChangedText = strFacetRow AndAlso + Not ucrInputStation.Equals(ucrChangedControl) AndAlso ucrInputStation.GetText() = strChangedText Then + bUpdateComboOptions = False + ucrInputStation.SetName(strNone) + bUpdateComboOptions = True + End If + If (strChangedText = strFacetWrap AndAlso ucrInputStation.GetText = strFacetRow) OrElse (strChangedText = strFacetRow AndAlso + ucrInputStation.GetText = strFacetWrap) OrElse (strChangedText = strFacetWrap AndAlso + ucrInputStation.GetText = strFacetCol) OrElse (strChangedText = strFacetCol AndAlso ucrInputStation.GetText = strFacetWrap) Then + ucrInputStation.SetName(strNone) + End If + End If + UpdateParameters() + AddRemoveFacets() + AddRemoveGroupBy() + End Sub + + Private Sub UpdateParameters() + clsFacetOperator.RemoveParameterByName("wrap" & ucrInputStation.Name) + clsFacetColOp.RemoveParameterByName("col" & ucrInputStation.Name) + clsFacetRowOp.RemoveParameterByName("row" & ucrInputStation.Name) + + clsBaseOperator.RemoveParameterByName("facets") + bUpdatingParameters = True + ucr1stFactorReceiver.SetRCode(Nothing) + Select Case ucrInputStation.GetText() + Case strFacetWrap + ucr1stFactorReceiver.ChangeParameterName("wrap" & ucrInputStation.Name) + ucr1stFactorReceiver.SetRCode(clsFacetOperator) + Case strFacetCol + ucr1stFactorReceiver.ChangeParameterName("col" & ucrInputStation.Name) + ucr1stFactorReceiver.SetRCode(clsFacetColOp) + Case strFacetRow + ucr1stFactorReceiver.ChangeParameterName("row" & ucrInputStation.Name) + ucr1stFactorReceiver.SetRCode(clsFacetRowOp) + End Select + bUpdatingParameters = False + End Sub + + Private Sub AddRemoveFacets() + Dim bWrap As Boolean = False + Dim bCol As Boolean = False + Dim bRow As Boolean = False + + If bUpdatingParameters Then + Exit Sub + End If + + clsBaseOperator.RemoveParameterByName("facets") + If Not ucr1stFactorReceiver.IsEmpty Then + Select Case ucrInputStation.GetText() + Case strFacetWrap + bWrap = True + Case strFacetCol + bCol = True + Case strFacetRow + bRow = True + End Select + End If + + If bWrap OrElse bRow OrElse bCol Then + clsBaseOperator.AddParameter("facets", clsRFunctionParameter:=clsFacetFunction) + End If + If bWrap Then + clsFacetFunction.SetRCommand("facet_wrap") + End If + If bRow OrElse bCol Then + clsFacetFunction.SetRCommand("facet_grid") + End If + If bRow Then + clsFacetOperator.AddParameter("left", clsROperatorParameter:=clsFacetRowOp, iPosition:=0) + ElseIf bCol AndAlso Not bWrap Then + clsFacetOperator.AddParameter("left", ".", iPosition:=0) + Else + clsFacetOperator.RemoveParameterByName("left") + End If + If bCol Then + clsFacetOperator.AddParameter("right", clsROperatorParameter:=clsFacetColOp, iPosition:=1) + ElseIf bRow AndAlso Not bWrap Then + clsFacetOperator.AddParameter("right", ".", iPosition:=1) + Else + clsFacetOperator.RemoveParameterByName("right") + End If + End Sub + + Private Sub ucr1stFactorReceiver_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucr1stFactorReceiver.ControlValueChanged + If Not ucr1stFactorReceiver.IsEmpty Then + clsGgwalterliethFunction.AddParameter("station", Chr(34) & ucr1stFactorReceiver.GetVariableNames(False) & Chr(34), iPosition:=1) + Else + clsGgwalterliethFunction.RemoveParameterByName("station") + End If + AddRemoveFacets() + AddRemoveGroupBy() + End Sub + + Private Sub AutoFacetStation() + Dim ucrCurrentReceiver As ucrReceiver = ucrSelectorClimograph.CurrentReceiver + + If ucrCurrentReceiver IsNot Nothing Then + ucr1stFactorReceiver.AddItemsWithMetadataProperty(ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text, "Climatic_Type", {"station_label"}) + ucrCurrentReceiver.SetMeAsReceiver() + AddRemoveGroupBy() + End If + End Sub + + Private Sub ucrSelectorClimograph_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorClimograph.ControlValueChanged + AutoFacetStation() + SetPipeAssignTo() + End Sub + + Private Sub GetParameterValue(clsOperator As ROperator) + Dim i As Integer = 0 + For Each clsTempParam As RParameter In clsOperator.clsParameters + If clsTempParam.strArgumentValue <> "" AndAlso clsTempParam.strArgumentValue <> "." Then + clsGroupByFunction.AddParameter(i, clsTempParam.strArgumentValue, bIncludeArgumentName:=False, iPosition:=i) + i = i + 1 + End If + Next + End Sub + + Private Sub AddRemoveGroupBy() + + If clsPipeOperator.ContainsParameter("mutate") Then + clsGroupByFunction.ClearParameters() + If clsBaseOperator.ContainsParameter("facets") Then + Select Case ucrInputStation.GetText() + Case strFacetWrap + GetParameterValue(clsFacetOperator) + Case strFacetCol + GetParameterValue(clsFacetColOp) + Case strFacetRow + GetParameterValue(clsFacetRowOp) + End Select + End If + + If clsGroupByFunction.iParameterCount > 0 Then + clsPipeOperator.AddParameter("group_by", clsRFunctionParameter:=clsGroupByFunction, iPosition:=1) + Else + clsPipeOperator.RemoveParameterByName("group_by") + End If + Else + clsPipeOperator.RemoveParameterByName("group_by") + End If + + SetPipeAssignTo() + End Sub + + Private Sub SetPipeAssignTo() + If ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" AndAlso clsPipeOperator.clsParameters.Count > 1 Then + clsPipeOperator.SetAssignTo(ucrSelectorClimograph.ucrAvailableDataFrames.cboAvailableDataFrames.Text) + Else + clsPipeOperator.RemoveAssignTo() + End If + End Sub + + Private Sub AllControls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrPnlClimograph.ControlContentsChanged, ucrReceiverRain.ControlContentsChanged, ucrReceiverAbsolute.ControlContentsChanged, ucrReceiverMonth.ControlContentsChanged, ucrReceiverMaxtem.ControlContentsChanged, ucrReceiverMintemp.ControlContentsChanged, ucrSave.ControlContentsChanged + TestOKEnabled() + End Sub End Class \ No newline at end of file diff --git a/instat/frmMain.Designer.vb b/instat/frmMain.Designer.vb index 123b0175b38..863f5e4816f 100644 --- a/instat/frmMain.Designer.vb +++ b/instat/frmMain.Designer.vb @@ -2193,7 +2193,6 @@ Partial Class frmMain ' 'mnuClimaticDescribeClimograph ' - Me.mnuClimaticDescribeClimograph.Enabled = False Me.mnuClimaticDescribeClimograph.Name = "mnuClimaticDescribeClimograph" Me.mnuClimaticDescribeClimograph.Size = New System.Drawing.Size(211, 22) Me.mnuClimaticDescribeClimograph.Text = "Climograph..." @@ -5120,9 +5119,7 @@ Partial Class frmMain Me.IsMdiContainer = True Me.MainMenuStrip = Me.mnuBar Me.Name = "frmMain" - Me.Text = "R-Instat " + My.Application.Info.Version.Major.ToString + "." + - My.Application.Info.Version.Minor.ToString + "." + - My.Application.Info.Version.Build.ToString + Me.Text = "R-Instat .." Me.WindowState = System.Windows.Forms.FormWindowState.Maximized Me.stsStrip.ResumeLayout(False) Me.stsStrip.PerformLayout() From 9427bdf27f4c25e861460c86c4226e90a8225fc0 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 10:27:45 +0100 Subject: [PATCH 16/30] Change made --- .../InstatObject/R/stand_alone_functions.R | 392 +++++++++++++----- 1 file changed, 285 insertions(+), 107 deletions(-) diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index 904794d2d2c..d69af86edbb 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -2,7 +2,6 @@ get_default_significant_figures <- function(data) { if(is.numeric(data)) return(3) else return(NA) } - convert_to_character_matrix <- function(data, format_decimal_places = TRUE, decimal_places, is_scientific = FALSE, return_data_frame = TRUE, na_display = NULL, check.names = TRUE) { if(nrow(data) == 0) { out <- matrix(nrow = 0, ncol = ncol(data)) @@ -40,7 +39,6 @@ convert_to_character_matrix <- function(data, format_decimal_places = TRUE, deci if(return_data_frame) out <- data.frame(out, stringsAsFactors = FALSE, check.names = check.names) return(out) } - next_default_item = function(prefix, existing_names = c(), include_index = FALSE, start_index = 1) { if(!is.character(prefix)) stop("prefix must be of type character") @@ -59,7 +57,6 @@ next_default_item = function(prefix, existing_names = c(), include_index = FALSE } return(out) } - import_from_ODK = function(username, form_name, platform) { if(platform == "kobo") { url <- "https://kc.kobotoolbox.org/api/v1/data" @@ -97,7 +94,6 @@ import_from_ODK = function(username, form_name, platform) { out <- jsonlite::fromJSON(form_data, flatten = TRUE) return(out) } - get_odk_form_names = function(username, platform) { #TODO This should not be repeated if(platform == "kobo") { @@ -122,7 +118,6 @@ get_odk_form_names = function(username, platform) { form_names <- sapply(forms, function(x) x$title) return(form_names) } - convert_SST <- function(datafile, data_from = 5){ start_year <- get_years_from_data(datafile)[1] end_year <- get_years_from_data(datafile)[length(get_years_from_data(datafile))] @@ -152,19 +147,15 @@ convert_SST <- function(datafile, data_from = 5){ my_data = cbind(period, lat_lon_df, SST_value) return(list(my_data, lat_lon_df)) } - get_years_from_data <- function(datafile){ return(na.omit(t(unique(datafile[3,2:ncol(datafile)])))) } - get_lat_from_data <- function(datafile){ return(unique(na.omit(as.numeric(as.character(datafile[5:nrow(datafile),1]))))) } - get_lon_from_data <- function(datafile){ return(na.omit(as.numeric(unique(t(datafile[5,2:ncol(datafile)]))))) } - lat_lon_dataframe <- function(datafile){ latitude <- get_lat_from_data(datafile) longitude <- get_lon_from_data(datafile) @@ -182,7 +173,6 @@ lat_lon_dataframe <- function(datafile){ } return(cbind(lat_lon,station)) } - output_CPT <- function(data, lat_lon_data, station_latlondata, latitude, longitude, station, year, element, long.data = TRUE, na_code = -999) { if(missing(data)) stop("data should be provided") @@ -256,24 +246,20 @@ output_CPT <- function(data, lat_lon_data, station_latlondata, latitude, longitu cpt_data <- rbind(t_lat_lon_data, unstacked_data) return(cpt_data) } - yday_366 <- function(date) { temp_doy <- lubridate::yday(date) temp_leap <- lubridate::leap_year(date) temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] <- 1 + temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] return(temp_doy) } - dekade <- function(date) { temp_dekade <- 3 * (lubridate::month(date)) - 2 + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 20) return(temp_dekade) } - pentad <- function(date){ temp_pentad <- 6*(lubridate::month(date)) - 5 + (lubridate::mday(date) > 5) + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 15) + (lubridate::mday(date) > 20) + (lubridate::mday(date) > 25) return(temp_pentad) } - nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { if(!dimension %in% names(nc$dim)) stop(dimension, " not found in file.") vals <- nc$dim[[dimension]]$vals @@ -299,7 +285,6 @@ nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { bounds <- c(min(vals, na.rm = TRUE), max(vals, na.rm = TRUE)) return(bounds) } - nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE) { if(missing(vars)) vars <- ncdf4.helpers::nc.get.variable.list(nc) if(sum(is.null(lon_points), is.null(lat_points)) == 1) stop("You must specificy both lon_points and lat_points") @@ -418,7 +403,6 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = count_list[[1]] <- count dim_values_list[[1]] <- dim_values } - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc) time_dims <- names(dim_axes[which(dim_axes == "T" & names(dim_axes) %in% dim_names)]) var_data_list <- list() @@ -533,7 +517,6 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = } return(var_data) } - # open_NetCDF <- function(nc_data, latitude_col_name, longitude_col_name, default_names){ # variables = names(nc_data$var) # lat_lon_names = names(nc_data$dim) @@ -613,7 +596,6 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = # } # return(list(my_data, lat_lon_df, new_lat_lon_column_names)) # } - multiple_nc_as_data_frame <- function(path, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE, id = "id") { filepaths <- list.files(path = path, pattern="*\\.nc", full.names = TRUE) filenames <- basename(filepaths) @@ -635,7 +617,6 @@ multiple_nc_as_data_frame <- function(path, vars, keep_raw_time = TRUE, include_ merged_data <- dplyr::bind_rows(nc_list, .id = id) return(merged_data) } - import_from_iri <- function(download_from, data_file, path, X1, X2,Y1,Y2, get_area_point){ if(path == ""){ gaugelocdir = getwd() @@ -795,46 +776,38 @@ import_from_iri <- function(download_from, data_file, path, X1, X2,Y1,Y2, get_ar file.remove(paste(gaugelocdir,"tmp_iri.csv",sep="/")) return(list(dataout,lat_lon_dataframe)) } - is.logical.like <- function(x) { if(is.logical(x)) return(TRUE) else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0))) else return(FALSE) } - is.binary <- function(x) { if(is.logical(x)) return(TRUE) else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0))) else if(is.factor(x)) return(nlevels(x) == 2) else return(FALSE) } - get_column_attributes <- function(x, drop = c("class", "levels")) { tmp_attr <- attributes(x) tmp_attr <- tmp_attr[!names(tmp_attr) %in% drop] return(tmp_attr) } - split_items_in_groups <- function(items, num) { if(length(items) %% num != 0) stop("The number of items must be divisible by the number of groups") x <- split(items, rep(1:num, each = length(items)/num)) return(x) } - cancor_coef <- function(object) { object[c("xcoef", "ycoef")] } ################### - # cmsaf Plot.Region script - # # This script displays a map of the selected product. # You can either specify a certain year / month from a data file with several time steps # or plot one 2D field. # Prepare the your netcdf-files with the R-script "Prep.Data.R" or "Apply.Function.R" ########################################################################################## - plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-01"), add2title = "CM SAF, ", lonmin = NA, lonmax = NA, latmin = NA, latmax = NA, height = 600, width = 600, plot.ano = FALSE, set.col.breaks = FALSE, brk.set = seq(240,310,5), colmin0 = NA, colmax0 = NA, ncol = 14, plotHighRes = FALSE, plotCoastline = TRUE, plotCountries = TRUE, plotRivers = FALSE, contour.thick = 2, plotCities = TRUE, pch.cities = 2, cex.cities = 1, label.cities = TRUE, plotCapitals = 1, cex.label.cities = 0.5, dlat = 0.25, plotOwnLocations = FALSE, loc_lon = c(), loc_lat = c(), loc_name = c(""), label_pos = 1, variable = "Tm", level = 5, CTY.type = 4) { # Set the variable name @@ -913,7 +886,6 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 if (varname == "CTY") datalev <- CTY.type #--------------------------------------------------# - # Invert the latitude dimension if necessary if (lat[ny] < lat[1]) { sort.out <- sort(lat,index.return=TRUE) @@ -1062,7 +1034,6 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 axis(3,lwd=1,at=c(lonmin,lonmax),tick=TRUE,lwd.ticks=0,labels=FALSE) axis(4,lwd=1,at=c(latmin,latmax), tick=TRUE,lwd.ticks=0,labels=FALSE) } - duplicated_cases <- function(col_name, ignore = NULL, tolerance=0.01) { col_name <- as.vector(col_name) col_data1 <- c(1, rep(NA, length(col_name) - 1)) @@ -1089,7 +1060,6 @@ duplicated_cases <- function(col_name, ignore = NULL, tolerance=0.01) { } return(col_data1) } - #This is Sam function from issue #4270 duplicated_count_index<-function(x, type = "count"){ if(type == "count"){ @@ -1122,21 +1092,17 @@ duplicated_count_index<-function(x, type = "count"){ return(x$count) } } - - get_installed_packages_with_data <- function(with_data = TRUE) { all_installed_packages <- .packages(all.available = TRUE) if (with_data) all_installed_packages <- unique(data(package = all_installed_packages)[["results"]][,1]) return(all_installed_packages) } - drop_unused_levels <- function(dat, columns) { for(i in seq_along(columns)) { if(is.factor(dat[[columns[i]]])) dat[[columns[i]]] <- droplevels(dat[[columns[i]]]) } return(dat) } - compare_columns <- function(x, y, use_unique = TRUE, sort_values = TRUE, firstnotsecond = TRUE, secondnotfirst = TRUE, display_intersection = FALSE, display_union = FALSE, display_values = TRUE) { x_name <- deparse(substitute(x)) y_name <- deparse(substitute(y)) @@ -1177,8 +1143,6 @@ compare_columns <- function(x, y, use_unique = TRUE, sort_values = TRUE, firstno if(display_union) cat(paste0("Union (Values that appear in either column): ", paste0("'", dplyr::union(x, y), "'", collapse = ", "))) } } - - consecutive_sum <- function(x, initial_value = NA){ out = x for(i in 1:length(x)){ @@ -1194,11 +1158,9 @@ consecutive_sum <- function(x, initial_value = NA){ } return(out) } - max_consecutive_sum <- function(x){ max(consecutive_sum(x, initial_value = 0)) } - hashed_id <- function(x, salt, algo = "crc32") { if (missing(salt)){ y <- x @@ -1207,9 +1169,7 @@ hashed_id <- function(x, salt, algo = "crc32") { } y <- sapply(y, function(X) digest::digest(X, algo = algo)) as.character(y) - } - # Possible alternative but is slower: # spells <- function(z) { # Reduce(function(x,y) {y = dplyr::if_else(y == 0, 0, x + 1)}, z[-1], @@ -1227,7 +1187,6 @@ hashed_id <- function(x, salt, algo = "crc32") { } return(y) } - convert_to_dec_deg <- function (dd, mm = 0 , ss = 0, dir) { if(missing(dd)) stop("dd must be supplied") if(!missing(dir)) { @@ -1241,17 +1200,14 @@ convert_to_dec_deg <- function (dd, mm = 0 , ss = 0, dir) { decdeg <- (dd + ((mm * 60) + ss)/3600) * sgn return(decdeg) } - convert_yy_to_yyyy <- function (x, base) { if(missing(base)) stop("base year must be supplied") dplyr::if_else(x+2000 <= base, x+2000, x+1900) } - create_av_packs <- function() { av_packs <<- available.packages(repos = "https://cran.rstudio.com/") av_packs <<- data.frame(av_packs) } - package_check <- function(package) { out <- c() if (!pingr::is_online()) out[[1]] <- "5" @@ -1294,13 +1250,11 @@ in_top_n <- function(x, n = 10, wt, fun = sum) { else dat <- dat %>% dplyr::count(x, sort = TRUE, name = "fq") return(x %in% dat$x[1:n]) } - summary_sample <- function(x, size, replace = FALSE){ if(length(x)==0){return(NA)} else if(length(x)==1){return(x)} else{sample(x = x, size = size, replace = replace)} } - add_xy_area_range <- function(path, min_lon, max_lon, min_lat, max_lat, dim_x = "X", dim_y = "Y") { paste0( path, "/", dim_x, "/", @@ -1313,7 +1267,6 @@ add_xy_area_range <- function(path, min_lon, max_lon, min_lat, max_lat, dim_x = "RANGEEDGES", "/" ) } - add_xy_point_range <- function(path, min_lon, min_lat, dim_x = "X", dim_y = "Y") { paste0( path, "/", dim_x, "/", @@ -1324,7 +1277,6 @@ add_xy_point_range <- function(path, min_lon, min_lat, dim_x = "X", dim_y = "Y") "VALUES", "/" ) } - add_t_range <- function(path, min_date, max_date, dim_t = "T") { paste0( path, dim_t, "/", @@ -1335,7 +1287,6 @@ add_t_range <- function(path, min_date, max_date, dim_t = "T") { "RANGEEDGES", "/" ) } - add_nc <- function(path) { paste0(path, "data.nc") } @@ -1347,8 +1298,6 @@ fourier_series <- function(x, n, period) { "cos(", x, " * ", h, " * ", p2, " / ", period, ")", collapse = " + ") } - - climatic_missing <- function(data, date, elements = ..., stations, start = TRUE, end = FALSE){ @@ -1368,7 +1317,6 @@ climatic_missing <- function(data, date, elements = ..., stations, values_to = "value") # sort start/end times - # set start date if (start){ data.stack <- data.stack %>% @@ -1418,10 +1366,8 @@ climatic_missing <- function(data, date, elements = ..., stations, if (missing(stations)){ summary.data$stations <- NULL } - return(summary.data) } - climatic_details <- function(data, date, elements = ..., stations, @@ -1490,7 +1436,6 @@ climatic_details <- function(data, date, elements = ..., stations, From = dplyr::first({{ date }}), To = dplyr::last({{ date }})) %>% dplyr::mutate(is.complete = ifelse(no == na, 1, 0)) # 0 if all are missing - detail.table.month <- detail.table.month %>% dplyr::group_by({{ stations }}, Element) %>% dplyr::mutate(element.na = data.table::rleid(is.complete)) %>% @@ -1548,15 +1493,11 @@ climatic_details <- function(data, date, elements = ..., stations, dplyr::mutate(Level = make_factor(Level)) return(detail.table.all) - } - slope <- function(y, x) { x <- as.numeric(x) lm(y ~ x)$coefficients[2] - } - # make_factor is intended to be somewhat equivalent to forcats::as_factor() or base::as.factor(). # It provides default behaviour for converting to factor depending on the data type, similar to forcats::as_factor(). # For "character" and "numeric" types make_factor is consistent with forcats::as_factor() in terms of the order of the factor levels. @@ -1583,9 +1524,6 @@ make_factor <- function(x, ordered = is.ordered(x)) { factor(x, levels = as.character(unique(x)), ordered = ordered) } } - - - # wwr_export function is meant to reshape data into formats required by WMO for submission of climatic data # this gives Yearly data records with monthly and annual data for a particular year: wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_pressure, @@ -1851,7 +1789,6 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ } cat(i, "file(s) created at:", folder) } - dd_to_dms <- function(x, lat) { if (lat) dir <- ifelse(x >= 0, "N", "S") else dir <- ifelse(x >= 0, "E", "W") @@ -1861,7 +1798,6 @@ dd_to_dms <- function(x, lat) { s <- round((x - d - m/60) * 3600) return(paste(sprintf(ifelse(lat, "%02d", "%03d"), d), sprintf("%02d", m), sprintf("%02d", s), dir)) } - plot_mrl <- function(data, station_name, element_name, umin, umax, ncol = 1, xlab = "Threshold", ylab = "Mean excess", fill = "red", col = "black", rug = TRUE, addNexcesses = TRUE, textsize = 4) { @@ -1899,13 +1835,10 @@ plot_mrl <- function(data, station_name, element_name, umin, umax, ncol = 1, ) } } - - ### Constants month_abb_english <- c("Jan","Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") month_name_english <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") - # factored out code for a multiple indices for a single station. # Called by climdex(). # Not intended to be used externally. @@ -1963,7 +1896,6 @@ climdex_single_station <- function(ci, freq = "annual", indices, year, month, } return(df_ind) } - climdex <- function(data, station, date, year, month, prec, tmax, tmin, indices, freq = "annual", base.range = c(1961, 1990), n = 5, northern.hemisphere = TRUE, quantiles = NULL, temp.qtiles = c(0.1, 0.9), @@ -2053,7 +1985,6 @@ climdex <- function(data, station, date, year, month, prec, tmax, tmin, indices, } return(df_out) } - spei_input <- function(data, station, year, month, element) { if (missing(station)) id_cols <- c(year, month) else id_cols <- c(station, year, month) # SPEI package assumes data is ordered so must be sorted @@ -2093,7 +2024,6 @@ spei_input <- function(data, station, year, month, element) { } ts_data } - # This function extracts the SPEI/SPI column from an spei object x. # It requires the original data in order to return a vector of the correct length by removing NA values introduced when unstacking. # An alternative to this is to have a single wrapper SPEI/SPI function to handle this. @@ -2127,9 +2057,7 @@ spei_output <- function(x, data, station, year, month) { col <- as.vector(vals) } col - } - # This function has been adapted from extRemes::threshrange.plot(). # It has been adapted for use in R-Instat and uses ggplot2 graphical system rather than base plot(). threshold_Plot <- function(x, r, type = c("GP", "PP", "Exponential"), nint = 10, @@ -2244,7 +2172,6 @@ threshold_Plot <- function(x, r, type = c("GP", "PP", "Exponential"), nint = 10, } patchwork::wrap_plots(lst_plots, ncol = 1) } - # This function produces multiple threshold plots for various stations at a time. plot_multiple_threshold <- function(data, station_col_name, element_col_name, r, type = c("GP", "PP", "Exponential"), nint = 10, alpha = 0.05, ncol = 1, xlb = "", main = NULL , verbose = FALSE,...) { @@ -2264,8 +2191,6 @@ plot_multiple_threshold <- function(data, station_col_name, element_col_name, r, threshold_Plot(x = element_col, r = r, type = type, nint = nint, alpha = alpha, verbose = verbose) } } - - plot_declustered <- function(data, station_col_name, element_col_name, threshold, r = NULL, xlab = NULL, ylab = NULL, ncol = 1, print_summary = FALSE) { if (!missing(station_col_name)) { plts <- list() @@ -2301,7 +2226,6 @@ plot_declustered <- function(data, station_col_name, element_col_name, threshold } } } - #This function creates a wrapper around functions from openair package other_rose_plots <- function(data, type1_col_name, type2_col_name, date_col_name, wd_col_name, ws_col_name, main_method, single_pollutant, multiple_pollutant, ...) { type <- "default" @@ -2336,7 +2260,6 @@ other_rose_plots <- function(data, type1_col_name, type2_col_name, date_col_name openair::polarFreq(mydata = data, type = type, pollutant = single_pollutant, ...) } } - #This function creates a wrapper around windRose and pollutionRose functions from openair package wind_pollution_rose <- function(mydata, date_name, pollutant, type1_col_name, type2_col_name, ...) { type <- "default" @@ -2358,12 +2281,10 @@ wind_pollution_rose <- function(mydata, date_name, pollutant, type1_col_name, ty openair::pollutionRose(mydata = mydata, type = type, pollutant, ...) } } - n_non_numeric <- function(x) { x <- as.character(x) sum(is.na(x) != is.na(suppressWarnings(as.numeric(x)))) } - # This function creates a wrapper around grDevices::recordPlot() to enable non-ggplot graphs to be saved as recorded_plot objects. # It also handles graphics devices carefully. record_graph <- function(x) { @@ -2395,8 +2316,6 @@ slopegraph_theme <- function(x_text_size = 12){ ggplot2::theme(axis.text.x.top = ggplot2::element_text(size = x_text_size, face = "bold")), ggplot2::theme(axis.ticks = ggplot2::element_blank())) } - - # slightly amended the "newggslopegraph" function in the CGPfunctions package slopegraph <- function(data, x, y, colour, data_label = NULL, y_text_size = 3, @@ -2523,7 +2442,6 @@ slopegraph <- function(data, x, y, colour, data_label = NULL, ggplot2::geom_label(ggplot2::aes_string(label = Ndata_label), size = data_text_size, label.padding = unit(data_label_padding, "lines"), label.size = data_label_line_size, colour = data_text_colour, fill = data_label_fill_colour) } - # Returns a three-letter string representing a specific quarter in a year (e.g. "JFM", "AMJ" etc.). get_quarter_label <- function(quarter, start_month){ if (!start_month %in% 1:12) stop(start_month, " is an invalid start month, must be in range of 1:12") @@ -2533,27 +2451,21 @@ get_quarter_label <- function(quarter, start_month){ paste(mabb[start_pos:(start_pos+2)], collapse = "")}) return(factor(x = qtr, levels = unique(qtr))) } - is.containVariableLabel <- function(x){ return(isTRUE(sjlabelled::get_label(x) != "")) } - is.emptyvariable <- function(x){ return(isTRUE(length(x) == sum(x == ""))) } - is.NAvariable <- function(x){ return(isTRUE(length(x) == sum(is.na(x)))) } - is.levelscount <- function(x, n){ return(isTRUE(sum(levels(x)) == n)) } - is.containValueLabel <- function(x){ return(labels_label %in% names(attributes(x))) } - is.containPartialValueLabel <- function(x) { if(is.containValueLabel(x)) { levelCounts <- table(x) @@ -2562,7 +2474,6 @@ is.containPartialValueLabel <- function(x) { } else{return(FALSE)} } - read_corpora <- function(data){ data_all <- NULL description <- NULL @@ -2611,8 +2522,6 @@ read_corpora <- function(data){ } return (data.frame(data_all)) } - - # Bind two data frames # and remove any duplicates from data frame x that are in data frame y # x = our data to remove duplicates from @@ -2622,7 +2531,6 @@ cbind_unique <- function(x, y, cols){ x <- x %>% dplyr::select(c(setdiff(names(x), cols))) x <- dplyr::bind_cols(x = x, y = dplyr::select(y, tidyselect::all_of(cols))) } - #object is the object to be displayed #object_format is the display format. If supplied, then returns file name of the object #if not then it prints the object @@ -2639,7 +2547,6 @@ view_object_data <- function(object, object_format = NULL) { } return(file_name) } - view_object <- function(data_book_object) { return( view_object_data( @@ -2648,7 +2555,6 @@ view_object <- function(data_book_object) { ) ) } - #displays the graph object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder @@ -2683,7 +2589,6 @@ view_graph_object <- function(graph_object){ print(graph_object) } dev.off() #todo. use graphics.off() which one is better? - #todo. should we use respective package "convenience" functions to save the objects as image files depending on the class names? #investigate if it will help with resolution and scaling? @@ -2698,7 +2603,6 @@ view_graph_object <- function(graph_object){ return(file_name) } - #displays the object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder @@ -2729,7 +2633,6 @@ view_text_object <- function(text_object){ return(file_name) } - #displays the html object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder @@ -2774,7 +2677,6 @@ view_html_object <- function(html_object){ message("R viewer not detected. File saved in location ", file_name) return(file_name) } - #tries to recordPlot if graph_object = NULL, then returns graph object of class "recordedplot". #applicable to base graphs only check_graph <- function(graph_object){ @@ -2804,8 +2706,6 @@ check_graph <- function(graph_object){ return(out) } - - get_data_book_output_object_names <- function(output_object_list, object_type_label = NULL, excluded_items = c(), @@ -2849,7 +2749,6 @@ get_data_book_output_object_names <- function(output_object_list, } } - get_vignette <- function (package = NULL, lib.loc = NULL, all = TRUE) { oneLink <- function(s) { @@ -2909,7 +2808,6 @@ get_vignette <- function (package = NULL, lib.loc = NULL, all = TRUE) port, basename(file)))} else return(sprintf("file://%s", file)) } - # for issue 8342 - adding in a count of the number of elements that have missing values by period (and station) cumulative_inventory <- function(data, station = NULL, from, to){ if (is.null(station)){ @@ -2939,7 +2837,6 @@ cumulative_inventory <- function(data, station = NULL, from, to){ } return(data) } - getRowHeadersWithText <- function(data, column, searchText, ignore_case, use_regex) { if(use_regex){ # Find the rows that match the search text using regex @@ -2955,7 +2852,6 @@ getRowHeadersWithText <- function(data, column, searchText, ignore_case, use_reg # Return the row headers return(rowHeaders) } - # Custom function to convert character to list of numeric vector convert_to_list <- function(x) { if (grepl("^c\\(", x)) { @@ -2968,7 +2864,6 @@ convert_to_list <- function(x) { return(as.numeric(x)) } } - getExample <- function (topic, package = NULL, lib.loc = NULL, character.only = TRUE, give.lines = FALSE, local = FALSE, echo = TRUE, verbose = getOption("verbose"), setRNG = FALSE, ask = getOption("example.ask"), prompt.prefix = abbreviate(topic, 6), run.dontrun = FALSE, run.donttest = interactive()) { if (!character.only) { topic <- substitute(topic) @@ -3008,7 +2903,6 @@ getExample <- function (topic, package = NULL, lib.loc = NULL, character.only = } return(example_text) } - WB_evaporation <- function(water_balance, frac, capacity, evaporation_value, rain){ if (water_balance >= frac*capacity){ evaporation <- evaporation_value @@ -3030,7 +2924,6 @@ WB_evaporation <- function(water_balance, frac, capacity, evaporation_value, rai } return(evaporation) } - write_weather_data <- function(year, month, day, rain, mn_tmp, mx_tmp, missing_code, output_file) { # Create a data frame with the provided inputs weather_data <- data.frame(year = year, @@ -3047,4 +2940,289 @@ write_weather_data <- function(year, month, day, rain, mn_tmp, mx_tmp, missing_c write.table(weather_data, file = output_file, sep = "\t", row.names = FALSE, col.names = TRUE, quote = FALSE) cat("Weather data has been written to", output_file, "\n") +} +prepare_walter_lieth <- function(data, month, tm_min, ta_min){ + dat_long_int <- NULL + for (j in seq(nrow(data) - 1)) { + intres <- NULL + for (i in seq_len(ncol(data))) { + if (is.character(data[j, i]) | is.factor(data[j, i])) { + val <- as.data.frame(data[j, i]) + } + else { + interpol <- approx(x = data[c(j, j + 1), "indrow"], + y = data[c(j, j + 1), i], + n = 50) + val <- as.data.frame(interpol$y) + } + names(val) <- names(data)[i] + intres <- dplyr::bind_cols(intres, val) + } + dat_long_int <- dplyr::bind_rows(dat_long_int, intres) + } + dat_long_int$interpolate <- TRUE + dat_long_int[[month]] <- "" + data$interpolate <- FALSE + dat_long_int <- dat_long_int[!dat_long_int$indrow %in% data$indrow, ] + dat_long_end <- dplyr::bind_rows(data, dat_long_int) + dat_long_end <- dat_long_end[order(dat_long_end$indrow), ] + dat_long_end <- dat_long_end[dat_long_end$indrow >= 0 & dat_long_end$indrow <= 12, ] + dat_long_end <- tibble::as_tibble(dat_long_end) + + getpolymax <- function(x, y, y_lim) { + initpoly <- FALSE + yres <- NULL + xres <- NULL + for (i in seq_len(length(y))) { + lastobs <- i == length(x) + if (y[i] > y_lim[i]) { + if (isFALSE(initpoly)) { + xres <- c(xres, x[i]) + yres <- c(yres, y_lim[i]) + initpoly <- TRUE + } + xres <- c(xres, x[i]) + yres <- c(yres, y[i]) + if (lastobs) { + xres <- c(xres, x[i], NA) + yres <- c(yres, y_lim[i], NA) + } + } + else { + if (initpoly) { + xres <- c(xres, x[i - 1], NA) + yres <- c(yres, y_lim[i - 1], NA) + initpoly <- FALSE + } + } + } + poly <- tibble::tibble(x = xres, y = yres) + return(poly) + } + getlines <- function(x, y, y_lim) { + yres <- NULL + xres <- NULL + ylim_res <- NULL + for (i in seq_len(length(y))) { + if (y[i] > y_lim[i]) { + xres <- c(xres, x[i]) + yres <- c(yres, y[i]) + ylim_res <- c(ylim_res, y_lim[i]) + } + } + line <- tibble::tibble(x = xres, y = yres, ylim_res = ylim_res) + return(line) + } + prep_max_poly <- getpolymax(x = dat_long_end$indrow, y = pmax(dat_long_end$pm_reesc, + 50), y_lim = rep(50, length(dat_long_end$indrow))) + tm_max_line <- getlines(x = dat_long_end$indrow, y = dat_long_end$tm, + y_lim = dat_long_end$pm_reesc) + pm_max_line <- getlines(x = dat_long_end$indrow, y = pmin(dat_long_end$pm_reesc, + 50), y_lim = dat_long_end$tm) + dat_real <- dat_long_end[dat_long_end$interpolate == FALSE, + c("indrow", ta_min)] + x <- NULL + y <- NULL + for (i in seq_len(nrow(dat_real))) { + if (dat_real[i, ][[ta_min]] < 0) { + x <- c(x, NA, rep(dat_real[i, ]$indrow - 0.5, 2), + rep(dat_real[i, ]$indrow + 0.5, 2), NA) + y <- c(y, NA, -3, 0, 0, -3, NA) + } + else { + x <- c(x, NA) + y <- c(y, NA) + } + } + probfreeze <- tibble::tibble(x = x, y = y) + rm(dat_real) + dat_real <- dat_long_end[dat_long_end$interpolate == FALSE, + c("indrow", tm_min)] + x <- NULL + y <- NULL + for (i in seq_len(nrow(dat_real))) { + if (dat_real[i, ][[tm_min]] < 0) { + x <- c(x, NA, rep(dat_real[i, ]$indrow - 0.5, 2), + rep(dat_real[i, ]$indrow + 0.5, 2), NA) + y <- c(y, NA, -3, 0, 0, -3, NA) + } + else { + x <- c(x, NA) + y <- c(y, NA) + } + } + surefreeze <- tibble::tibble(x = x, y = y) + return_list <- list(dat_long_end, + tm_max_line, + pm_max_line, + prep_max_poly, + probfreeze, + surefreeze) + names(return_list) <- c("dat_long_end", "tm_max_line", "pm_max_line", + "prep_max_poly", "prob_freeze", "surefreeze") + return(return_list) +} +ggwalter_lieth <- function (data, month, station = NULL, p_mes, tm_max, tm_min, ta_min, station_name = "", + alt = NA, per = NA, pcol = "#002F70", + tcol = "#ff0000", pfcol = "#9BAEE2", sfcol = "#3C6FC4", + shem = FALSE, p3line = FALSE, ...) + { + + # Preprocess data with vectorised operations + data <- data %>% + dplyr::mutate(tm = (.data[[tm_max]] + .data[[tm_min]]) / 2, + pm_reesc = dplyr::if_else(.data[[p_mes]] < 100, .data[[p_mes]] * 0.5, .data[[p_mes]] * 0.05 + 45), + p3line = .data[[p_mes]] / 3) %>% + dplyr::mutate(across(.data[[month]], ~ forcats::fct_expand(.data[[month]], ""))) %>% + dplyr::arrange(.data[[month]]) + # do this for each station, if we have a station + if (!is.null(station)){ + data <- data %>% group_by(!!sym(station)) + } + data <- data %>% + group_modify(~{ + # Add dummy rows at the beginning and end for each group + .x <- bind_rows(.x[nrow(.x), , drop = FALSE], .x, .x[1, , drop = FALSE]) + # Clear month value for the dummy rows + .x[c(1, nrow(.x)), which(names(.x) == data[[month]])] <- "" + # Add an index column for plotting or further transformations + .x <- cbind(indrow = seq(-0.5, 12.5, 1), .x) + .x + }) + + if (!is.null(station)){ + data <- data %>% ungroup() + } + data <- data.frame(data) + + # split by station + if (is.null(station)){ + data_list <- prepare_walter_lieth(data, month, tm_min, ta_min) + # data things + dat_long_end <- data_list$dat_long_end + tm_max_line <- data_list$tm_max_line + pm_max_line <- data_list$pm_max_line + prep_max_poly <- data_list$prep_max_poly + probfreeze <- data_list$prob_freeze + surefreeze <- data_list$surefreeze + } else { + results <- + map(.x = unique(data[[station]]), + .f = ~{filtered_data <- data %>% filter(!!sym(station) == .x) + prepare_walter_lieth(filtered_data, month, tm_min, ta_min)}) + # Function to bind rows for a specific sub-element across all main elements + n <- length(results) + m <- length(results[[1]]) + station_name <- unique(data[[station]]) + binds <- NULL + combined <- NULL + for (j in 1:m){ + for (i in 1:n) { # for each station data set + binds[[i]] <- results[[i]][[j]] %>% mutate(!!sym(station) := station_name[i]) + } + combined[[j]] <- do.call(rbind, binds) # Combine all the sub-elements row-wise + } + # data things + dat_long_end <- combined[[1]] + tm_max_line <- combined[[2]] + pm_max_line <- combined[[3]] + prep_max_poly <- combined[[4]] + probfreeze <- combined[[5]] + surefreeze <- combined[[6]] + } + + # data frame pretty things ------------------------------------------------------ + ticks <- data.frame(x = seq(0, 12), ymin = -3, ymax = 0) + title <- station_name + if (!is.na(alt)) { + title <- paste0(title, " (", prettyNum(alt, big.mark = ",", + decimal.mark = "."), " m)") + } + if (!is.na(per)) { + title <- paste0(title, "\n", per) + } + sub <- paste(round(mean(dat_long_end[dat_long_end$interpolate == FALSE, ]$tm), 1), + "C ", + prettyNum(round(sum(dat_long_end[dat_long_end$interpolate == FALSE, ][[p_mes]])), big.mark = ","), " mm", sep = "") + + maxtm <- prettyNum(round(max(dat_long_end[[tm_max]]), 1)) + mintm <- prettyNum(round(min(dat_long_end[[tm_min]]), 1)) + tags <- paste0(paste0(rep(" \n", 6), collapse = ""), maxtm, + paste0(rep(" \n", 10), collapse = ""), mintm) + month_breaks <- dat_long_end[dat_long_end[[month]] != "", ]$indrow + month_labs <- dat_long_end[dat_long_end[[month]] != "", ][[month]] + + ymax <- max(60, 10 * floor(max(dat_long_end$pm_reesc)/10) + 10) + ymin <- min(-3, min(dat_long_end$tm)) + range_tm <- seq(0, ymax, 10) + if (ymin < -3) { + ymin <- floor(ymin/10) * 10 + range_tm <- seq(ymin, ymax, 10) + } + templabs <- paste0(range_tm) + templabs[range_tm > 50] <- "" + range_prec <- range_tm * 2 + range_prec[range_tm > 50] <- range_tm[range_tm > 50] * 20 - 900 + preclabs <- paste0(range_prec) + preclabs[range_tm < 0] <- "" + + wandlplot <- ggplot2::ggplot() + ggplot2::geom_line(data = dat_long_end, + aes(x = .data$indrow, y = .data$pm_reesc), color = pcol) + + ggplot2::geom_line(data = dat_long_end, aes(x = .data$indrow, + y = .data$tm), color = tcol) + if (nrow(tm_max_line > 0)) { + wandlplot <- wandlplot + ggplot2::geom_segment(aes(x = .data$x, + y = .data$ylim_res, xend = .data$x, yend = .data$y), + data = tm_max_line, color = tcol, alpha = 0.2) + } + if (nrow(pm_max_line > 0)) { + wandlplot <- wandlplot + ggplot2::geom_segment(aes(x = .data$x, + y = .data$ylim_res, xend = .data$x, yend = .data$y), + data = pm_max_line, color = pcol, alpha = 0.2) + } + if (p3line) { + wandlplot <- wandlplot + ggplot2::geom_line(data = dat_long_end, + aes(x = .data$indrow, y = .data$p3line), color = pcol) + } + if (max(dat_long_end$pm_reesc) > 50) { + wandlplot <- wandlplot + ggplot2::geom_polygon(data = prep_max_poly, aes(x, y), + fill = pcol) + } + if (min(dat_long_end[[ta_min]]) < 0) { + wandlplot <- wandlplot + ggplot2::geom_polygon(data = probfreeze, aes(x = x, y = y), + fill = pfcol, colour = "black") + } + if (min(dat_long_end[[tm_min]]) < 0) { + wandlplot <- wandlplot + geom_polygon(data = surefreeze, aes(x = x, y = y), + fill = sfcol, colour = "black") + } + wandlplot <- wandlplot + geom_hline(yintercept = c(0, 50), + size = 0.5) + + geom_segment(data = ticks, aes(x = x, xend = x, y = ymin, yend = ymax)) + + scale_x_continuous(breaks = month_breaks, name = "", labels = month_labs, expand = c(0, 0)) + + scale_y_continuous("C", limits = c(ymin, ymax), labels = templabs, + breaks = range_tm, sec.axis = dup_axis(name = "mm", labels = preclabs)) + wandlplot <- wandlplot + + ggplot2::labs(title = title, subtitle = sub, tag = tags) + + ggplot2::theme_classic() + + ggplot2::theme(plot.title = element_text(lineheight = 1, size = 14, face = "bold"), + plot.subtitle = element_text(hjust = 1, vjust = 1, size = 14), + plot.tag = element_text(size = 10), + plot.tag.position = "left", axis.ticks.length.x.bottom = unit(0, "pt"), + axis.line.x.bottom = element_blank(), + axis.title.y.left = element_text(angle = 0, + vjust = 0.9, size = 10, colour = tcol, + margin = unit(rep(10, 4), "pt")), + axis.text.x.bottom = element_text(size = 10), + axis.text.y.left = element_text(colour = tcol, size = 10), + axis.title.y.right = element_text(angle = 0, vjust = 0.9, + size = 10, colour = pcol, + margin = unit(rep(10, 4), "pt")), + axis.text.y.right = element_text(colour = pcol, size = 10)) + + if (!is.null(station)){ + wandlplot <- wandlplot + facet_wrap(station) + } + + return(wandlplot) } \ No newline at end of file From 3d52f15b21eeaef7ab1167c651bd6a4e5c957153 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 10:34:57 +0100 Subject: [PATCH 17/30] Change made --- instat/frmMain.Designer.vb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instat/frmMain.Designer.vb b/instat/frmMain.Designer.vb index 863f5e4816f..ecf06650717 100644 --- a/instat/frmMain.Designer.vb +++ b/instat/frmMain.Designer.vb @@ -5119,7 +5119,9 @@ Partial Class frmMain Me.IsMdiContainer = True Me.MainMenuStrip = Me.mnuBar Me.Name = "frmMain" - Me.Text = "R-Instat .." + Me.Text = "R-Instat " + My.Application.Info.Version.Major.ToString + "." + + My.Application.Info.Version.Minor.ToString + "." + + My.Application.Info.Version.Build.ToString Me.WindowState = System.Windows.Forms.FormWindowState.Maximized Me.stsStrip.ResumeLayout(False) Me.stsStrip.PerformLayout() From 9790eed3e0cac65989f4d00591881aceb22ec109 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 10:49:49 +0100 Subject: [PATCH 18/30] Cchange made --- instat/dlgClimograph.vb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instat/dlgClimograph.vb b/instat/dlgClimograph.vb index 97d6da1aebd..b7c7646e0c5 100644 --- a/instat/dlgClimograph.vb +++ b/instat/dlgClimograph.vb @@ -284,7 +284,8 @@ Public Class dlgClimograph Private Sub ucr1stFactorReceiver_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucr1stFactorReceiver.ControlValueChanged If Not ucr1stFactorReceiver.IsEmpty Then - clsGgwalterliethFunction.AddParameter("station", Chr(34) & ucr1stFactorReceiver.GetVariableNames(False) & Chr(34), iPosition:=1) + 'clsGgwalterliethFunction.AddParameter("station", Chr(34) & ucr1stFactorReceiver.GetVariableNames(False) & Chr(34), iPosition:=1) + clsGgwalterliethFunction.AddParameter("station", ucr1stFactorReceiver.GetVariableNames(), iPosition:=1) Else clsGgwalterliethFunction.RemoveParameterByName("station") End If From c0c3bd9cba4bd905a53f7e5d275b448455452711 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 11:06:16 +0100 Subject: [PATCH 19/30] Change made --- .../InstatObject/R/stand_alone_functions.R | 144 ++++++++++++++++-- 1 file changed, 135 insertions(+), 9 deletions(-) diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index d69af86edbb..e5cb1ade294 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -2,6 +2,7 @@ get_default_significant_figures <- function(data) { if(is.numeric(data)) return(3) else return(NA) } + convert_to_character_matrix <- function(data, format_decimal_places = TRUE, decimal_places, is_scientific = FALSE, return_data_frame = TRUE, na_display = NULL, check.names = TRUE) { if(nrow(data) == 0) { out <- matrix(nrow = 0, ncol = ncol(data)) @@ -39,6 +40,7 @@ convert_to_character_matrix <- function(data, format_decimal_places = TRUE, deci if(return_data_frame) out <- data.frame(out, stringsAsFactors = FALSE, check.names = check.names) return(out) } + next_default_item = function(prefix, existing_names = c(), include_index = FALSE, start_index = 1) { if(!is.character(prefix)) stop("prefix must be of type character") @@ -57,6 +59,7 @@ next_default_item = function(prefix, existing_names = c(), include_index = FALSE } return(out) } + import_from_ODK = function(username, form_name, platform) { if(platform == "kobo") { url <- "https://kc.kobotoolbox.org/api/v1/data" @@ -94,6 +97,7 @@ import_from_ODK = function(username, form_name, platform) { out <- jsonlite::fromJSON(form_data, flatten = TRUE) return(out) } + get_odk_form_names = function(username, platform) { #TODO This should not be repeated if(platform == "kobo") { @@ -118,6 +122,7 @@ get_odk_form_names = function(username, platform) { form_names <- sapply(forms, function(x) x$title) return(form_names) } + convert_SST <- function(datafile, data_from = 5){ start_year <- get_years_from_data(datafile)[1] end_year <- get_years_from_data(datafile)[length(get_years_from_data(datafile))] @@ -147,15 +152,19 @@ convert_SST <- function(datafile, data_from = 5){ my_data = cbind(period, lat_lon_df, SST_value) return(list(my_data, lat_lon_df)) } + get_years_from_data <- function(datafile){ return(na.omit(t(unique(datafile[3,2:ncol(datafile)])))) } + get_lat_from_data <- function(datafile){ return(unique(na.omit(as.numeric(as.character(datafile[5:nrow(datafile),1]))))) } + get_lon_from_data <- function(datafile){ return(na.omit(as.numeric(unique(t(datafile[5,2:ncol(datafile)]))))) } + lat_lon_dataframe <- function(datafile){ latitude <- get_lat_from_data(datafile) longitude <- get_lon_from_data(datafile) @@ -173,6 +182,7 @@ lat_lon_dataframe <- function(datafile){ } return(cbind(lat_lon,station)) } + output_CPT <- function(data, lat_lon_data, station_latlondata, latitude, longitude, station, year, element, long.data = TRUE, na_code = -999) { if(missing(data)) stop("data should be provided") @@ -246,20 +256,24 @@ output_CPT <- function(data, lat_lon_data, station_latlondata, latitude, longitu cpt_data <- rbind(t_lat_lon_data, unstacked_data) return(cpt_data) } + yday_366 <- function(date) { temp_doy <- lubridate::yday(date) temp_leap <- lubridate::leap_year(date) temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] <- 1 + temp_doy[(!is.na(temp_doy)) & temp_doy > 59 & (!temp_leap)] return(temp_doy) } + dekade <- function(date) { temp_dekade <- 3 * (lubridate::month(date)) - 2 + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 20) return(temp_dekade) } + pentad <- function(date){ temp_pentad <- 6*(lubridate::month(date)) - 5 + (lubridate::mday(date) > 5) + (lubridate::mday(date) > 10) + (lubridate::mday(date) > 15) + (lubridate::mday(date) > 20) + (lubridate::mday(date) > 25) return(temp_pentad) } + nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { if(!dimension %in% names(nc$dim)) stop(dimension, " not found in file.") vals <- nc$dim[[dimension]]$vals @@ -285,6 +299,7 @@ nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { bounds <- c(min(vals, na.rm = TRUE), max(vals, na.rm = TRUE)) return(bounds) } + nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE) { if(missing(vars)) vars <- ncdf4.helpers::nc.get.variable.list(nc) if(sum(is.null(lon_points), is.null(lat_points)) == 1) stop("You must specificy both lon_points and lat_points") @@ -403,6 +418,7 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = count_list[[1]] <- count dim_values_list[[1]] <- dim_values } + dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc) time_dims <- names(dim_axes[which(dim_axes == "T" & names(dim_axes) %in% dim_names)]) var_data_list <- list() @@ -517,6 +533,7 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = } return(var_data) } + # open_NetCDF <- function(nc_data, latitude_col_name, longitude_col_name, default_names){ # variables = names(nc_data$var) # lat_lon_names = names(nc_data$dim) @@ -596,6 +613,7 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = # } # return(list(my_data, lat_lon_df, new_lat_lon_column_names)) # } + multiple_nc_as_data_frame <- function(path, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = TRUE, id = "id") { filepaths <- list.files(path = path, pattern="*\\.nc", full.names = TRUE) filenames <- basename(filepaths) @@ -617,6 +635,7 @@ multiple_nc_as_data_frame <- function(path, vars, keep_raw_time = TRUE, include_ merged_data <- dplyr::bind_rows(nc_list, .id = id) return(merged_data) } + import_from_iri <- function(download_from, data_file, path, X1, X2,Y1,Y2, get_area_point){ if(path == ""){ gaugelocdir = getwd() @@ -776,38 +795,46 @@ import_from_iri <- function(download_from, data_file, path, X1, X2,Y1,Y2, get_ar file.remove(paste(gaugelocdir,"tmp_iri.csv",sep="/")) return(list(dataout,lat_lon_dataframe)) } + is.logical.like <- function(x) { if(is.logical(x)) return(TRUE) else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0))) else return(FALSE) } + is.binary <- function(x) { if(is.logical(x)) return(TRUE) else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0))) else if(is.factor(x)) return(nlevels(x) == 2) else return(FALSE) } + get_column_attributes <- function(x, drop = c("class", "levels")) { tmp_attr <- attributes(x) tmp_attr <- tmp_attr[!names(tmp_attr) %in% drop] return(tmp_attr) } + split_items_in_groups <- function(items, num) { if(length(items) %% num != 0) stop("The number of items must be divisible by the number of groups") x <- split(items, rep(1:num, each = length(items)/num)) return(x) } + cancor_coef <- function(object) { object[c("xcoef", "ycoef")] } ################### + # cmsaf Plot.Region script + # # This script displays a map of the selected product. # You can either specify a certain year / month from a data file with several time steps # or plot one 2D field. # Prepare the your netcdf-files with the R-script "Prep.Data.R" or "Apply.Function.R" ########################################################################################## + plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-01"), add2title = "CM SAF, ", lonmin = NA, lonmax = NA, latmin = NA, latmax = NA, height = 600, width = 600, plot.ano = FALSE, set.col.breaks = FALSE, brk.set = seq(240,310,5), colmin0 = NA, colmax0 = NA, ncol = 14, plotHighRes = FALSE, plotCoastline = TRUE, plotCountries = TRUE, plotRivers = FALSE, contour.thick = 2, plotCities = TRUE, pch.cities = 2, cex.cities = 1, label.cities = TRUE, plotCapitals = 1, cex.label.cities = 0.5, dlat = 0.25, plotOwnLocations = FALSE, loc_lon = c(), loc_lat = c(), loc_name = c(""), label_pos = 1, variable = "Tm", level = 5, CTY.type = 4) { # Set the variable name @@ -886,6 +913,7 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 if (varname == "CTY") datalev <- CTY.type #--------------------------------------------------# + # Invert the latitude dimension if necessary if (lat[ny] < lat[1]) { sort.out <- sort(lat,index.return=TRUE) @@ -1034,6 +1062,7 @@ plot.region <- function(lon, lat, product, time, time_point = as.Date("2002-01-0 axis(3,lwd=1,at=c(lonmin,lonmax),tick=TRUE,lwd.ticks=0,labels=FALSE) axis(4,lwd=1,at=c(latmin,latmax), tick=TRUE,lwd.ticks=0,labels=FALSE) } + duplicated_cases <- function(col_name, ignore = NULL, tolerance=0.01) { col_name <- as.vector(col_name) col_data1 <- c(1, rep(NA, length(col_name) - 1)) @@ -1060,6 +1089,7 @@ duplicated_cases <- function(col_name, ignore = NULL, tolerance=0.01) { } return(col_data1) } + #This is Sam function from issue #4270 duplicated_count_index<-function(x, type = "count"){ if(type == "count"){ @@ -1092,17 +1122,21 @@ duplicated_count_index<-function(x, type = "count"){ return(x$count) } } + + get_installed_packages_with_data <- function(with_data = TRUE) { all_installed_packages <- .packages(all.available = TRUE) if (with_data) all_installed_packages <- unique(data(package = all_installed_packages)[["results"]][,1]) return(all_installed_packages) } + drop_unused_levels <- function(dat, columns) { for(i in seq_along(columns)) { if(is.factor(dat[[columns[i]]])) dat[[columns[i]]] <- droplevels(dat[[columns[i]]]) } return(dat) } + compare_columns <- function(x, y, use_unique = TRUE, sort_values = TRUE, firstnotsecond = TRUE, secondnotfirst = TRUE, display_intersection = FALSE, display_union = FALSE, display_values = TRUE) { x_name <- deparse(substitute(x)) y_name <- deparse(substitute(y)) @@ -1143,6 +1177,8 @@ compare_columns <- function(x, y, use_unique = TRUE, sort_values = TRUE, firstno if(display_union) cat(paste0("Union (Values that appear in either column): ", paste0("'", dplyr::union(x, y), "'", collapse = ", "))) } } + + consecutive_sum <- function(x, initial_value = NA){ out = x for(i in 1:length(x)){ @@ -1158,9 +1194,11 @@ consecutive_sum <- function(x, initial_value = NA){ } return(out) } + max_consecutive_sum <- function(x){ max(consecutive_sum(x, initial_value = 0)) } + hashed_id <- function(x, salt, algo = "crc32") { if (missing(salt)){ y <- x @@ -1169,7 +1207,9 @@ hashed_id <- function(x, salt, algo = "crc32") { } y <- sapply(y, function(X) digest::digest(X, algo = algo)) as.character(y) + } + # Possible alternative but is slower: # spells <- function(z) { # Reduce(function(x,y) {y = dplyr::if_else(y == 0, 0, x + 1)}, z[-1], @@ -1187,6 +1227,7 @@ hashed_id <- function(x, salt, algo = "crc32") { } return(y) } + convert_to_dec_deg <- function (dd, mm = 0 , ss = 0, dir) { if(missing(dd)) stop("dd must be supplied") if(!missing(dir)) { @@ -1200,14 +1241,17 @@ convert_to_dec_deg <- function (dd, mm = 0 , ss = 0, dir) { decdeg <- (dd + ((mm * 60) + ss)/3600) * sgn return(decdeg) } + convert_yy_to_yyyy <- function (x, base) { if(missing(base)) stop("base year must be supplied") dplyr::if_else(x+2000 <= base, x+2000, x+1900) } + create_av_packs <- function() { av_packs <<- available.packages(repos = "https://cran.rstudio.com/") av_packs <<- data.frame(av_packs) } + package_check <- function(package) { out <- c() if (!pingr::is_online()) out[[1]] <- "5" @@ -1250,11 +1294,13 @@ in_top_n <- function(x, n = 10, wt, fun = sum) { else dat <- dat %>% dplyr::count(x, sort = TRUE, name = "fq") return(x %in% dat$x[1:n]) } + summary_sample <- function(x, size, replace = FALSE){ if(length(x)==0){return(NA)} else if(length(x)==1){return(x)} else{sample(x = x, size = size, replace = replace)} } + add_xy_area_range <- function(path, min_lon, max_lon, min_lat, max_lat, dim_x = "X", dim_y = "Y") { paste0( path, "/", dim_x, "/", @@ -1267,6 +1313,7 @@ add_xy_area_range <- function(path, min_lon, max_lon, min_lat, max_lat, dim_x = "RANGEEDGES", "/" ) } + add_xy_point_range <- function(path, min_lon, min_lat, dim_x = "X", dim_y = "Y") { paste0( path, "/", dim_x, "/", @@ -1277,6 +1324,7 @@ add_xy_point_range <- function(path, min_lon, min_lat, dim_x = "X", dim_y = "Y") "VALUES", "/" ) } + add_t_range <- function(path, min_date, max_date, dim_t = "T") { paste0( path, dim_t, "/", @@ -1287,6 +1335,7 @@ add_t_range <- function(path, min_date, max_date, dim_t = "T") { "RANGEEDGES", "/" ) } + add_nc <- function(path) { paste0(path, "data.nc") } @@ -1298,6 +1347,8 @@ fourier_series <- function(x, n, period) { "cos(", x, " * ", h, " * ", p2, " / ", period, ")", collapse = " + ") } + + climatic_missing <- function(data, date, elements = ..., stations, start = TRUE, end = FALSE){ @@ -1317,6 +1368,7 @@ climatic_missing <- function(data, date, elements = ..., stations, values_to = "value") # sort start/end times + # set start date if (start){ data.stack <- data.stack %>% @@ -1366,8 +1418,10 @@ climatic_missing <- function(data, date, elements = ..., stations, if (missing(stations)){ summary.data$stations <- NULL } + return(summary.data) } + climatic_details <- function(data, date, elements = ..., stations, @@ -1436,6 +1490,7 @@ climatic_details <- function(data, date, elements = ..., stations, From = dplyr::first({{ date }}), To = dplyr::last({{ date }})) %>% dplyr::mutate(is.complete = ifelse(no == na, 1, 0)) # 0 if all are missing + detail.table.month <- detail.table.month %>% dplyr::group_by({{ stations }}, Element) %>% dplyr::mutate(element.na = data.table::rleid(is.complete)) %>% @@ -1493,11 +1548,15 @@ climatic_details <- function(data, date, elements = ..., stations, dplyr::mutate(Level = make_factor(Level)) return(detail.table.all) + } + slope <- function(y, x) { x <- as.numeric(x) lm(y ~ x)$coefficients[2] + } + # make_factor is intended to be somewhat equivalent to forcats::as_factor() or base::as.factor(). # It provides default behaviour for converting to factor depending on the data type, similar to forcats::as_factor(). # For "character" and "numeric" types make_factor is consistent with forcats::as_factor() in terms of the order of the factor levels. @@ -1524,6 +1583,9 @@ make_factor <- function(x, ordered = is.ordered(x)) { factor(x, levels = as.character(unique(x)), ordered = ordered) } } + + + # wwr_export function is meant to reshape data into formats required by WMO for submission of climatic data # this gives Yearly data records with monthly and annual data for a particular year: wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_pressure, @@ -1789,6 +1851,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ } cat(i, "file(s) created at:", folder) } + dd_to_dms <- function(x, lat) { if (lat) dir <- ifelse(x >= 0, "N", "S") else dir <- ifelse(x >= 0, "E", "W") @@ -1798,6 +1861,7 @@ dd_to_dms <- function(x, lat) { s <- round((x - d - m/60) * 3600) return(paste(sprintf(ifelse(lat, "%02d", "%03d"), d), sprintf("%02d", m), sprintf("%02d", s), dir)) } + plot_mrl <- function(data, station_name, element_name, umin, umax, ncol = 1, xlab = "Threshold", ylab = "Mean excess", fill = "red", col = "black", rug = TRUE, addNexcesses = TRUE, textsize = 4) { @@ -1835,10 +1899,13 @@ plot_mrl <- function(data, station_name, element_name, umin, umax, ncol = 1, ) } } + + ### Constants month_abb_english <- c("Jan","Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") month_name_english <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") + # factored out code for a multiple indices for a single station. # Called by climdex(). # Not intended to be used externally. @@ -1896,6 +1963,7 @@ climdex_single_station <- function(ci, freq = "annual", indices, year, month, } return(df_ind) } + climdex <- function(data, station, date, year, month, prec, tmax, tmin, indices, freq = "annual", base.range = c(1961, 1990), n = 5, northern.hemisphere = TRUE, quantiles = NULL, temp.qtiles = c(0.1, 0.9), @@ -1985,6 +2053,7 @@ climdex <- function(data, station, date, year, month, prec, tmax, tmin, indices, } return(df_out) } + spei_input <- function(data, station, year, month, element) { if (missing(station)) id_cols <- c(year, month) else id_cols <- c(station, year, month) # SPEI package assumes data is ordered so must be sorted @@ -2024,6 +2093,7 @@ spei_input <- function(data, station, year, month, element) { } ts_data } + # This function extracts the SPEI/SPI column from an spei object x. # It requires the original data in order to return a vector of the correct length by removing NA values introduced when unstacking. # An alternative to this is to have a single wrapper SPEI/SPI function to handle this. @@ -2057,7 +2127,9 @@ spei_output <- function(x, data, station, year, month) { col <- as.vector(vals) } col + } + # This function has been adapted from extRemes::threshrange.plot(). # It has been adapted for use in R-Instat and uses ggplot2 graphical system rather than base plot(). threshold_Plot <- function(x, r, type = c("GP", "PP", "Exponential"), nint = 10, @@ -2172,6 +2244,7 @@ threshold_Plot <- function(x, r, type = c("GP", "PP", "Exponential"), nint = 10, } patchwork::wrap_plots(lst_plots, ncol = 1) } + # This function produces multiple threshold plots for various stations at a time. plot_multiple_threshold <- function(data, station_col_name, element_col_name, r, type = c("GP", "PP", "Exponential"), nint = 10, alpha = 0.05, ncol = 1, xlb = "", main = NULL , verbose = FALSE,...) { @@ -2191,6 +2264,8 @@ plot_multiple_threshold <- function(data, station_col_name, element_col_name, r, threshold_Plot(x = element_col, r = r, type = type, nint = nint, alpha = alpha, verbose = verbose) } } + + plot_declustered <- function(data, station_col_name, element_col_name, threshold, r = NULL, xlab = NULL, ylab = NULL, ncol = 1, print_summary = FALSE) { if (!missing(station_col_name)) { plts <- list() @@ -2226,6 +2301,7 @@ plot_declustered <- function(data, station_col_name, element_col_name, threshold } } } + #This function creates a wrapper around functions from openair package other_rose_plots <- function(data, type1_col_name, type2_col_name, date_col_name, wd_col_name, ws_col_name, main_method, single_pollutant, multiple_pollutant, ...) { type <- "default" @@ -2260,6 +2336,7 @@ other_rose_plots <- function(data, type1_col_name, type2_col_name, date_col_name openair::polarFreq(mydata = data, type = type, pollutant = single_pollutant, ...) } } + #This function creates a wrapper around windRose and pollutionRose functions from openair package wind_pollution_rose <- function(mydata, date_name, pollutant, type1_col_name, type2_col_name, ...) { type <- "default" @@ -2281,10 +2358,12 @@ wind_pollution_rose <- function(mydata, date_name, pollutant, type1_col_name, ty openair::pollutionRose(mydata = mydata, type = type, pollutant, ...) } } + n_non_numeric <- function(x) { x <- as.character(x) sum(is.na(x) != is.na(suppressWarnings(as.numeric(x)))) } + # This function creates a wrapper around grDevices::recordPlot() to enable non-ggplot graphs to be saved as recorded_plot objects. # It also handles graphics devices carefully. record_graph <- function(x) { @@ -2316,6 +2395,8 @@ slopegraph_theme <- function(x_text_size = 12){ ggplot2::theme(axis.text.x.top = ggplot2::element_text(size = x_text_size, face = "bold")), ggplot2::theme(axis.ticks = ggplot2::element_blank())) } + + # slightly amended the "newggslopegraph" function in the CGPfunctions package slopegraph <- function(data, x, y, colour, data_label = NULL, y_text_size = 3, @@ -2442,6 +2523,7 @@ slopegraph <- function(data, x, y, colour, data_label = NULL, ggplot2::geom_label(ggplot2::aes_string(label = Ndata_label), size = data_text_size, label.padding = unit(data_label_padding, "lines"), label.size = data_label_line_size, colour = data_text_colour, fill = data_label_fill_colour) } + # Returns a three-letter string representing a specific quarter in a year (e.g. "JFM", "AMJ" etc.). get_quarter_label <- function(quarter, start_month){ if (!start_month %in% 1:12) stop(start_month, " is an invalid start month, must be in range of 1:12") @@ -2451,21 +2533,27 @@ get_quarter_label <- function(quarter, start_month){ paste(mabb[start_pos:(start_pos+2)], collapse = "")}) return(factor(x = qtr, levels = unique(qtr))) } + is.containVariableLabel <- function(x){ return(isTRUE(sjlabelled::get_label(x) != "")) } + is.emptyvariable <- function(x){ return(isTRUE(length(x) == sum(x == ""))) } + is.NAvariable <- function(x){ return(isTRUE(length(x) == sum(is.na(x)))) } + is.levelscount <- function(x, n){ return(isTRUE(sum(levels(x)) == n)) } + is.containValueLabel <- function(x){ return(labels_label %in% names(attributes(x))) } + is.containPartialValueLabel <- function(x) { if(is.containValueLabel(x)) { levelCounts <- table(x) @@ -2474,6 +2562,7 @@ is.containPartialValueLabel <- function(x) { } else{return(FALSE)} } + read_corpora <- function(data){ data_all <- NULL description <- NULL @@ -2522,6 +2611,8 @@ read_corpora <- function(data){ } return (data.frame(data_all)) } + + # Bind two data frames # and remove any duplicates from data frame x that are in data frame y # x = our data to remove duplicates from @@ -2531,6 +2622,7 @@ cbind_unique <- function(x, y, cols){ x <- x %>% dplyr::select(c(setdiff(names(x), cols))) x <- dplyr::bind_cols(x = x, y = dplyr::select(y, tidyselect::all_of(cols))) } + #object is the object to be displayed #object_format is the display format. If supplied, then returns file name of the object #if not then it prints the object @@ -2542,11 +2634,12 @@ view_object_data <- function(object, object_format = NULL) { file_name <- view_text_object(object) } else if (identical(object_format, "html")) { file_name <- view_html_object(object) - }else{ + } else{ print(object) } return(file_name) } + view_object <- function(data_book_object) { return( view_object_data( @@ -2555,6 +2648,7 @@ view_object <- function(data_book_object) { ) ) } + #displays the graph object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder @@ -2589,6 +2683,7 @@ view_graph_object <- function(graph_object){ print(graph_object) } dev.off() #todo. use graphics.off() which one is better? + #todo. should we use respective package "convenience" functions to save the objects as image files depending on the class names? #investigate if it will help with resolution and scaling? @@ -2603,6 +2698,7 @@ view_graph_object <- function(graph_object){ return(file_name) } + #displays the object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder @@ -2633,11 +2729,29 @@ view_text_object <- function(text_object){ return(file_name) } + +view_html_object <- function(html_object) { + # Check if html_object is a list and has more than one element + if (is.list(html_object) && all(sapply(html_object, class) == class(html_object[[1]]))) { + file_names <- vector("list", length(html_object)) + for (i in seq_along(html_object)) { + # If html_object is a list with multiple elements of the same class, + # use a for loop to process each element + file_names[[i]] <- process_html_object(html_object[[i]]) + } + return(file_names) + } + + # Process the html_object + return(process_html_object(html_object)) +} + +#Function to process individual HTML object #displays the html object in the set R "viewer". #if the viewer is not available then #it saves the object as a file in the temporary folder #and returns the file path. -view_html_object <- function(html_object){ +process_html_object <- function(html_object) { #if there is a viewer, like in the case of RStudio then just print the object #this check is primarily meant to make this function work in a similar manner when run outside R-Instat r_viewer <- base::getOption("viewer") @@ -2648,14 +2762,13 @@ view_html_object <- function(html_object){ return(html_object) } + # Get a unique temporary file name from the tempdir path + file_name <- tempfile(pattern = "viewhtml", fileext = ".html") - file_name <- "" - #get a vector of available class names + # Get a vector of available class names object_class_names <- class(html_object) - #get a unique temporary file name from the tempdir path - file_name <- tempfile(pattern = "viewhtml", fileext = ".html") - #save the object as a html file depending on the object type + # Save the object as an HTML file depending on the object type if ("htmlwidget" %in% object_class_names) { #Note. When selfcontained is set to True #a "Saving a widget with selfcontained = TRUE requires pandoc" error is thrown in R-Instat @@ -2671,12 +2784,15 @@ view_html_object <- function(html_object){ } else if ("gt_tbl" %in% object_class_names) { #"gt table" objects are not compatible with "htmlwidgets" package. So they have to be saved differently. #"mmtable2" package produces "gt_tbl" objects - gt::gtsave(html_object,filename = file_name) + gt::gtsave(html_object, filename = file_name) } message("R viewer not detected. File saved in location ", file_name) return(file_name) -} +} + + + #tries to recordPlot if graph_object = NULL, then returns graph object of class "recordedplot". #applicable to base graphs only check_graph <- function(graph_object){ @@ -2706,6 +2822,8 @@ check_graph <- function(graph_object){ return(out) } + + get_data_book_output_object_names <- function(output_object_list, object_type_label = NULL, excluded_items = c(), @@ -2749,6 +2867,7 @@ get_data_book_output_object_names <- function(output_object_list, } } + get_vignette <- function (package = NULL, lib.loc = NULL, all = TRUE) { oneLink <- function(s) { @@ -2808,6 +2927,7 @@ get_vignette <- function (package = NULL, lib.loc = NULL, all = TRUE) port, basename(file)))} else return(sprintf("file://%s", file)) } + # for issue 8342 - adding in a count of the number of elements that have missing values by period (and station) cumulative_inventory <- function(data, station = NULL, from, to){ if (is.null(station)){ @@ -2837,6 +2957,7 @@ cumulative_inventory <- function(data, station = NULL, from, to){ } return(data) } + getRowHeadersWithText <- function(data, column, searchText, ignore_case, use_regex) { if(use_regex){ # Find the rows that match the search text using regex @@ -2852,6 +2973,7 @@ getRowHeadersWithText <- function(data, column, searchText, ignore_case, use_reg # Return the row headers return(rowHeaders) } + # Custom function to convert character to list of numeric vector convert_to_list <- function(x) { if (grepl("^c\\(", x)) { @@ -2864,6 +2986,7 @@ convert_to_list <- function(x) { return(as.numeric(x)) } } + getExample <- function (topic, package = NULL, lib.loc = NULL, character.only = TRUE, give.lines = FALSE, local = FALSE, echo = TRUE, verbose = getOption("verbose"), setRNG = FALSE, ask = getOption("example.ask"), prompt.prefix = abbreviate(topic, 6), run.dontrun = FALSE, run.donttest = interactive()) { if (!character.only) { topic <- substitute(topic) @@ -2903,6 +3026,7 @@ getExample <- function (topic, package = NULL, lib.loc = NULL, character.only = } return(example_text) } + WB_evaporation <- function(water_balance, frac, capacity, evaporation_value, rain){ if (water_balance >= frac*capacity){ evaporation <- evaporation_value @@ -2924,6 +3048,7 @@ WB_evaporation <- function(water_balance, frac, capacity, evaporation_value, rai } return(evaporation) } + write_weather_data <- function(year, month, day, rain, mn_tmp, mx_tmp, missing_code, output_file) { # Create a data frame with the provided inputs weather_data <- data.frame(year = year, @@ -2941,6 +3066,7 @@ write_weather_data <- function(year, month, day, rain, mn_tmp, mx_tmp, missing_c cat("Weather data has been written to", output_file, "\n") } + prepare_walter_lieth <- function(data, month, tm_min, ta_min){ dat_long_int <- NULL for (j in seq(nrow(data) - 1)) { From 4c3ad54e119235b723a967ef962adf0bd24c5cb3 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 28 Mar 2024 17:06:48 +0100 Subject: [PATCH 20/30] Change made --- instat/dlgEvapotranspiration.vb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/instat/dlgEvapotranspiration.vb b/instat/dlgEvapotranspiration.vb index 13e70ffc238..45452879aa7 100644 --- a/instat/dlgEvapotranspiration.vb +++ b/instat/dlgEvapotranspiration.vb @@ -226,8 +226,6 @@ Public Class dlgEvapotranspiration clsReadInputsFunction.AddParameter("varnames", clsRFunctionParameter:=clsVarnamesVectorPMFunction, iPosition:=0) clsReadInputsFunction.AddParameter("climatedata", clsRFunctionParameter:=clsDataFunctionPMFunction, iPosition:=1) clsReadInputsFunction.AddParameter("missing_method", Chr(34) & "monthly average" & Chr(34), iPosition:=8) - clsReadInputsFunction.AddParameter("varnames", clsRFunctionParameter:=clsVarnamesVectorPTFunction, iPosition:=10) - clsReadInputsFunction.AddParameter("climatedata", clsRFunctionParameter:=clsDataFunctionPTFunction, iPosition:=11) clsReadInputsFunction.SetAssignTo("temp_data") clsVarnamesVectorPTFunction.SetRCommand("c") @@ -295,6 +293,8 @@ Public Class dlgEvapotranspiration ucrBase.clsRsyntax.ClearCodes() ucrBase.clsRsyntax.SetBaseROperator(clsBaseOperator) ucrBase.clsRsyntax.AddToBeforeCodes(clsListFunction, iPosition:=1) + + Constants() End Sub Private Sub SetRCodeForControls(bReset As Boolean) @@ -316,7 +316,6 @@ Public Class dlgEvapotranspiration ucrReceiverTmin.SetRCode(clsDataFunctionPMFunction, bReset) ucrReceiverHumidityMax.SetRCode(clsDataFunctionPMFunction, bReset) ucrReceiverHumidityMin.SetRCode(clsDataFunctionPMFunction, bReset) - ucrReceiverWindSpeed.SetRCode(clsDataFunctionPMFunction, bReset) ucrInputTimeStep.SetRCode(clsETPenmanMonteithFunction, bReset) ucrInputCrop.SetRCode(clsETPenmanMonteithFunction, bReset) ucrChkWind.SetRCode(clsETPenmanMonteithFunction, bReset) @@ -324,6 +323,7 @@ Public Class dlgEvapotranspiration ucrPnlMethod.SetRCode(clsBaseOperator, bReset) ucrNudAlpha.SetRCode(clsETPriestleyTaylorFunction, bReset) If bReset Then + ucrReceiverWindSpeed.SetRCode(clsDataFunctionPMFunction, bReset) ucrInputSolar.SetRCode(clsETPenmanMonteithFunction, bReset) End If End Sub @@ -488,9 +488,9 @@ Public Class dlgEvapotranspiration Private Sub ucrReceiverWindSpeed_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverWindSpeed.ControlValueChanged, ucrChkWind.ControlValueChanged If ucrChkWind.Checked AndAlso Not ucrReceiverWindSpeed.IsEmpty Then - clsVarnamesVectorPMFunction.AddParameter("u2", Chr(34) & "u2" & Chr(34), bIncludeArgumentName:=False) + clsVarnamesVectorPMFunction.AddParameter("x", Chr(34) & "u2" & Chr(34), bIncludeArgumentName:=False) Else - clsVarnamesVectorPMFunction.RemoveParameterByName("u2") + clsVarnamesVectorPMFunction.RemoveParameterByName("x") ucrReceiverHumidityMax.SetMeAsReceiver() End If End Sub @@ -610,7 +610,7 @@ Public Class dlgEvapotranspiration Solar() End Sub - Private Sub ucrPnlMethod_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrPnlMethod.ControlContentsChanged, ucrNewColName.ControlContentsChanged, ucrReceiverDate.ControlContentsChanged, ucrReceiverTmax.ControlContentsChanged, ucrReceiverTmin.ControlContentsChanged, ucrReceiverHumidityMax.ControlContentsChanged, ucrReceiverHumidityMin.ControlContentsChanged, ucrReceiverRadiation.ControlContentsChanged, ucrReceiverWindSpeed.ControlContentsChanged, ucrInputTimeStep.ControlContentsChanged, ucrChkWind.ControlContentsChanged, ucrChkWind.ControlContentsChanged + Private Sub ucrPnlMethod_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrPnlMethod.ControlContentsChanged, ucrNewColName.ControlContentsChanged, ucrReceiverDate.ControlContentsChanged, ucrReceiverTmax.ControlContentsChanged, ucrReceiverTmin.ControlContentsChanged, ucrReceiverHumidityMax.ControlContentsChanged, ucrReceiverHumidityMin.ControlContentsChanged, ucrReceiverRadiation.ControlContentsChanged, ucrReceiverWindSpeed.ControlContentsChanged, ucrInputTimeStep.ControlContentsChanged, ucrChkWind.ControlContentsChanged TestOKEnabled() End Sub End Class From 717e5d74a6494557cde78d4018e821599a2ec7c5 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 3 Apr 2024 11:11:13 +0100 Subject: [PATCH 21/30] Update stand_alone_functions.R --- .../InstatObject/R/stand_alone_functions.R | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index e5cb1ade294..92267e8ece8 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3259,22 +3259,6 @@ ggwalter_lieth <- function (data, month, station = NULL, p_mes, tm_max, tm_min, # data frame pretty things ------------------------------------------------------ ticks <- data.frame(x = seq(0, 12), ymin = -3, ymax = 0) - title <- station_name - if (!is.na(alt)) { - title <- paste0(title, " (", prettyNum(alt, big.mark = ",", - decimal.mark = "."), " m)") - } - if (!is.na(per)) { - title <- paste0(title, "\n", per) - } - sub <- paste(round(mean(dat_long_end[dat_long_end$interpolate == FALSE, ]$tm), 1), - "C ", - prettyNum(round(sum(dat_long_end[dat_long_end$interpolate == FALSE, ][[p_mes]])), big.mark = ","), " mm", sep = "") - - maxtm <- prettyNum(round(max(dat_long_end[[tm_max]]), 1)) - mintm <- prettyNum(round(min(dat_long_end[[tm_min]]), 1)) - tags <- paste0(paste0(rep(" \n", 6), collapse = ""), maxtm, - paste0(rep(" \n", 10), collapse = ""), mintm) month_breaks <- dat_long_end[dat_long_end[[month]] != "", ]$indrow month_labs <- dat_long_end[dat_long_end[[month]] != "", ][[month]] @@ -3329,13 +3313,8 @@ ggwalter_lieth <- function (data, month, station = NULL, p_mes, tm_max, tm_min, scale_y_continuous("C", limits = c(ymin, ymax), labels = templabs, breaks = range_tm, sec.axis = dup_axis(name = "mm", labels = preclabs)) wandlplot <- wandlplot + - ggplot2::labs(title = title, subtitle = sub, tag = tags) + ggplot2::theme_classic() + - ggplot2::theme(plot.title = element_text(lineheight = 1, size = 14, face = "bold"), - plot.subtitle = element_text(hjust = 1, vjust = 1, size = 14), - plot.tag = element_text(size = 10), - plot.tag.position = "left", axis.ticks.length.x.bottom = unit(0, "pt"), - axis.line.x.bottom = element_blank(), + ggplot2::theme(axis.line.x.bottom = element_blank(), axis.title.y.left = element_text(angle = 0, vjust = 0.9, size = 10, colour = tcol, margin = unit(rep(10, 4), "pt")), @@ -3351,4 +3330,4 @@ ggwalter_lieth <- function (data, month, station = NULL, p_mes, tm_max, tm_min, } return(wandlplot) -} \ No newline at end of file +} From ae0c9a403090f2f8f1827ebb8dc35d993f9a80d9 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 3 Apr 2024 11:14:14 +0100 Subject: [PATCH 22/30] size to linewidth --- instat/static/InstatObject/R/stand_alone_functions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index 92267e8ece8..3117ee37ac6 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3307,7 +3307,7 @@ ggwalter_lieth <- function (data, month, station = NULL, p_mes, tm_max, tm_min, fill = sfcol, colour = "black") } wandlplot <- wandlplot + geom_hline(yintercept = c(0, 50), - size = 0.5) + + linewidth = 0.5) + geom_segment(data = ticks, aes(x = x, xend = x, y = ymin, yend = ymax)) + scale_x_continuous(breaks = month_breaks, name = "", labels = month_labs, expand = c(0, 0)) + scale_y_continuous("C", limits = c(ymin, ymax), labels = templabs, From 3cdf805264f881df56b87c0e97754c9558c5e22b Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:28:39 +0200 Subject: [PATCH 23/30] Code Changes --- instat/dlgTransform.vb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 18a169332fc..dd224231125 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -419,7 +419,6 @@ Public Class dlgTransform ucrReceiverRank.SetMeAsReceiver() ucrSaveNew.Reset() ucrInputLogicOperations.SetText("==") - rdoSingle.Checked = True clsConstantDummyFunction.AddParameter("checked", "FALSE", iPosition:=0) clsConstantDummyFunction.AddParameter("preview", "TRUE", iPosition:=1) @@ -635,7 +634,6 @@ Public Class dlgTransform clsAssignOperator.AddParameter("left", clsRFunctionParameter:=clsColumnsFunction, iPosition:=0) clsAssignOperator.AddParameter("right", clsRFunctionParameter:=clsPasteFunction, iPosition:=1) - clsAddColumnsFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data") clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsAddColumnsFunction.AddParameter("before", "FALSE", iPosition:=2) @@ -768,14 +766,13 @@ Public Class dlgTransform Private Sub NewDefaultName() If rdoSingle.Checked Then ucrSaveNew.SetLabelText("New Column Name:") - If (Not ucrSaveNew.bUserTyped) AndAlso Not ucrReceiverRank.IsEmpty Then + If Not ucrSaveNew.bUserTyped AndAlso Not ucrReceiverRank.IsEmpty Then ucrSaveNew.SetPrefix(ucrReceiverRank.GetVariableNames(bWithQuotes:=False)) End If ElseIf rdoMultiple.Checked Then ucrSaveNew.SetLabelText("Suffix Name:") ucrSaveNew.btnColumnPosition.Visible = False If Not ucrReceiverRank.IsEmpty AndAlso (Not ucrSaveNew.bUserTyped) Then - clsAddColumnsFunction.AddParameter("col_data", "col", iPosition:=1) End If End If @@ -796,7 +793,6 @@ Public Class dlgTransform ucrBase.clsRsyntax.ClearCodes() If rdoSingle.Checked Then - If rdoRank.Checked Then clsPreviewTextFunction = clsRankFunction.Clone clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) @@ -894,7 +890,7 @@ Public Class dlgTransform ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAssignOperator) ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddColumnsFunction) Else - LoopsParameters() + UpdateLoopParameters() ucrBase.clsRsyntax.ClearCodes() ucrBase.clsRsyntax.SetAssignTo("col") ucrBase.clsRsyntax.AddToAfterCodes(clsPipeOperator, 0) @@ -910,7 +906,7 @@ Public Class dlgTransform AddRemoveLogicalValues() End Sub - Private Sub LoopsParameters() + Private Sub UpdateLoopParameters() If rdoRank.Checked Then clsDummyTransformFunction.AddParameter("check", "rank", iPosition:=0) clsPreviewTextFunction = clsRankColsFunction.Clone @@ -984,7 +980,6 @@ Public Class dlgTransform End If ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNonNegative.Checked Then clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) If rdoSquareRoot.Checked Then @@ -1002,7 +997,6 @@ Public Class dlgTransform ElseIf rdoLogToBase10.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) - clsLogBase10ColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLogBase10ColsFunction, bIncludeArgumentName:=False) ElseIf rdoNaturalLog.Checked Then @@ -1134,7 +1128,6 @@ Public Class dlgTransform If ucrSaveNew.GetText <> "" AndAlso ucrSaveNew.IsComplete() Then clsRemoveLabelsFunction.AddParameter("col_names", Chr(34) & ucrSaveNew.GetText & Chr(34), iPosition:=1) clsPasteFunction.AddParameter("col_data", Chr(34) & "_" & ucrSaveNew.GetText & Chr(34), iPosition:=1, bIncludeArgumentName:=False) - End If End Sub @@ -1149,9 +1142,7 @@ Public Class dlgTransform clsGetDataFrameFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.strCurrentDataFrame & Chr(34), iPosition:=0, bIncludeArgumentName:=False) clsGetDataFrameFunction.AddParameter("column_selection_name ", ucrReceiverRank.GetVariableNames, iPosition:=1) clsGetDataFrameFunction.SetAssignTo(ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text) - clsAddColumnsFunction.AddParameter("data_name", Chr(34) & ucrSelectorForRank.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) - If rdoMultiple.Checked Then clsDummyTransformFunction.AddParameter("col", "multiple", iPosition:=0) ucrSelectorForRank.SetItemType("column_selection") @@ -1169,7 +1160,6 @@ Public Class dlgTransform Private Sub ucrChkMultiply_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkMultiply.ControlValueChanged, ucrInputMultiply.ControlValueChanged If ucrChkMultiply.Checked AndAlso Not ucrInputMultiply.IsEmpty Then clsScaleMultiplyColsOperator.AddParameter("y", ucrInputMultiply.GetText, iPosition:=1) - Else clsScaleMultiplyColsOperator.RemoveParameterByName("y") End If @@ -1178,7 +1168,6 @@ Public Class dlgTransform Private Sub ucrChkAdd_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkAdd.ControlValueChanged, ucrInputAdd.ControlValueChanged If ucrChkAdd.Checked AndAlso Not ucrInputAdd.IsEmpty Then clsScaleAddColsOperator.AddParameter("v", ucrInputAdd.GetText, iPosition:=1) - Else clsScaleAddColsOperator.RemoveParameterByName("v") End If @@ -1187,7 +1176,6 @@ Public Class dlgTransform Private Sub ucrChkSubtract_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSubtract.ControlValueChanged, ucrInputSubtract.ControlValueChanged If ucrChkSubtract.Checked AndAlso Not ucrInputSubtract.IsEmpty Then clsScaleSubtractColsOperator.AddParameter("u", ucrInputSubtract.GetText, iPosition:=1) - Else clsScaleSubtractColsOperator.RemoveParameterByName("u") End If @@ -1196,7 +1184,6 @@ Public Class dlgTransform Private Sub ucrChkDivide_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkDivide.ControlValueChanged, ucrInputDivide.ControlValueChanged If ucrChkDivide.Checked AndAlso Not ucrInputDivide.IsEmpty Then clsScaleDivideColsOperator.AddParameter("z", ucrInputDivide.GetText, iPosition:=1) - Else clsScaleDivideColsOperator.RemoveParameterByName("z") End If From 6c32a61ba6cddb995b3ae905e94a269b67ecb2fa Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:32:10 +0200 Subject: [PATCH 24/30] Code Changes --- instat/dlgTransform.vb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index dd224231125..4d0ae1b168c 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -979,35 +979,28 @@ Public Class dlgTransform End Select End If ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction) - ElseIf rdoNonNegative.Checked Then clsDummyTransformFunction.AddParameter("check", "non-negative", iPosition:=0) If rdoSquareRoot.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "sqrt", iPosition:=0) - clsSquarerootColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSquarerootColsFunction, bIncludeArgumentName:=False) ElseIf rdoPower.Checked Then - clsNonNegativeDummyFunction.AddParameter("check", "power", iPosition:=0) clsPowerColsOperator.AddParameter("y", ucrInputPower.GetText, iPosition:=1) - clsPowerColsOperator.AddParameter("x", "~.", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsPowerColsOperator, bIncludeArgumentName:=False) ElseIf rdoLogToBase10.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log10", iPosition:=0) - clsLogBase10ColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLogBase10ColsFunction, bIncludeArgumentName:=False) ElseIf rdoNaturalLog.Checked Then clsNonNegativeDummyFunction.AddParameter("check", "log", iPosition:=0) - clsNaturalLogColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsNaturalLogColsFunction, bIncludeArgumentName:=False) End If ElseIf rdoScale.Checked Then clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) - clsScaleSubtractColsOperator.AddParameter("left", "~.x", iPosition:=0) clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) End If From 073370c76ff270b4e3b85fefd085afb03c88fe6a Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 4 Apr 2024 11:01:00 +0100 Subject: [PATCH 25/30] minor change made --- instat/dlgClimograph.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/instat/dlgClimograph.vb b/instat/dlgClimograph.vb index b7c7646e0c5..5852c08272f 100644 --- a/instat/dlgClimograph.vb +++ b/instat/dlgClimograph.vb @@ -284,7 +284,6 @@ Public Class dlgClimograph Private Sub ucr1stFactorReceiver_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucr1stFactorReceiver.ControlValueChanged If Not ucr1stFactorReceiver.IsEmpty Then - 'clsGgwalterliethFunction.AddParameter("station", Chr(34) & ucr1stFactorReceiver.GetVariableNames(False) & Chr(34), iPosition:=1) clsGgwalterliethFunction.AddParameter("station", ucr1stFactorReceiver.GetVariableNames(), iPosition:=1) Else clsGgwalterliethFunction.RemoveParameterByName("station") From 8782aba65d7ea808b2a9986e89d0d827ba2e1530 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:46:37 +0200 Subject: [PATCH 26/30] fixed the Standardise function for the select columns --- instat/dlgTransform.vb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 4d0ae1b168c..5b50a95bd9b 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -46,6 +46,7 @@ Public Class dlgTransform Private clsLogBase10Function As New RFunction Private clsLogBase10ColsFunction As New RFunction Private clsStandardDevColsFunction As New RFunction + Private clsSymbolOperator As New ROperator Private clsMeanColsFunction As New RFunction Private clsReplicateColsFunction As New RFunction Private clsConcDiffColsFunction As New RFunction @@ -408,6 +409,7 @@ Public Class dlgTransform clsConcDiffColsFunction = New RFunction clsReplicateColsFunction = New RFunction clsStandardDevColsFunction = New RFunction + clsSymbolOperator = New ROperator clsBooleanColsOperator = New ROperator clsAddColumnsFunction = New RFunction clsPasteFunction = New RFunction @@ -543,13 +545,17 @@ Public Class dlgTransform clsStandardDevColsFunction.AddParameter("na.rm", "TRUE", iPosition:=1) clsSubtractColsOperator.SetOperation("-") - clsSubtractColsOperator.AddParameter("left", "~.x", iPosition:=0) + clsSubtractColsOperator.AddParameter("left", ".x", iPosition:=0) clsSubtractColsOperator.AddParameter("y", clsRFunctionParameter:=clsMeanColsFunction, iPosition:=1) clsDivisionColsOperator.SetOperation("/") clsDivisionColsOperator.AddParameter("x", clsROperatorParameter:=clsSubtractColsOperator, iPosition:=0) clsDivisionColsOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevColsFunction, iPosition:=1) - clsDivisionColsOperator.bBrackets = False + 'clsDivisionColsOperator.bBrackets = False + + clsSymbolOperator.AddParameter("left", "~", iPosition:=0, bIncludeArgumentName:=False) + clsSymbolOperator.AddParameter("right", clsROperatorParameter:=clsDivisionColsOperator, iPosition:=1, bIncludeArgumentName:=False) + clsSymbolOperator.bBrackets = False clsSquarerootColsFunction.SetRCommand("~sqrt") @@ -948,7 +954,7 @@ Public Class dlgTransform clsMeanColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsStandardDevColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsDivisionColsOperator, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsSymbolOperator, bIncludeArgumentName:=False) ElseIf rdoLogical.Checked Then clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) clsBooleanColsOperator.AddParameter("x", "~.x", bIncludeArgumentName:=False, iPosition:=0) From e39e2f74a0aaf1c8addffd35cedea7ce752b9af6 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 4 Apr 2024 15:08:30 +0200 Subject: [PATCH 27/30] Fixed Scale Function for the select column --- instat/dlgTransform.vb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 5b50a95bd9b..3200d7b2624 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -47,6 +47,7 @@ Public Class dlgTransform Private clsLogBase10ColsFunction As New RFunction Private clsStandardDevColsFunction As New RFunction Private clsSymbolOperator As New ROperator + Private clsSymbolOperator2 As New ROperator Private clsMeanColsFunction As New RFunction Private clsReplicateColsFunction As New RFunction Private clsConcDiffColsFunction As New RFunction @@ -410,6 +411,7 @@ Public Class dlgTransform clsReplicateColsFunction = New RFunction clsStandardDevColsFunction = New RFunction clsSymbolOperator = New ROperator + clsSymbolOperator2 = New ROperator clsBooleanColsOperator = New ROperator clsAddColumnsFunction = New RFunction clsPasteFunction = New RFunction @@ -551,7 +553,6 @@ Public Class dlgTransform clsDivisionColsOperator.SetOperation("/") clsDivisionColsOperator.AddParameter("x", clsROperatorParameter:=clsSubtractColsOperator, iPosition:=0) clsDivisionColsOperator.AddParameter("y", clsRFunctionParameter:=clsStandardDevColsFunction, iPosition:=1) - 'clsDivisionColsOperator.bBrackets = False clsSymbolOperator.AddParameter("left", "~", iPosition:=0, bIncludeArgumentName:=False) clsSymbolOperator.AddParameter("right", clsROperatorParameter:=clsDivisionColsOperator, iPosition:=1, bIncludeArgumentName:=False) @@ -591,7 +592,10 @@ Public Class dlgTransform clsScaleAddColsOperator.SetOperation("+") clsScaleAddColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleDivideColsOperator, iPosition:=0) clsScaleAddColsOperator.AddParameter("v", "0", iPosition:=1) - clsScaleAddColsOperator.bBrackets = False + + clsSymbolOperator2.AddParameter("left", "~", iPosition:=0, bIncludeArgumentName:=False) + clsSymbolOperator2.AddParameter("right", clsROperatorParameter:=clsScaleAddColsOperator, iPosition:=1, bIncludeArgumentName:=False) + clsSymbolOperator2.bBrackets = False clsBooleanColsOperator.SetOperation("==") clsIsNAColsFunction.SetRCommand("is.na") @@ -1007,8 +1011,8 @@ Public Class dlgTransform End If ElseIf rdoScale.Checked Then clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) - clsScaleSubtractColsOperator.AddParameter("left", "~.x", iPosition:=0) - clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) + clsScaleSubtractColsOperator.AddParameter("left", ".x", iPosition:=0) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsSymbolOperator2, bIncludeArgumentName:=False) End If clsMutateFunction.AddParameter("var", clsRFunctionParameter:=clsAcrossFunction, bIncludeArgumentName:=False, iPosition:=0) From 49cbfc03bdaf6970f8d969287f8ae07b029020de Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 4 Apr 2024 15:58:53 +0200 Subject: [PATCH 28/30] Code Changes --- instat/dlgTransform.vb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index 3200d7b2624..ca8a6986e2f 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -935,17 +935,14 @@ Public Class dlgTransform clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsRoundColsFunction, bIncludeArgumentName:=False) ElseIf rdoSignificantDigits.Checked Then clsNumericDummyFunction.AddParameter("check", "signif", iPosition:=0) - clsSignifColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsSignifColsFunction, bIncludeArgumentName:=False) ElseIf rdoLag.Checked Then clsNumericDummyFunction.AddParameter("check", "lag", iPosition:=0) - clsLagColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLagColsFunction, bIncludeArgumentName:=False) ElseIf rdoLead.Checked Then clsNumericDummyFunction.AddParameter("check", "lead", iPosition:=0) - clsLeadColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsLeadColsFunction, bIncludeArgumentName:=False) ElseIf rdoDifference.Checked Then @@ -954,10 +951,8 @@ Public Class dlgTransform clsAcrossFunction.AddParameter("operator", clsRFunctionParameter:=clsConcDiffColsFunction, bIncludeArgumentName:=False) ElseIf rdoStandardize.Checked Then clsNumericDummyFunction.AddParameter("check", "standardise", iPosition:=0) - clsMeanColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) clsStandardDevColsFunction.AddParameter("x", ".x", bIncludeArgumentName:=False, iPosition:=0) - clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsSymbolOperator, bIncludeArgumentName:=False) ElseIf rdoLogical.Checked Then clsNumericDummyFunction.AddParameter("check", "logical", iPosition:=0) From 4deafdde0e1648095c7e8440fd4026a5bfa931d7 Mon Sep 17 00:00:00 2001 From: Derrick Agorhom <76208189+derekagorhom@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:51:45 +0200 Subject: [PATCH 29/30] Fixed the Scale function for the select columns --- instat/dlgTransform.vb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/instat/dlgTransform.vb b/instat/dlgTransform.vb index ca8a6986e2f..fc8147d6f9c 100644 --- a/instat/dlgTransform.vb +++ b/instat/dlgTransform.vb @@ -582,19 +582,19 @@ Public Class dlgTransform clsScaleMultiplyColsOperator.SetOperation("*") clsScaleMultiplyColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleSubtractColsOperator, iPosition:=0) clsScaleMultiplyColsOperator.AddParameter("y", "1", iPosition:=1) - clsScaleMultiplyColsOperator.bBrackets = False clsScaleDivideColsOperator.SetOperation("/") - clsScaleDivideColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleMultiplyColsOperator, iPosition:=0) + clsScaleDivideColsOperator.AddParameter("x", clsROperatorParameter:=clsSymbolOperator2, iPosition:=0) clsScaleDivideColsOperator.AddParameter("z", "1", iPosition:=1) clsScaleDivideColsOperator.bBrackets = False clsScaleAddColsOperator.SetOperation("+") clsScaleAddColsOperator.AddParameter("x", clsROperatorParameter:=clsScaleDivideColsOperator, iPosition:=0) clsScaleAddColsOperator.AddParameter("v", "0", iPosition:=1) + clsScaleAddColsOperator.bBrackets = False clsSymbolOperator2.AddParameter("left", "~", iPosition:=0, bIncludeArgumentName:=False) - clsSymbolOperator2.AddParameter("right", clsROperatorParameter:=clsScaleAddColsOperator, iPosition:=1, bIncludeArgumentName:=False) + clsSymbolOperator2.AddParameter("right", clsROperatorParameter:=clsScaleMultiplyColsOperator, iPosition:=1, bIncludeArgumentName:=False) clsSymbolOperator2.bBrackets = False clsBooleanColsOperator.SetOperation("==") @@ -1007,7 +1007,7 @@ Public Class dlgTransform ElseIf rdoScale.Checked Then clsDummyTransformFunction.AddParameter("check", "scale", iPosition:=0) clsScaleSubtractColsOperator.AddParameter("left", ".x", iPosition:=0) - clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsSymbolOperator2, bIncludeArgumentName:=False) + clsAcrossFunction.AddParameter("operator", clsROperatorParameter:=clsScaleAddColsOperator, bIncludeArgumentName:=False) End If clsMutateFunction.AddParameter("var", clsRFunctionParameter:=clsAcrossFunction, bIncludeArgumentName:=False, iPosition:=0) From 7029cbf45a0efad1d5f0259c5cacd9c068866e65 Mon Sep 17 00:00:00 2001 From: Stephen Lloyd Date: Fri, 5 Apr 2024 09:32:38 +0200 Subject: [PATCH 30/30] ensured that dlgEnter assignments are correctly deleted --- instat/clsRSyntax.vb | 7 +++++-- instat/ucrButtons.vb | 4 ---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/instat/clsRSyntax.vb b/instat/clsRSyntax.vb index 8b4476a0615..c73283a7497 100644 --- a/instat/clsRSyntax.vb +++ b/instat/clsRSyntax.vb @@ -94,8 +94,6 @@ Public Class RSyntax ''' The R command in the form of a string. Public strCommandString As String = "" - ''' The script associated with the base R code. - Public strScript As String ''' The R functions/operators/commands that should be run before the base R code. Private lstBeforeCodes As New List(Of RCodeStructure) @@ -231,6 +229,8 @@ Public Class RSyntax clsBaseFunction.GetAllAssignTo(lstCodes, lstValues) ElseIf bUseBaseOperator Then clsBaseOperator.GetAllAssignTo(lstCodes, lstValues) + ElseIf bUseCommandString Then + clsBaseCommandString.GetAllAssignTo(lstCodes, lstValues) End If lstBeforeCodes.Sort(AddressOf CompareCodePositions) For Each clsTempCode As RCodeStructure In lstBeforeCodes @@ -295,6 +295,7 @@ Public Class RSyntax '''-------------------------------------------------------------------------------------------- Public Function GetScript() As String Dim strTemp As String = "" + Dim strScript As String = "" If bUseBaseFunction Then strTemp = clsBaseFunction.ToScript(strScript) @@ -431,6 +432,7 @@ Public Class RSyntax clsBaseFunction = clsFunction bUseBaseFunction = True bUseBaseOperator = False + bUseCommandString = False End Sub '''-------------------------------------------------------------------------------------------- @@ -442,6 +444,7 @@ Public Class RSyntax clsBaseOperator = clsOperator bUseBaseFunction = False bUseBaseOperator = True + bUseCommandString = False End Sub '''-------------------------------------------------------------------------------------------- diff --git a/instat/ucrButtons.vb b/instat/ucrButtons.vb index 39ec45ab36a..9406a8b3535 100644 --- a/instat/ucrButtons.vb +++ b/instat/ucrButtons.vb @@ -173,10 +173,6 @@ Public Class ucrButtons frmMain.AddToScriptWindow(clsRsyntax.GetScript(), bMakeVisible:=bMakeVisibleScriptWindow, bAppendAtCurrentCursorPosition:=bAppendScriptsAtCurrentScriptWindowCursorPosition) End If - 'This clears the script after it has been run, but leave the function and parameters in the base function - 'so that it can be run exactly the same when reopened. - clsRsyntax.strScript = "" - 'Run additional after codes lstAfterCodes = clsRsyntax.GetAfterCodes() lstAfterScripts = clsRsyntax.GetScriptsFromCodeList(lstAfterCodes)