Skip to content

Commit

Permalink
Merge pull request #2912 from dannyparsons/packagename
Browse files Browse the repository at this point in the history
implemented package name for RFunctions with example on scatter and one variable model dialogs
  • Loading branch information
dannyparsons authored Apr 10, 2017
2 parents 5767098 + 5db975e commit e855f86
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion instat/clsRFunction.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Public Class RFunction
Inherits RCodeStructure

Public strRCommand As String
Private strPackageName As String = ""

Public Sub New()
OnParametersChanged()
Expand All @@ -28,14 +29,21 @@ Public Class RFunction
bIsAssigned = False
End Sub

Public Sub SetPackageName(strName As String)
strPackageName = strName
End Sub

Public Overrides Function ToScript(Optional ByRef strScript As String = "", Optional strTemp As String = "") As String
'Converting the RFunction into a string that when run in R gives the appropriate output
Dim i As Integer
'For method with OrderedIndices, replace clsParameters.count by Mybase.OrderedIndices.count and i by Mybase.OrderedIndices(i)

'Parameters are sorted in the appropriate order and then the script is built.
SortParameters()
strTemp = strRCommand & "("
If strPackageName <> "" Then
strTemp = strPackageName & "::"
End If
strTemp = strTemp & strRCommand & "("
For i = 0 To clsParameters.Count - 1
If i > 0 Then
strTemp = strTemp & ", "
Expand Down
11 changes: 11 additions & 0 deletions instat/clsRSyntax.vb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Public Class RSyntax
bUseCommandString = False
End Sub

Public Sub SetPackageName(strName As String)
If clsBaseFunction Is Nothing Then
MsgBox("Developer error: base function must be set before package name is set.")
Else
clsBaseFunction.SetPackageName(strName)
bUseBaseFunction = True
bUseBaseOperator = False
bUseCommandString = False
End If
End Sub

Public Sub SetBaseRFunction(clsFunction As RFunction)
clsBaseFunction = clsFunction
bUseBaseFunction = True
Expand Down
7 changes: 5 additions & 2 deletions instat/dlgOneVarFitModel.vb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Public Class dlgOneVarFitModel

Public Sub FitDistFunction()
UcrBase.clsRsyntax.SetBaseRFunction(clsROneVarFitModel)
clsROneVarFitModel.SetPackageName("fitdistrplus")
clsROneVarFitModel.SetRCommand("fitdist")
clsROneVarFitModel.AddParameter("distr", Chr(34) & ucrFamily.clsCurrDistribution.strRName & Chr(34))
SetDataParameter()
Expand All @@ -210,7 +211,8 @@ Public Class dlgOneVarFitModel
End Sub

Private Sub SetVarTest()
clsVarTest.SetRCommand("EnvStats::varTest")
clsVarTest.SetPackageName("EnvStats")
clsVarTest.SetRCommand("varTest")
UcrBase.clsRsyntax.SetBaseRFunction(clsVarTest)
clsRConvert.SetRCommand("as.vector")
clsRConvert.AddParameter("x", clsRFunctionParameter:=UcrReceiver.GetVariables())
Expand Down Expand Up @@ -241,7 +243,8 @@ Public Class dlgOneVarFitModel
End Sub

Private Sub SetNonSignTest()
clsRNonSignTest.SetRCommand("signmedian.test:: signmedian.test")
clsRNonSignTest.SetPackageName("signmedian.test")
clsRNonSignTest.SetRCommand("signmedian.test")
UcrBase.clsRsyntax.SetBaseRFunction(clsRNonSignTest)
clsRNonSignTest.AddParameter("x", clsRFunctionParameter:=UcrReceiver.GetVariables())
clsRNonSignTest.AddParameter("conf.level", nudCI.Value.ToString)
Expand Down
3 changes: 3 additions & 0 deletions instat/dlgScatterPlot.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ Public Class dlgScatterPlot
Private Sub InitialiseDialog()
ucrBase.clsRsyntax.SetOperation("+")
clsRggplotFunction.SetRCommand("ggplot")
clsRggplotFunction.SetPackageName("ggplot2")
clsRaesFunction.SetRCommand("aes")
clsRaesFunction.SetPackageName("ggplot2")
clsRggplotFunction.AddParameter("mapping", clsRFunctionParameter:=clsRaesFunction)
ucrBase.clsRsyntax.SetOperatorParameter(True, clsRFunc:=clsRggplotFunction)

clsRgeom_scatterplotFunction.SetRCommand("geom_point")
clsRgeom_scatterplotFunction.SetPackageName("ggplot2")
ucrBase.clsRsyntax.SetOperatorParameter(False, clsRFunc:=clsRgeom_scatterplotFunction)

ucrVariablesAsFactorForScatter.SetFactorReceiver(ucrFactorOptionalReceiver)
Expand Down

0 comments on commit e855f86

Please sign in to comment.