Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#1864 from FrancoisJRenaud/Graph…
Browse files Browse the repository at this point in the history
…icsExploration

Some questions and small commits
  • Loading branch information
dannyparsons authored Oct 9, 2016
2 parents 4a2d427 + 5db21ee commit 6724018
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 124 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ Public Class RSyntax
Public strScript As String
Public i As Integer
Public bExcludeAssignedFunctionOutput As Boolean = True
'Decides whether or not the output oof the R-command should be part of the script or not, in the case this has already been assigned.
Private strAssignTo As String
'strAssignTo is the name that should be used to assign in R the output of the main (Base) R-command.
Private strAssignToDataframe As String
Private strAssignToColumn As String
Private strAssignToModel As String
Private strAssignToGraph As String
'These AssingTo's are only relevant in the string case, as RFunction and ROperator have internal equivalents.
Private strAssignToGraph As String
'These AssingTo's are only relevant in the string case, as RFunction and ROperator have internal equivalents.
'If they are empty, the output Of the command Is Not linked To an R-instat object.
'If they are non-empty, that gives the name of the R-instat Object fields it needs to be linked with.
Public bToBeAssigned As Boolean = False
'bToBeAssigned is a boolean telling whether or not, AT THE CURRENT STAGE of running code within R, the output of the Base R-command NEEDS TO BE assigned to the variable with the appropriate name: strAssignTo.
'bToBeAssigned is a boolean telling whether or not, AT THE CURRENT STAGE of running code within R, the output of the Base R-command NEEDS TO BE assigned to
' - the variable With the appropriate name: strAssignTo,
' - And potentially assigned to elements in an R-instat object, if specified in the AssignToDataFrame,... parameters.
Public bIsAssigned As Boolean = False
'bIsAssigned tells blindly whether or not the variabe with the appropriate name has been assigned to the output of the Base R-command.
'bIsAssigned tells blindly whether or not the output of the R-command has been assigned and, if relevant, the link with the appropriate R-instat object has been done.
'Both booleans are necessary to distinguish the case where nothing needs to be assigned, and nothing is indeed assigned from the case, nothing needs to be assigned as it has already been assigned.
'So bIsAssigned Is Not enough To decide whether Or Not we should assign, unless we use the information "is strAssignTo empty or not", but for the moment we keep it like it is.
Private bAssignToIsPrefix As Boolean
Private bAssignToColumnWithoutNames As Boolean
Private bInsertColumnBefore As String
Expand Down Expand Up @@ -177,123 +184,119 @@ Public Class RSyntax
clsFunction.ClearParameters()
End Sub

Public Function GetScript(Optional ByRef clsFunction As RFunction = Nothing) As String
Public Function GetScript() As String

Dim strTemp As String = ""

If IsNothing(clsFunction) Then
If bUseBaseFunction Then
clsFunction = clsBaseFunction
strTemp = clsBaseFunction.ToScript(strScript)
End If
If bUseBaseOperator Then
strTemp = clsBaseOperator.ToScript(strScript)
End If
If bUseCommandString Then
Dim clsAddColumns As New RFunction
Dim clsGetColumns As New RFunction
Dim clsAddData As New RFunction
Dim clsGetData As New RFunction
Dim clsAddModels As New RFunction
Dim clsGetModels As New RFunction
Dim clsAddGraphs As New RFunction
Dim clsGetGraphs As New RFunction
Dim clsDataList As New RFunction

strTemp = strCommandString
If bToBeAssigned Then
If Not frmMain.clsRLink.bInstatObjectExists Then
frmMain.clsRLink.CreateNewInstatObject()
End If
strScript = strScript & strAssignTo & " <- " & strTemp & vbCrLf
If Not strAssignToDataframe = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then
clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data")
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
If Not bAssignToColumnWithoutNames Then
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
End If
clsAddColumns.AddParameter("col_data", strAssignTo)
If bAssignToIsPrefix Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "TRUE")
Else
If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "FALSE")
End If
End If
If bInsertColumnBefore Then
clsAddColumns.AddParameter("before", "TRUE")
Else
If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then
clsAddColumns.AddParameter("before", "FALSE")
End If
End If
strScript = strScript & clsAddColumns.ToScript() & vbCrLf

clsGetColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_columns_from_data")
clsGetColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
strAssignTo = clsGetColumns.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToModel = "" Then
clsAddModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_model")
clsAddModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34))
clsAddModels.AddParameter("model", strAssignTo)
If Not strAssignToDataframe = "" Then
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetModels.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
End If
strScript = strScript & clsAddModels.ToScript() & vbCrLf

clsGetModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_models")
clsGetModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34))
strAssignTo = clsGetModels.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToGraph = "" Then
clsAddGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_graph")
clsAddGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34))
clsAddGraphs.AddParameter("graph", strAssignTo)
If Not strAssignToDataframe = "" Then
clsAddGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
End If
strScript = strScript & clsAddGraphs.ToScript() & vbCrLf

clsGetGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_graphs")
clsGetGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34))
strAssignTo = clsGetGraphs.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToDataframe = "" Then
clsAddData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$import_data")
clsDataList.SetRCommand("list")
clsDataList.AddParameter(strAssignToDataframe, strAssignTo)
clsAddData.AddParameter("data_tables", clsRFunctionParameter:=clsDataList)
strScript = strScript & clsAddData.ToScript() & vbCrLf

clsGetData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame")
clsGetData.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
strAssignTo = clsGetData.ToScript()

bIsAssigned = True
bToBeAssigned = False
End If
strTemp = strAssignTo
Else
'Return strTemp
End If
End If
Else
strTemp = clsFunction.ToScript(strScript)
Dim strTemp As String = ""

If bUseBaseFunction Then
strTemp = clsBaseFunction.ToScript(strScript)
End If
If bUseBaseOperator Then
strTemp = clsBaseOperator.ToScript(strScript)
End If
If bUseCommandString Then
Dim clsAddColumns As New RFunction
Dim clsGetColumns As New RFunction
Dim clsAddData As New RFunction
Dim clsGetData As New RFunction
Dim clsAddModels As New RFunction
Dim clsGetModels As New RFunction
Dim clsAddGraphs As New RFunction
Dim clsGetGraphs As New RFunction
Dim clsDataList As New RFunction

strTemp = strCommandString

If bIsAssigned Then
strTemp = strAssignTo
ElseIf bToBeAssigned Then
If Not frmMain.clsRLink.bInstatObjectExists Then
frmMain.clsRLink.CreateNewInstatObject()
End If
strScript = strScript & strAssignTo & " <- " & strTemp & vbCrLf
If Not strAssignToDataframe = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then
clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data")
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
If Not bAssignToColumnWithoutNames Then
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
End If
clsAddColumns.AddParameter("col_data", strAssignTo)
If bAssignToIsPrefix Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "TRUE")
Else
If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "FALSE")
End If
End If
If bInsertColumnBefore Then
clsAddColumns.AddParameter("before", "TRUE")
Else
If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then
clsAddColumns.AddParameter("before", "FALSE")
End If
End If
strScript = strScript & clsAddColumns.ToScript() & vbCrLf

clsGetColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_columns_from_data")
clsGetColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
strAssignTo = clsGetColumns.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToModel = "" Then
clsAddModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_model")
clsAddModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34))
clsAddModels.AddParameter("model", strAssignTo)
If Not strAssignToDataframe = "" Then
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetModels.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
End If
strScript = strScript & clsAddModels.ToScript() & vbCrLf

clsGetModels.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_models")
clsGetModels.AddParameter("model_name", Chr(34) & strAssignToModel & Chr(34))
strAssignTo = clsGetModels.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToGraph = "" Then
clsAddGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_graph")
clsAddGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34))
clsAddGraphs.AddParameter("graph", strAssignTo)
If Not strAssignToDataframe = "" Then
clsAddGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
clsGetGraphs.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
End If
strScript = strScript & clsAddGraphs.ToScript() & vbCrLf

clsGetGraphs.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_graphs")
clsGetGraphs.AddParameter("graph_name", Chr(34) & strAssignToGraph & Chr(34))
strAssignTo = clsGetGraphs.ToScript()

bIsAssigned = True
bToBeAssigned = False
ElseIf Not strAssignToDataframe = "" Then
clsAddData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$import_data")
clsDataList.SetRCommand("list")
clsDataList.AddParameter(strAssignToDataframe, strAssignTo)
clsAddData.AddParameter("data_tables", clsRFunctionParameter:=clsDataList)
strScript = strScript & clsAddData.ToScript() & vbCrLf

clsGetData.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame")
clsGetData.AddParameter("data_name", Chr(34) & strAssignToDataframe & Chr(34))
strAssignTo = clsGetData.ToScript()

bIsAssigned = True
bToBeAssigned = False
End If
strTemp = strAssignTo
End If
End If
If bExcludeAssignedFunctionOutput Then
If (bUseBaseFunction AndAlso clsFunction.bIsAssigned) OrElse (bUseBaseOperator AndAlso clsBaseOperator.bIsAssigned) OrElse (bUseCommandString AndAlso bIsAssigned) Then
'Sometimes the output of the R-command we deal with should not be part of the script... That's only the case when this output has already been assigned.
If (bUseBaseFunction AndAlso clsBaseFunction.bIsAssigned) OrElse (bUseBaseOperator AndAlso clsBaseOperator.bIsAssigned) OrElse (bUseCommandString AndAlso bIsAssigned) Then
Return strScript
Exit Function
End If
End If
Return strScript & strTemp
Expand Down
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
Loading

0 comments on commit 6724018

Please sign in to comment.