Public/Set-ScriptPath.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Set-ScriptPath {

    <#

    .SYNOPSIS
    Set Rscript path

    .DESCRIPTION
    Configures the path to Rscript.exe as preparation for other commands.

    .PARAMETER Path
    Specifies the path to Rscript.exe to be used by other commands.

    .EXAMPLE
    PS C:\> Set-RScriptPath -Path 'C:\Program Files\Microsoft\R Open\R-3.5.2\bin\x64\Rscript.exe'
    PS C:\> $version = Get-RVersion
    R scripting front-end version 3.5.2 (2018-12-20)

    #>


    [CmdletBinding()]
    param (
        [Parameter( Mandatory )]
        [ValidateScript({ Test-Path $_ -PathType Leaf })]
        [ValidateScript({ $_.EndsWith('Rscript.exe') })]
        [string] $Path
    )

    Set-Variable -Name RScriptPath -Value $Path -Visibility Public -Scope Script

}