From 06e6a90d4e535e2cba1877a36d9a10e7abcbe847 Mon Sep 17 00:00:00 2001 From: lloyddewit Date: Mon, 27 Jan 2020 11:25:34 +0100 Subject: [PATCH 1/3] #5577 was caused by the following: - `RLink.RunScript(...)`, line 570 - Calls `Evaluate(...)` with the R script (e.g. `.temp_val <- capture.output(2+x)`) - `Evaluate(...)` returns `True` if script executed successfully, else `False` - Line 570 ignores the return value - `RLink.RunScript(...)`, lines 571-577 - Extracts and displays the value of `.temp_val` - If the script was not successful then `.temp_val` still contains its previous value (or is potentially undefined) Issue fixed by: - line 570: Check the return value of `Evaluate(...)` - If `True` then - Extract and display the value of `.temp_val` - Remove `.temp_val` (as recommended by @dannyparsons it's good to keep the R environment tidy and remove variables after using them) - Else do nothing --- instat/clsRLink.vb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index 363d0f292f0..ad1eb3eac42 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -567,12 +567,14 @@ Public Class RLink strCapturedScript = "capture.output(" & strSplitScript & ")" End If Try - Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) - expTemp = GetSymbol(strTempAssignTo) - If expTemp IsNot Nothing Then - strTemp = String.Join(Environment.NewLine, expTemp.AsCharacter()) - If strTemp <> "" Then - strOutput = strOutput & strTemp & Environment.NewLine + If Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) = True Then + expTemp = GetSymbol(strTempAssignTo) + Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True) + If expTemp IsNot Nothing Then + strTemp = String.Join(Environment.NewLine, expTemp.AsCharacter()) + If strTemp <> "" Then + strOutput = strOutput & strTemp & Environment.NewLine + End If End If End If Catch e As Exception From aa71f554fcb2fd55baa9e62631fc8f5343ddba53 Mon Sep 17 00:00:00 2001 From: lloyddewit Date: Mon, 27 Jan 2020 12:15:03 +0100 Subject: [PATCH 2/3] Removed `= True` check from if ststement. --- instat/clsRLink.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index ad1eb3eac42..2418c7266b2 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -567,7 +567,7 @@ Public Class RLink strCapturedScript = "capture.output(" & strSplitScript & ")" End If Try - If Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) = True Then + If Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) Then expTemp = GetSymbol(strTempAssignTo) Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True) If expTemp IsNot Nothing Then From ac8ac5687fa2676b2e02d0f6cfce944615ff87f3 Mon Sep 17 00:00:00 2001 From: Danny Parsons Date: Mon, 27 Jan 2020 17:29:11 +0300 Subject: [PATCH 3/3] added check to capture error when displaying assigned output (multi line commands) --- instat/clsRLink.vb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index 2418c7266b2..10fff377fd5 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -444,6 +444,7 @@ Public Class RLink Dim clsPNGFunction As New RFunction Dim strTempAssignTo As String = ".temp_val" Dim bSuccess As Boolean + Dim bError As Boolean = False strTempGraphsDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath() & "R_Instat_Temp_Graphs") strOutput = "" @@ -558,7 +559,7 @@ Public Class RLink strSplitScript = Left(strScript, strScript.Trim(Environment.NewLine.ToCharArray).LastIndexOf(Environment.NewLine.ToCharArray)) If strSplitScript <> "" Then Try - Evaluate(strSplitScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) + bError = Not Evaluate(strSplitScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) Catch e As Exception MsgBox(e.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 Try @@ -567,13 +568,15 @@ Public Class RLink strCapturedScript = "capture.output(" & strSplitScript & ")" End If Try - If Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) Then - expTemp = GetSymbol(strTempAssignTo) - Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True) - If expTemp IsNot Nothing Then - strTemp = String.Join(Environment.NewLine, expTemp.AsCharacter()) - If strTemp <> "" Then - strOutput = strOutput & strTemp & Environment.NewLine + If Not bError Then + If Evaluate(strTempAssignTo & " <- " & strCapturedScript, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride) Then + expTemp = GetSymbol(strTempAssignTo) + Evaluate("rm(" & strTempAssignTo & ")", bSilent:=True) + If expTemp IsNot Nothing Then + strTemp = String.Join(Environment.NewLine, expTemp.AsCharacter()) + If strTemp <> "" Then + strOutput = strOutput & strTemp & Environment.NewLine + End If End If End If End If