Skip to content

Commit

Permalink
Merge pull request #160 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
update main branch
  • Loading branch information
stevekogo authored Oct 7, 2016
2 parents 29f0162 + e9e0d44 commit ccd45ac
Show file tree
Hide file tree
Showing 25 changed files with 815 additions and 497 deletions.
14 changes: 7 additions & 7 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ Public Class RLink
Try
clsEngine.Evaluate(strScript)
Catch e As Exception
MsgBox("Error occurred in attempting to run:" & vbNewLine & strScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & e.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(e.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End Try
ElseIf bReturnOutput = 1 Then
Try
temp = clsEngine.Evaluate(strScript)
strTemp = String.Join(vbCrLf, temp.AsCharacter())
strOutput = strOutput & strTemp & vbCrLf
Catch e As Exception
MsgBox("Error occurred in attempting to run:" & vbNewLine & strScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & e.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(e.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End Try
Else
If strScript.Trim(vbCrLf).LastIndexOf(vbCrLf) = -1 Then
Expand All @@ -246,7 +246,7 @@ Public Class RLink
Try
clsEngine.Evaluate(strSplitScript)
Catch e As Exception
MsgBox("Error occurred in attempting to run:" & vbNewLine & strSplitScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & e.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(e.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End Try
End If
strSplitScript = Right(strScript, strScript.Length - strScript.Trim(vbCrLf).LastIndexOf(vbCrLf) - 2)
Expand All @@ -257,7 +257,7 @@ Public Class RLink
strTemp = String.Join(vbCrLf, temp.AsCharacter())
strOutput = strOutput & strTemp & vbCrLf
Catch e As Exception
MsgBox("Error occurred in attempting to run:" & vbNewLine & strCapturedScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & e.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(e.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End Try
End If
If bOutput Then
Expand Down Expand Up @@ -311,7 +311,7 @@ Public Class RLink
expTemp = clsEngine.GetSymbol(strVariableName)
Catch ex As Exception
If Not bSilent Then
MsgBox("Error occurred in attempting to run:" & vbNewLine & strScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & ex.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(ex.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End If
End Try
End If
Expand All @@ -327,7 +327,7 @@ Public Class RLink
chrTemp = expTemp.AsCharacter()
Catch ex As Exception
If Not bSilent Then
MsgBox("Error occurred in attempting to run:" & vbNewLine & strScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & ex.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(ex.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End If
chrTemp = Nothing
End Try
Expand Down Expand Up @@ -359,7 +359,7 @@ Public Class RLink
Return True
Catch ex As Exception
If Not bSilent Then
MsgBox("Error occurred in attempting to run:" & vbNewLine & strScript & vbNewLine & vbNewLine & "With error message:" & vbNewLine & ex.Message & vbNewLine & vbNewLine, MsgBoxStyle.Critical, "Error running R code")
MsgBox(ex.Message & vbNewLine & "The error occurred in attempting to run the following R command(s):" & vbNewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End If
Return False
End Try
Expand Down
78 changes: 45 additions & 33 deletions instat/clsRSyntax.vb
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
' Instat+R
' Copyright (C) 2015
'
' 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 k
' along with this program. If not, see <http://www.gnu.org/licenses/>.


Public Class RSyntax
' Instat+R
' Copyright (C) 2015
'
' 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 k
' along with this program. If not, see <http://www.gnu.org/licenses/>.


Public Class RSyntax
'RSyntax is intended to store all the R-commands that are raised by the activity of a dialogue.
'So far, it consists in a main R-command (Base), that takes the form of:
'- an "RFunction", dealing with R-commands of the form __(__=__, __=__, ...),
'- "ROperator", dealing with R-commands of the form: __+__,
'- or more generally a string.
'See also RLink to understand how these commands, as RSyntax fields, are then communicated to, and run in R.
Public clsBaseFunction As New RFunction
Public clsBaseOperator As New ROperator
Public strCommandString As String = ""
Public bUseBaseFunction As Boolean = False
Public bUseBaseOperator As Boolean = False
Public bUseCommandString As Boolean = False
'Above, the three types of Base R-commands, and their associated "radio bottons booleans".
Public iCallType As Integer = 0
Public strScript As String
Public i As Integer
Public bExcludeAssignedFunctionOutput As Boolean = True
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
'Explain a little bit the different roles and nature of the different AssignTo ...
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.
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.
Private bAssignToIsPrefix As Boolean
Private bAssignToColumnWithoutNames As Boolean
Private bInsertColumnBefore As String

Public Sub SetFunction(strFunctionName As String, Optional ByRef clsFunction As RFunction = Nothing)
If clsFunction Is Nothing Then
clsFunction = clsBaseFunction
End If
clsFunction.SetRCommand(strFunctionName)
Public Sub SetFunction(strFunctionName As String)
'Warning: confusing name
clsBaseFunction.SetRCommand(strFunctionName)
bUseBaseFunction = True
bUseBaseOperator = False
bUseCommandString = False
Expand All @@ -53,27 +62,30 @@ Public Class RSyntax
bUseBaseOperator = False
bUseCommandString = False
End Sub

'Both SetFunction and SetBaseRFunction set the Base R-command to the RFunction type,
'and set the clsBaseFunction by giving respectively the desired RFunction as parameter, or the R-command that characterizes the desired RFunction as parameter.
Public Sub SetBaseROperator(clsOperator As ROperator)
clsBaseOperator = clsOperator
bUseBaseFunction = False
bUseBaseOperator = True
bUseCommandString = False
End Sub

Public Sub SetOperation(strOp As String, Optional bBracketTemp As Boolean = True)
clsBaseOperator.SetOperation(strOp, bBracketTemp)
bUseBaseFunction = False
bUseBaseOperator = True
bUseCommandString = False
End Sub

End Sub
'Similarly, both SetBaseROperator and SetOperation set the Base R-command to the ROperator type,
'and set the clsBaseOperator by giving respectively the desired ROperator itself as parameter, or the desired R-command that characterize the desired ROperator as parameters.
Public Sub SetCommandString(strCommand As String)
strCommandString = strCommand
bUseBaseFunction = False
bUseBaseOperator = False
bUseCommandString = True
End Sub

Public Sub SetOperation(strOp As String, Optional bBracketTemp As Boolean = True)
clsBaseOperator.SetOperation(strOp, bBracketTemp)
bUseBaseFunction = False
bUseBaseOperator = True
bUseCommandString = False
End Sub
'In the string case, the class used for the Base R-command is simply a string...

Public Sub SetAssignTo(strAssignToName As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False, Optional bAssignToColumnWithoutNames As Boolean = False, Optional bInsertColumnBefore As Boolean = False)
If bUseBaseOperator Then
Expand Down
2 changes: 2 additions & 0 deletions instat/dlgCanonicalCorrelationAnalysis.Designer.vb

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

20 changes: 10 additions & 10 deletions instat/dlgCountinFactor.Designer.vb

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

33 changes: 21 additions & 12 deletions instat/dlgCountinFactor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports instat.Translations
Public Class dlgCountinFactor
Private bFirstLoad As Boolean
Private bFirstLoad As Boolean = True
Private Sub dlgCountinFactor_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
InitialiseDialog()
Expand All @@ -24,29 +24,30 @@ Public Class dlgCountinFactor
Else
ReopenDialog()
End If
TestOkEnabled()
End Sub
Private Sub InitialiseDialog()
ucrCountReceiver.Selector = ucrCountSelector
ucrCountReceiver.SetIncludedDataTypes({"factor"})
ucrCountReceiver.SetMeAsReceiver()

ucrInputColumnName.SetPrefix("Count")
ucrInputColumnName.SetItemsTypeAsColumns()
ucrInputColumnName.SetDefaultTypeAsColumn()
ucrInputColumnName.SetDataFrameSelector(ucrCountSelector.ucrAvailableDataFrames)
ucrInputColumnName.SetValidationTypeAsRVariable()

'ucrBase.iHelpTopicID=
ucrInputCountColumnName.SetItemsTypeAsColumns()
ucrInputCountColumnName.SetDefaultTypeAsColumn()
ucrInputCountColumnName.SetDataFrameSelector(ucrCountSelector.ucrAvailableDataFrames)
ucrInputCountColumnName.SetValidationTypeAsRVariable()
ucrBase.clsRsyntax.SetFunction("fac.nested")
End Sub
Private Sub SetDefaults()
ucrCountSelector.Reset()
ucrInputColumnName.Reset()
ucrInputCountColumnName.Reset()
ucrInputCountColumnName.SetPrefix("Count")
TestOkEnabled()
End Sub
Private Sub ReopenDialog()

End Sub
Private Sub TestOkEnabled()
If Not ucrCountReceiver.IsEmpty AndAlso Not ucrInputColumnName.IsEmpty Then
If Not ucrCountReceiver.IsEmpty AndAlso Not ucrInputCountColumnName.IsEmpty Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
Expand All @@ -56,8 +57,16 @@ Public Class dlgCountinFactor
SetDefaults()
End Sub

Private Sub ucrInputColumnName_NameChanged() Handles ucrInputColumnName.NameChanged
ucrBase.clsRsyntax.SetAssignTo(strAssignToName:=ucrInputColumnName.GetText, strTempDataframe:=ucrCountSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrInputColumnName.GetText, bAssignToIsPrefix:=True)
Private Sub ucrInputColumnName_NameChanged() Handles ucrInputCountColumnName.NameChanged
ucrBase.clsRsyntax.SetAssignTo(strAssignToName:=ucrInputCountColumnName.GetText, strTempDataframe:=ucrCountSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrInputCountColumnName.GetText, bAssignToIsPrefix:=True)
TestOkEnabled()
End Sub
Private Sub ucrCountReceiver_SelectionChanged(sender As Object, e As EventArgs) Handles ucrCountReceiver.SelectionChanged
If Not ucrCountReceiver.IsEmpty Then
ucrBase.clsRsyntax.AddParameter("nesting.fac", clsRFunctionParameter:=ucrCountReceiver.GetVariables)
Else
ucrBase.clsRsyntax.RemoveParameter("nesting.fac")
End If
TestOkEnabled()
End Sub
End Class
2 changes: 1 addition & 1 deletion instat/dlgOneVarCompareModels.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Imports instat.Translations

Public Class dlgOneVarCompareModels
Private clsRcdfcompFunction As New RFunction
'Private clsRcdfcompFunction As New RFunction
Public bfirstload As Boolean = True

Private Sub dlgOneVarCompareModels_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Expand Down
Loading

0 comments on commit ccd45ac

Please sign in to comment.