Skip to content

Title: ROpenCVLite:::.findRtools() fails when PowerShell Execution Policy restricts profile loading from UNC paths #53

@allan-sims

Description

@allan-sims

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

  1. 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).
  2. Attempt to install or load ROpenCVLite.
  3. 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 $&gt; 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions