Skip to content

Commit

Permalink
Merge pull request #73 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Updating Master
  • Loading branch information
Ivanluv authored Feb 6, 2020
2 parents 737ebc1 + c0aab8f commit 46be36a
Show file tree
Hide file tree
Showing 50 changed files with 9,449 additions and 11,710 deletions.
35 changes: 25 additions & 10 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -597,27 +597,27 @@ Public Class RLink
End If
End Sub

Public Function RunInternalScriptGetValue(strScript As String, Optional strVariableName As String = ".temp_value", Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As SymbolicExpression
Public Function RunInternalScriptGetValue(strScript As String, Optional strVariableName As String = ".temp_value", Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As SymbolicExpression
Dim expTemp As SymbolicExpression
Dim strCommand As String

expTemp = Nothing
'TODO Bug here if strScript is multiple lines. Wrong value will be returned
strCommand = strVariableName & "<-" & strScript
strCommand = strVariableName & " <- " & strScript
If clsEngine IsNot Nothing Then
Evaluate(strCommand, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
Evaluate(strCommand, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride, strError:=strError)
expTemp = GetSymbol(strVariableName, bSilent:=True)
'Very important to remove the variable after getting it othewise could be returning wrong variable later if a command gives an error
Evaluate("rm(" & strVariableName & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread)
End If
Return expTemp
End Function

Public Function RunInternalScriptGetOutput(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As CharacterVector
Public Function RunInternalScriptGetOutput(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As CharacterVector
Dim chrTemp As CharacterVector
Dim expTemp As SymbolicExpression

expTemp = RunInternalScriptGetValue("capture.output(" & strScript & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
expTemp = RunInternalScriptGetValue("capture.output(" & strScript & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride, strError:=strError)
Try
chrTemp = expTemp.AsCharacter()
Catch ex As Exception
Expand Down Expand Up @@ -646,14 +646,15 @@ Public Class RLink
End If
End Function

Private Function Evaluate(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As Boolean
Private Function Evaluate(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As Boolean
Dim thrRScript As Threading.Thread
Dim thrDelay As Threading.Thread
Dim thrWaitDisplay As Threading.Thread
Dim evtWaitHandleWaitDisplayDone As New System.Threading.AutoResetEvent(False)
Dim evtWaitHandleDelayDone As New System.Threading.AutoResetEvent(False)
Dim bReturn As Boolean = True
Dim i As Integer = 1
Dim strTempError As String = ""
Dim strTempFile As String
Dim bErrorMessageOpen As Boolean = False
Dim bCurrentShowWaiting As Boolean
Expand Down Expand Up @@ -721,6 +722,7 @@ Public Class RLink
MsgBox(ex.Message & Environment.NewLine & "The error occurred in attempting to run the following R command(s):" & Environment.NewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
bErrorMessageOpen = False
End If
strTempError = ex.Message
bReturn = False
End Try
End Sub)
Expand Down Expand Up @@ -763,12 +765,14 @@ Public Class RLink
If Not bSilent Then
MsgBox(ex.Message & Environment.NewLine & "The error occurred in attempting to run the following R command(s):" & Environment.NewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End If
strTempError = ex.Message
bReturn = False
End Try
Else
bReturn = False
End If
bRCodeRunning = False
strError = strTempError
Return bReturn
End Function

Expand Down Expand Up @@ -1460,11 +1464,22 @@ Public Class RLink
RunScript(clsCreateIO.ToScript(), strComment:="Creating New Instat Object")
End Sub

Public Sub ViewLastGraph()
Public Sub ViewLastGraph(Optional bAsPlotly As Boolean = False)
Dim clsLastGraph As New RFunction

clsLastGraph.SetRCommand(strInstatDataObject & "$get_last_graph")
RunScript(clsLastGraph.ToScript(), strComment:="View last graph", bSeparateThread:=False)
Dim clsInteractivePlot As New RFunction

If bAsPlotly Then
clsInteractivePlot.SetPackageName("plotly")
clsInteractivePlot.SetRCommand("ggplotly")
clsLastGraph.SetRCommand(strInstatDataObject & "$get_last_graph")
clsLastGraph.AddParameter("print_graph", "FALSE", iPosition:=0)
clsInteractivePlot.AddParameter("p", clsRFunctionParameter:=clsLastGraph, iPosition:=0)
'Need to set iCallType = 2 to obtain a graph in an interactive viewer.
RunScript(clsInteractivePlot.ToScript(), iCallType:=2, strComment:="View last graph as Plotly", bSeparateThread:=False)
Else
clsLastGraph.SetRCommand(strInstatDataObject & "$get_last_graph")
RunScript(clsLastGraph.ToScript(), strComment:="View last graph", bSeparateThread:=False)
End If
End Sub

'construct and format the comment
Expand Down
4 changes: 2 additions & 2 deletions instat/dlgCalculator.resx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="ucrBase.Location" type="System.Drawing.Point, System.Drawing">
<value>17, 490</value>
<value>17, 537</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ucrBase.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
Expand Down Expand Up @@ -175,7 +175,7 @@
<value>8, 16</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>689, 559</value>
<value>689, 611</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>3, 4, 3, 4</value>
Expand Down
84 changes: 9 additions & 75 deletions instat/dlgCalculator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ Public Class dlgCalculator
ucrCalc.ucrSaveResultInto.SetPrefix("Calc")
ucrCalc.ucrInputCalOptions.SetName("Basic")
ucrCalc.Reset()
ucrCalc.chkShowArguments.Checked = False
ucrCalc.chkShowParameters.Checked = False
ucrCalc.chkSaveResultInto.Checked = True
SaveResults()
ucrCalc.ucrSelectorForCalculations.bUseCurrentFilter = False
'ucrCalc.ucrTryModelling.SetRSyntax(ucrBase.clsRsyntax)
ucrBase.Visible = True
End Sub

Expand All @@ -69,17 +70,22 @@ Public Class dlgCalculator
Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 14
ucrCalc.ucrReceiverForCalculation.SetMeAsReceiver()
'ucrCalc.ucrTryModelling.SetIsCommand()
'ucrCalc.ucrTryModelling.SetReceiver(ucrCalc.ucrReceiverForCalculation)
clsAttach.SetRCommand("attach")
clsDetach.SetRCommand("detach")
clsAttach.AddParameter("what", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
clsDetach.AddParameter("name", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
clsDetach.AddParameter("unload", "TRUE")
ucrBase.clsRsyntax.AddToBeforeCodes(clsAttach)
ucrBase.clsRsyntax.AddToAfterCodes(clsDetach)
ucrBase.clsRsyntax.SetCommandString("")
ucrCalc.ucrSaveResultInto.SetItemsTypeAsColumns()
ucrCalc.ucrSaveResultInto.SetDefaultTypeAsColumn()
ucrCalc.ucrSaveResultInto.SetDataFrameSelector(ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames)
ucrCalc.ucrSelectorForCalculations.Reset()
ucrCalc.ucrSaveResultInto.SetValidationTypeAsRVariable()
' ucrCalc.ucrTryModelling.StrvecOutputRequired()
End Sub

Private Sub ucrCalc_SaveNameChanged() Handles ucrCalc.SaveNameChanged
Expand All @@ -98,27 +104,13 @@ Public Class dlgCalculator
ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False
End If
End Sub

Private Sub ucrBase_BeforeClickOk(sender As Object, e As EventArgs) Handles ucrBase.BeforeClickOk
Dim strScript As String = ""
Dim strFunc As String
clsAttach.AddParameter("what", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
strFunc = clsAttach.ToScript(strScript)
frmMain.clsRLink.RunScript(strScript & strFunc)
End Sub

Private Sub ucrBase_ClickOk(sender As Object, e As EventArgs) Handles ucrBase.ClickOk
Dim strScript As String = ""
Dim strFunc As String
strFunc = clsDetach.ToScript(strScript)
frmMain.clsRLink.RunScript(strScript & strFunc)
ucrCalc.SetCalculationHistory()
End Sub

Private Sub ucrCalc_SelectionChanged() Handles ucrCalc.SelectionChanged
ucrBase.clsRsyntax.SetCommandString(ucrCalc.ucrReceiverForCalculation.GetVariableNames(False))
ucrCalc.ucrInputTryMessage.SetName("")
ucrCalc.cmdTry.Enabled = Not ucrCalc.ucrReceiverForCalculation.IsEmpty()
' ucrCalc.ucrTryModelling.ucrInputTryMessage.SetName("")
TestOKEnabled()
End Sub

Expand Down Expand Up @@ -168,7 +160,7 @@ Public Class dlgCalculator
End Sub

Private Sub ucrSelectorForCalculations_DataframeChanged() Handles ucrCalc.DataFrameChanged
ucrCalc.ucrInputTryMessage.SetName("")
'ucrCalc.ucrTryModelling.ucrInputTryMessage.SetName("")
SaveResults()
End Sub

Expand All @@ -179,62 +171,4 @@ Public Class dlgCalculator
ucrCalc.ucrSaveResultInto.Visible = False
End If
End Sub

Private Sub TryScript()
Dim strOutPut As String
Dim strAttach As String
Dim strDetach As String
Dim strTempScript As String = ""
Dim strVecOutput As CharacterVector
Dim bIsAssigned As Boolean
Dim bToBeAssigned As Boolean
Dim strAssignTo As String
Dim strAssignToColumn As String
Dim strAssignToDataFrame As String

bIsAssigned = ucrBase.clsRsyntax.GetbIsAssigned()
bToBeAssigned = ucrBase.clsRsyntax.GetbToBeAssigned()
strAssignTo = ucrBase.clsRsyntax.GetstrAssignTo()
'These should really be done through RSyntax methods as above
strAssignToColumn = ucrBase.clsRsyntax.GetstrAssignToColumn()
strAssignToDataFrame = ucrBase.clsRsyntax.GetstrAssignToDataFrame()

Try
If ucrCalc.ucrReceiverForCalculation.IsEmpty Then
ucrCalc.ucrInputTryMessage.SetName("")
Else
'get strScript here
strAttach = clsAttach.ToScript(strTempScript)
frmMain.clsRLink.RunInternalScript(strTempScript & strAttach, bSilent:=True)
ucrBase.clsRsyntax.RemoveAssignTo()
strOutPut = ucrBase.clsRsyntax.GetScript
strVecOutput = frmMain.clsRLink.RunInternalScriptGetOutput(strOutPut, bSilent:=True)
If strVecOutput IsNot Nothing Then
If strVecOutput.Length > 1 Then
ucrCalc.ucrInputTryMessage.SetName(Mid(strVecOutput(0), 5) & "...")
Else
ucrCalc.ucrInputTryMessage.SetName(Mid(strVecOutput(0), 5))
End If
Else
ucrCalc.ucrInputTryMessage.SetName("Command produced an error or no output to display.")
End If
End If
Catch ex As Exception
ucrCalc.ucrInputTryMessage.SetName("Command produced an error. Modify input before running.")
Finally
strTempScript = ""
strDetach = clsDetach.ToScript(strTempScript)
frmMain.clsRLink.RunInternalScript(strTempScript & strDetach, bSilent:=True)
ucrBase.clsRsyntax.SetbIsAssigned(bIsAssigned)
ucrBase.clsRsyntax.SetbToBeAssigned(bToBeAssigned)
ucrBase.clsRsyntax.SetstrAssignTo(strAssignTo)
'These should really be done through RSyntax methods as above
ucrBase.clsRsyntax.SetstrAssignToColumn(strAssignToColumn)
ucrBase.clsRsyntax.SetstrAssignToDataFrame(strAssignToDataFrame)
End Try
End Sub

Private Sub cmdTry_Click() Handles ucrCalc.TryCommadClick
TryScript()
End Sub
End Class
67 changes: 0 additions & 67 deletions instat/dlgCorruptionFile.Designer.vb

This file was deleted.

15 changes: 0 additions & 15 deletions instat/dlgCorruptionFile.sw-KE.resx

This file was deleted.

42 changes: 0 additions & 42 deletions instat/dlgCorruptionFile.vb

This file was deleted.

Loading

0 comments on commit 46be36a

Please sign in to comment.