-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_fmi.ps1
More file actions
44 lines (36 loc) · 1.59 KB
/
Copy pathrun_fmi.ps1
File metadata and controls
44 lines (36 loc) · 1.59 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
<#
.SYNOPSIS
Caprazli FMI Auto-Launcher
.DESCRIPTION
Automatically locates the latest R installation on Windows and executes the analysis pipeline.
#>
Write-Host ">>> [INIT] Looking for R installation..." -ForegroundColor Cyan
# 1. Find Rscript.exe automatically in Program Files
# We sort descending to grab the highest version number (e.g., R-4.3.1 over R-4.1.0)
$rScriptPath = Get-ChildItem -Path "C:\Program Files\R" -Filter "Rscript.exe" -Recurse -ErrorAction SilentlyContinue |
Sort-Object FullName -Descending |
Select-Object -First 1 -ExpandProperty FullName
if (-not $rScriptPath) {
Write-Host ">>> [ERROR] Rscript.exe not found in C:\Program Files\R." -ForegroundColor Red
Write-Host " Please ensure R is installed in the default location."
Exit
}
Write-Host ">>> [FOUND] Using R at: $rScriptPath" -ForegroundColor Green
# 2. Check if the Analysis Script exists
$scriptPath = "R\run_analysis.R"
if (-not (Test-Path $scriptPath)) {
Write-Host ">>> [ERROR] Analysis script not found at: $scriptPath" -ForegroundColor Red
Write-Host " Did you save the file inside the 'R' folder?"
Exit
}
# 3. Execute the Pipeline
Write-Host ">>> [EXEC] Starting Caprazli FMI Pipeline..." -ForegroundColor Cyan
& $rScriptPath $scriptPath
# 4. Finish
if ($LASTEXITCODE -eq 0) {
Write-Host "`n>>> [SUCCESS] Analysis complete. Check the 'output' folder." -ForegroundColor Green
} else {
Write-Host "`n>>> [FAIL] The R script encountered an error." -ForegroundColor Red
}
# Pause so the window doesn't close immediately
Read-Host -Prompt "Press Enter to exit"