Skip to content

Commit

Permalink
Merge pull request #6 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Update from the main
  • Loading branch information
FrancoisJRenaud authored Oct 9, 2016
2 parents ea0cb54 + 6724018 commit d464cca
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 417 deletions.
2 changes: 2 additions & 0 deletions instat/clsRFunction.vb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Public Class RFunction
End Sub

Public Function ToScript(Optional ByRef strScript As String = "") As String
'Converting the RFunction into a string that when run in R gives the appropriate output
Dim strTemp As String = ""
Dim i As Integer
Dim clsAddColumns As New RFunction
Expand All @@ -85,6 +86,7 @@ Public Class RFunction
If bIsAssigned Then
Return (strAssignTo)
End If
'In case R has already stored the output of the function in the string of the appropriate name -AssignTo-, then that variable can be used as script.

strTemp = strRCommand & "("

Expand Down
4 changes: 3 additions & 1 deletion instat/clsROperator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ Public Class ROperator
End Function

Public Sub SetParameter(bSetFirst As Boolean, Optional strParameterName As String = "Right", Optional strValue As String = "", Optional clsParam As RParameter = Nothing, Optional clsRFunc As RFunction = Nothing, Optional clsOp As ROperator = Nothing, Optional bIncludeArgumentName As Boolean = True)

'Only one of the nonboolean parameters should ever be nonempty, but strParameterName.
'bSetFirst decides wether we are modifying/adding the first parameter.
'The default new parameter name is "Right", in case we are not modyfying the first parameter. Cannot be recursively adding parameters using default name as it will overwrite.
If strValue <> "" Then
clsParam = New RParameter
clsParam.SetArgumentValue(strValue)
Expand Down
237 changes: 120 additions & 117 deletions instat/clsRSyntax.vb

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions instat/dlgGeneralForGraphics.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Public Class dlgGeneralForGraphics
Public clsRggplotFunction As New RFunction
Private bFirstLoad As Boolean = True
Private lstLayerComplete As New List(Of Boolean)
'list of completed layers.
Private iLayerIndex As Integer
'current layer
Public WithEvents clsGgplotAesFunction As New RFunction
Private strGlobalDataFrame As String = ""
Public bDataFrameSet As Boolean = False
Private strGlobalDataFrame As String
Public bDataFrameSet As Boolean

Private Sub dlgGeneralForGraphics_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
Expand All @@ -41,6 +43,7 @@ Public Class dlgGeneralForGraphics
clsRggplotFunction.SetRCommand("ggplot")
clsGgplotAesFunction.SetRCommand("aes")
ucrBase.clsRsyntax.SetOperatorParameter(True, clsRFunc:=clsRggplotFunction)
'True for "we are setting the first parameter, on the left of +.
ucrBase.iHelpTopicID = 356

ucrSaveGraph.SetDataFrameSelector(sdgLayerOptions.ucrGeomWithAes.UcrSelector.ucrAvailableDataFrames)
Expand All @@ -49,7 +52,8 @@ Public Class dlgGeneralForGraphics
ucrAdditionalLayers.SetGGplotFunction(clsRggplotFunction)
ucrAdditionalLayers.SetAesFunction(clsGgplotAesFunction)
ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False

'By default, we want to put in the script the output of our Base R-command (in this case the ...+...+...) even when it has been assigned to some object (in which case we want the name of that object in the script so that it's called when the script is run).
'For example, when a graph is saved, it is assigned to it's place in an R-instat object. If we had set bExcludeAssignedFunctionOutput to True, then we would never print the graph when running the script.

End Sub

Expand All @@ -59,6 +63,7 @@ Public Class dlgGeneralForGraphics
lstLayerComplete.Clear()
'SetEditDeleteEnabled()
strGlobalDataFrame = ""
bDataFrameSet = False
clsRggplotFunction.ClearParameters()
clsGgplotAesFunction.ClearParameters()
ucrAdditionalLayers.Reset()
Expand Down
252 changes: 72 additions & 180 deletions instat/dlgMerge.Designer.vb

Large diffs are not rendered by default.

147 changes: 41 additions & 106 deletions instat/dlgMerge.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Imports instat.Translations

Public Class dlgMerge
Private bFirstLoad As Boolean = True
Private clsByList As New RFunction

Private Sub dlgMerge_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
Expand All @@ -35,80 +34,72 @@ Public Class dlgMerge
Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 60
ucrNewDataFrameName.SetValidationTypeAsRVariable()
cmdAddAnotherPair.Enabled = False
ucrReceiverFirstDF.Selector = ucrSelectorFirstDataFrame
ucrReceiverSecondDF.Selector = ucrSelectorSecondDataFrame
clsByList.SetRCommand("c")
ucrBase.clsRsyntax.AddParameter("by", clsRFunctionParameter:=clsByList)
ucrReceiverFirstDF.bExcludeFromSelector = True
ucrReceiverSecondDF.bExcludeFromSelector = True
ucrInputMergeColumnsOptions.SetItems({"Merge by all columns with the same name", "Choose which columns to merge by"})
sdgMerge.SetRSyntax(ucrBase.clsRsyntax)
' This has a bug when using numeric and integer columns as the joining columns.
' Issue reported here: https://github.com/hadley/dplyr/issues/2164
' Alternatives would be to use the much slower base merge
' or plyrJoin which cannot handle joining columns with different names
' ucrBase.clsRsyntax.SetFunction("join")
End Sub

Private Sub SetDefaults()
ucrNewDataFrameName.Reset()
ucrSelectorFirstDataFrame.Reset()
ucrSelectorSecondDataFrame.Reset()
ucrReceiverFirstDF.SetMeAsReceiver()
ucrReceiverSecondDF.SetMeAsReceiver()
ucrFirstDataFrame.Reset()
ucrSecondDataFrame.Reset()
rdoLeftJoin.Checked = True
rdoChooseMergeColumns.Checked = True
ucrInputMergeColumnsOptions.SetName("Merge by all columns with the same name")
End Sub

Private Sub ReopenDialog()

End Sub

Private Sub TestOKEnabled()
If ucrNewDataFrameName.IsEmpty() Then
ucrBase.OKEnabled(False)
Else
If rdoChooseMergeColumns.Checked Then
If (Not ucrReceiverFirstDF.IsEmpty() AndAlso Not ucrReceiverSecondDF.IsEmpty) OrElse lstKeyColumns.Items.Count > 0 Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
ElseIf rdoMergeByAllColumns.Checked Then
If ucrInputMergeColumnsOptions.GetText() = "Merge by all columns with the same name" Then
If Not ucrNewDataFrameName.IsEmpty() Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
ElseIf ucrInputMergeColumnsOptions.GetText() = "Choose which columns to merge by" Then
If sdgMerge.IsOkEnabled() Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
Else
ucrBase.OKEnabled(False)
End If
End Sub

Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
sdgMerge.SetDefaults()
TestOKEnabled()
End Sub

Private Sub ucrSelectorDataFrames_DataFrameChanged() Handles ucrSelectorFirstDataFrame.DataFrameChanged, ucrSelectorSecondDataFrame.DataFrameChanged
Private Sub ucrSelectorDataFrames_DataFrameChanged() Handles ucrFirstDataFrame.DataFrameChanged, ucrSecondDataFrame.DataFrameChanged
If Not ucrNewDataFrameName.UserTyped() Then
ucrNewDataFrameName.SetName(ucrSelectorFirstDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_merged_with_" & ucrSelectorSecondDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
ucrNewDataFrameName.SetName(ucrFirstDataFrame.cboAvailableDataFrames.Text & "_merged_with_" & ucrSecondDataFrame.cboAvailableDataFrames.Text)
End If
ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrSelectorFirstDataFrame.ucrAvailableDataFrames.clsCurrDataFrame)
ucrBase.clsRsyntax.AddParameter("y", clsRFunctionParameter:=ucrSelectorSecondDataFrame.ucrAvailableDataFrames.clsCurrDataFrame)
ucrBase.clsRsyntax.AddParameter("suffix", "c(" & Chr(34) & ucrSelectorFirstDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34) & ", " & Chr(34) & ucrSelectorSecondDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34) & ")")
ResetKeyList()
End Sub

Private Sub ResetKeyList()
lstKeyColumns.Columns.Clear()
lstKeyColumns.Clear()
lstKeyColumns.Columns.Add(ucrSelectorFirstDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
lstKeyColumns.Columns.Add("-")
lstKeyColumns.Columns.Add(ucrSelectorSecondDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
lstKeyColumns.Columns(0).Width = 95
lstKeyColumns.Columns(1).Width = 80
lstKeyColumns.Columns(2).Width = 95
pnlKeyColumns.Hide()
ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrFirstDataFrame.clsCurrDataFrame)
ucrBase.clsRsyntax.AddParameter("y", clsRFunctionParameter:=ucrSecondDataFrame.clsCurrDataFrame)
ucrBase.clsRsyntax.AddParameter("suffix", "c(" & Chr(34) & ucrFirstDataFrame.cboAvailableDataFrames.Text & Chr(34) & ", " & Chr(34) & ucrSecondDataFrame.cboAvailableDataFrames.Text & Chr(34) & ")")
End Sub

Private Sub JoinType_CheckedChanged(sender As Object, e As EventArgs) Handles rdoFullJoin.CheckedChanged, rdoInnerJoin.CheckedChanged, rdoLeftJoin.CheckedChanged, rdoRightJoin.CheckedChanged
If rdoLeftJoin.Checked Then
'ucrBase.clsRsyntax.AddParameter("type", Chr(34) & "left" & Chr(34))
ucrBase.clsRsyntax.SetFunction("left_join")
ElseIf rdoFullJoin.Checked Then
'ucrBase.clsRsyntax.AddParameter("type", Chr(34) & "full" & Chr(34))
ucrBase.clsRsyntax.SetFunction("full_join")
ElseIf rdoInnerJoin.Checked Then
'ucrBase.clsRsyntax.AddParameter("type", Chr(34) & "inner" & Chr(34))
ucrBase.clsRsyntax.SetFunction("inner_join")
ElseIf rdoRightJoin.Checked Then
'ucrBase.clsRsyntax.AddParameter("type", Chr(34) & "right" & Chr(34))
ucrBase.clsRsyntax.SetFunction("right_join")
End If
End Sub
Expand All @@ -122,75 +113,19 @@ Public Class dlgMerge
TestOKEnabled()
End Sub

Private Sub KeyOptions_CheckedChanged(sender As Object, e As EventArgs) Handles rdoMergeByAllColumns.CheckedChanged, rdoChooseMergeColumns.CheckedChanged
If rdoChooseMergeColumns.Checked Then
grpKeys.Visible = True
SetByArgument()
ucrSelectorFirstDataFrame.SetVariablesEnabled(True)
ucrSelectorSecondDataFrame.SetVariablesEnabled(True)
Else
grpKeys.Visible = False
Private Sub ucrInputMergeColumnsOptions_NameChanged() Handles ucrInputMergeColumnsOptions.NameChanged
If ucrInputMergeColumnsOptions.GetText() = "Merge by all columns with the same name" Then
cmdChooseMergeColumns.Enabled = False
ElseIf ucrInputMergeColumnsOptions.GetText() = "Choose which columns to merge by" Then
cmdChooseMergeColumns.Enabled = True
'temp disabled until working
cmdChooseMergeColumns.Enabled = False
ucrBase.clsRsyntax.RemoveParameter("by")
ucrSelectorFirstDataFrame.SetVariablesEnabled(False)
ucrSelectorSecondDataFrame.SetVariablesEnabled(False)
End If
TestOKEnabled()
End Sub

Private Sub ucrReceiverFirstDFKey1_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverFirstDF.SelectionChanged
If Not ucrReceiverFirstDF.IsEmpty() Then
If ucrReceiverSecondDF.IsEmpty AndAlso ucrSelectorSecondDataFrame.ContainsVariable(ucrReceiverFirstDF.GetVariableNames(False)) Then
ucrReceiverSecondDF.Add(ucrReceiverFirstDF.GetVariableNames(False))
End If
End If
If ucrReceiverFirstDF.IsEmpty() OrElse ucrReceiverSecondDF.IsEmpty Then
cmdAddAnotherPair.Enabled = False
Else
cmdAddAnotherPair.Enabled = True
End If
SetByArgument()
TestOKEnabled()
End Sub

Private Sub SetByArgument()
Dim lviItem As ListViewItem
clsByList.ClearParameters()
If Not ucrReceiverFirstDF.IsEmpty() AndAlso Not ucrReceiverSecondDF.IsEmpty() Then
clsByList.AddParameter(ucrReceiverFirstDF.GetVariableNames(), ucrReceiverFirstDF.GetVariableNames())
End If
For Each lviItem In lstKeyColumns.Items
clsByList.AddParameter(lviItem.Text(), lviItem.SubItems(2).Text())
Next
End Sub

Private Sub cmdAddAnotherPair_Click(sender As Object, e As EventArgs) Handles cmdAddAnotherPair.Click
lstKeyColumns.Items.Add(ucrReceiverFirstDF.GetVariableNames()).SubItems.AddRange({"Matched With", ucrReceiverSecondDF.GetVariableNames()})
pnlKeyColumns.Show()
ucrReceiverFirstDF.Clear()
ucrReceiverSecondDF.Clear()
SetByArgument()
End Sub

Private Sub cmdRemoveSelectedPair_Click(sender As Object, e As EventArgs) Handles cmdRemoveSelectedPair.Click
Dim i As Integer

If lstKeyColumns.SelectedItems.Count > 0 Then
For i = lstKeyColumns.SelectedItems.Count - 1 To 0 Step -1
lstKeyColumns.Items.RemoveAt(lstKeyColumns.SelectedIndices(i))
Next
End If
End Sub

Private Sub lstKeyColumns_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstKeyColumns.SelectedIndexChanged
If lstKeyColumns.SelectedItems.Count = 0 Then
cmdRemoveSelectedPair.Enabled = False
Else
cmdRemoveSelectedPair.Enabled = True
End If
TestOKEnabled()
End Sub

Private Sub ucrReceiverSecondDF_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverSecondDF.SelectionChanged

Private Sub cmdChooseMergeColumns_Click(sender As Object, e As EventArgs) Handles cmdChooseMergeColumns.Click
sdgMerge.ShowDialog()
End Sub
End Class
3 changes: 2 additions & 1 deletion instat/dlgName.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions instat/dlgName.vb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Public Class dlgName
ucrReceiverName.Selector = ucrSelectVariables
ucrReceiverName.SetMeAsReceiver()
ucrBase.clsRsyntax.SetFunction(frmMain.clsRLink.strInstatDataObject & "$rename_column_in_data")
ucrInputNewName.SetValidationTypeAsRVariable()
End Sub

Public Sub SetDefaults()
Expand Down
1 change: 0 additions & 1 deletion instat/frmVariables.vb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Public Class frmVariables
grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_Readonly, True)
grdCurrSheet.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_DragSelectionToMoveCells, False)
grdCurrSheet.SelectionForwardDirection = unvell.ReoGrid.SelectionForwardDirection.Down
frmMain.strCurrentDataFrame = grdCurrSheet.Name
End Sub

Private Sub grdCurrSheet_AfterCellEdit(sender As Object, e As CellAfterEditEventArgs) Handles grdCurrSheet.AfterCellEdit
Expand Down
5 changes: 4 additions & 1 deletion instat/sdgLayerOptions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Public Class sdgLayerOptions
Public clsGgplotFunction As New RFunction
Public bFirstLoad As Boolean = True
Public bAesInGeom As Boolean
Public strGlobalDataFrame As String = ""
Public strGlobalDataFrame As String

Public Sub New()
' This call is required by the designer.
Expand All @@ -43,10 +43,12 @@ Public Class sdgLayerOptions
Private Sub InitialiseDialog()
ucrLayerParameter.ucrGeomWithAes = ucrGeomWithAes
ucrGeomWithAes.ucrLayersControl = ucrLayerParameter
'All these controls are on the current subdialogue and should be linked together as shown above.
End Sub

Private Sub SetDefaults()
ucrGeomWithAes.UcrSelector.Reset()
strGlobalDataFrame = ""
End Sub

Private Sub ReopenDialog()
Expand All @@ -66,6 +68,7 @@ Public Class sdgLayerOptions
clsGgplotFunction = clsTempGgPlot
ucrGeomWithAes.Setup(clsTempGgPlot, clsTempGeomFunc, clsTempAesFunc, bFixAes, bFixGeom, strDataframe, bUseGlobalAes, iNumVariablesForGeoms, clsTempLocalAes)
ucrLayerParameter.Setup(clsTempGgPlot, clsTempGeomFunc, clsTempAesFunc, bFixAes, bFixGeom, strDataframe, bUseGlobalAes, iNumVariablesForGeoms, clsTempLocalAes)
'Warning, when coming back to a layer where the geom was not fixed, the geom is now fixed...
End Sub

Public Function TestForOKEnabled() As Boolean
Expand Down
Loading

0 comments on commit d464cca

Please sign in to comment.