diff --git a/instat/frmMain.vb b/instat/frmMain.vb index 6b37bf3c29..8d2464c286 100644 --- a/instat/frmMain.vb +++ b/instat/frmMain.vb @@ -223,9 +223,15 @@ Public Class frmMain '--------------------------------------- '-------------------------------------- - CreateAdditionalLibraryDirectory() + Dim strVersion As String = My.Application.Info.Version.Major.ToString() & "." & + My.Application.Info.Version.Minor.ToString() & "." & + My.Application.Info.Version.Build.ToString() + + Me.Text = "R-Instat " & strVersion + + CreateAdditionalLibraryDirectory(strVersion) '------------------------------------- - SetAppVersionNumber() + isMaximised = True 'Need to get the windowstate when the application is loaded SetHideMenus() End Sub @@ -398,9 +404,9 @@ Public Class frmMain End If End Function - Private Sub CreateAdditionalLibraryDirectory() + Private Sub CreateAdditionalLibraryDirectory(strVersion As String) ' Define the custom library path in the ApplicationData folder - Dim strLibraryPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "R-Instat", "library") + Dim strLibraryPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "R-Instat", strVersion, "library") Try ' Check if the directory exists, if not, create it @@ -408,18 +414,15 @@ Public Class frmMain Directory.CreateDirectory(strLibraryPath) End If + 'To ensure this part of the code only runs when the application Is Not in the Debug mode (i.e., in Release mode) #If Not DEBUG Then - ' Add the custom library path to R's .libPaths for user-level package installation - Dim strScript As String = $".libPaths(c('{strLibraryPath.Replace("\", "/")}', .libPaths()))" & Environment.NewLine & - "if (length(.libPaths()) > 2) { - current_paths <- .libPaths() - valid_indices <- c(1, 3)[c(1, 3) <= length(current_paths)] - .libPaths(current_paths[valid_indices]) - }" + Dim clsSetLibPathsFunction As New RFunction + clsSetLibPathsFunction.SetRCommand("set_library_paths") + clsSetLibPathsFunction.AddParameter("library_path", Chr(34) & strLibraryPath.Replace("\", "/") & Chr(34)) ' Execute the R script to update the library paths - clsRLink.RunScript(strScript:=strScript, bSeparateThread:=False, bSilent:=False) + clsRLink.RunScript(strScript:=clsSetLibPathsFunction.ToScript, bSeparateThread:=False, bSilent:=False) #End If Catch ex As Exception ' Handle potential errors (e.g., directory creation failure) @@ -590,10 +593,8 @@ Public Class frmMain mnuTbLan.Visible = bVisible End Sub - Public Sub SetAppVersionNumber() - Me.Text = "R-Instat " & My.Application.Info.Version.Major.ToString() & "." & - My.Application.Info.Version.Minor.ToString() & "." & - My.Application.Info.Version.Build.ToString() + Public Sub SetAppVersionNumber(strVersionNumber As String) + End Sub Private Sub SetHideMenus() diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index ef7ae16ee9..be519ef0b0 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3429,4 +3429,21 @@ monitor_memory <- function() { time_operation <- function(expr) { timing <- system.time(expr) print(timing) -} \ No newline at end of file +} + +set_library_paths <- function(library_path) { + # Update the library paths + .libPaths(c(library_path, .libPaths())) + + # Check if there are more than 2 library paths + if (length(.libPaths()) > 2) { + # Get the current library paths + current_paths <- .libPaths() + + # Select valid indices (1 and 3) only if they exist + valid_indices <- c(1, 3)[c(1, 3) <= length(current_paths)] + + # Set the library paths to the valid ones + .libPaths(current_paths[valid_indices]) + } +}