From 5db975eae2a176d1714437f0ffc3906ce3810fd6 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Mon, 10 Apr 2017 11:07:51 +0100 Subject: [PATCH] implemented package name in RFunction with example on scatter and one variable model --- instat/clsRFunction.vb | 10 +++++++++- instat/clsRSyntax.vb | 11 +++++++++++ instat/dlgOneVarFitModel.vb | 7 +++++-- instat/dlgScatterPlot.vb | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/instat/clsRFunction.vb b/instat/clsRFunction.vb index 5e28313af7a..a8f5555a4d6 100644 --- a/instat/clsRFunction.vb +++ b/instat/clsRFunction.vb @@ -18,6 +18,7 @@ Public Class RFunction Inherits RCodeStructure Public strRCommand As String + Private strPackageName As String = "" Public Sub New() OnParametersChanged() @@ -28,6 +29,10 @@ 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 @@ -35,7 +40,10 @@ Public Class RFunction '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 & ", " diff --git a/instat/clsRSyntax.vb b/instat/clsRSyntax.vb index c43a569a6a1..fec315a2006 100644 --- a/instat/clsRSyntax.vb +++ b/instat/clsRSyntax.vb @@ -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 diff --git a/instat/dlgOneVarFitModel.vb b/instat/dlgOneVarFitModel.vb index 6c755e1dd94..73674cb3480 100644 --- a/instat/dlgOneVarFitModel.vb +++ b/instat/dlgOneVarFitModel.vb @@ -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() @@ -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()) @@ -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) diff --git a/instat/dlgScatterPlot.vb b/instat/dlgScatterPlot.vb index 49e41d8a303..d675417fb9c 100644 --- a/instat/dlgScatterPlot.vb +++ b/instat/dlgScatterPlot.vb @@ -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)