Description
The function ROpenCVLite:::.findRtools() fails to correctly parse the Rtools version on Windows systems where PowerShell scripts (specifically the user profile) are disabled by Group Policy or restricted due to being located on a network share (UNC path).
In such environments, the system() call to PowerShell returns a multi-line character vector containing a PSSecurityException warning followed by the actual version number. This causes the subsequent if (is.na(rtools_version)) check to fail with the error:
Error in if (is.na(rtools_version)) ... : the condition has length > 1.
Steps to Reproduce
- Use a Windows machine where the PowerShell Execution Policy is set to
Restricted or where the user profile profile.ps1 is located on a network drive (e.g., \\server\home\user\Documents\WindowsPowerShell\profile.ps1).
- Attempt to install or load
ROpenCVLite.
- The Rtools detection logic executes the following:
rtools_version <- system(paste0("powershell (Get-Item ", rtools_path, "/unins000.exe).VersionInfo.ProductVersion"), intern = TRUE)
Actual Output
The rtools_version variable becomes a character vector of length 9:
[1] ". : File \\\\salv1\\home\\asims\\My Documents\\WindowsPowerShell\\profile.ps1 cannot be loaded because running scripts is disabled on this system."
...
[8] "+ FullyQualifiedErrorId : UnauthorizedAccess"
[9] "4.5.6768"
Because the vector length is $> 1$, the if statement crashes the installer.
Suggested Fix
To make the Rtools detection more robust, the PowerShell call should include the -NoProfile flag to ensure a clean output regardless of the user's environment or security policies:
# Current line:
system(paste0("powershell (Get-Item ", rtools_path, "/unins000.exe).VersionInfo.ProductVersion"), intern = TRUE)
# Suggested fix:
system(paste0("powershell -NoProfile (Get-Item ", rtools_path, "/unins000.exe).VersionInfo.ProductVersion"), intern = TRUE)
Additionally, it might be safer to use tail(rtools_version, 1) or a regex to extract the version number if the output contains warnings.
Description
The function
ROpenCVLite:::.findRtools()fails to correctly parse the Rtools version on Windows systems where PowerShell scripts (specifically the user profile) are disabled by Group Policy or restricted due to being located on a network share (UNC path).In such environments, the
system()call to PowerShell returns a multi-line character vector containing aPSSecurityExceptionwarning followed by the actual version number. This causes the subsequentif (is.na(rtools_version))check to fail with the error:Error in if (is.na(rtools_version)) ... : the condition has length > 1.Steps to Reproduce
Restrictedor where the user profileprofile.ps1is located on a network drive (e.g.,\\server\home\user\Documents\WindowsPowerShell\profile.ps1).ROpenCVLite.Actual Output
The
rtools_versionvariable becomes a character vector of length 9:Because the vector length is$> 1$ , the
ifstatement crashes the installer.Suggested Fix
To make the Rtools detection more robust, the PowerShell call should include the
-NoProfileflag to ensure a clean output regardless of the user's environment or security policies:Additionally, it might be safer to use
tail(rtools_version, 1)or a regex to extract the version number if the output contains warnings.