-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst53_run.bat
More file actions
104 lines (85 loc) · 3.64 KB
/
Copy pathst53_run.bat
File metadata and controls
104 lines (85 loc) · 3.64 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@echo off
cd /d "%~dp0"
echo Wiping cached session states and temporary files
echo ----------------------------------------------------------------------
:: 1. Define the specific target paths
set "TARGET_DIR=%~dp0_Workflow\5_NBS\1_Managment_scenario\3_CropRotation\FarmR_project"
set "PORTABLE_RSTUDIO=%~dp0RStudio-Portable\rstudio.exe"
set "PORTABLE_R_EXE=%~dp0R-Portable\bin\x64\R.exe"
set "RENV_LIB_DIR=%~dp0renv\library"
:: 2. Delete targeted files if they exist in that specific folder
if exist "%TARGET_DIR%\.Rhistory" del /f /q "%TARGET_DIR%\.Rhistory"
if exist "%TARGET_DIR%\*.Rdata" del /f /q "%TARGET_DIR%\*.Rdata"
:: This safely removes the folder and its entire contents
if exist "%TARGET_DIR%\.Rproj.user" rmdir /s /q "%TARGET_DIR%\.Rproj.user"
:: CRITICAL FIX: Wipe out the autogenerated renv 'windows' platform folder to prevent library splits
if exist "%RENV_LIB_DIR%\windows" rmdir /s /q "%RENV_LIB_DIR%\windows"
echo Cleanup complete!
echo ----------------------------------------------------------------------
echo AUTOMATED PORTABILITY VERIFICATION:
echo Current Drive Root: %~d0
echo Workshop Directory: %~dp0
echo ----------------------------------------------------------------------
:: 3. VERIFY RSTUDIO PORTABLE PATH & EXECUTABLE VERSION
if not exist "%PORTABLE_RSTUDIO%" (
echo [ERROR] RStudio-Portable was not found at:
echo "%PORTABLE_RSTUDIO%"
echo Please make sure the folder is unzipped correctly on your drive.
echo.
pause
exit /b
)
for /f "usebackq tokens=1" %%v in (`powershell -NoProfile -Command "(Get-Item '%PORTABLE_RSTUDIO%').VersionInfo.ProductVersion"`) do set "DETECTED_RSTUDIO=%%v"
if not "%DETECTED_RSTUDIO%"=="2026.05.0+218" (
echo [WARNING] Mismatched RStudio version detected!
echo Expected: 2026.05.0+218
echo Found: %DETECTED_RSTUDIO%
echo.
pause
exit /b
) else (
echo [SUCCESS] RStudio Version Verified: 2026.05.0 Build 218
)
:: 4. VERIFY R ENGINE PATH & EXECUTABLE VERSION
if not exist "%PORTABLE_R_EXE%" (
echo [ERROR] Portable R Engine was not found at:
echo "%PORTABLE_R_EXE%"
echo.
pause
exit /b
)
:: Fix syntax issue by piping output to a temporary file first
"%PORTABLE_R_EXE%" --version > "%TEMP%\r_version_check.txt" 2>&1
:: Look explicitly for the literal phrase "R version" to avoid catching "R is free software"
for /f "tokens=3" %%r in ('findstr /C:"R version" "%TEMP%\r_version_check.txt"') do set "DETECTED_R=%%r"
:: Delete the temporary file
del /f /q "%TEMP%\r_version_check.txt" >nul 2>&1
if not "%DETECTED_R%"=="4.5.1" (
echo [WARNING] Mismatched R Engine version detected!
echo Expected: 4.5.1
echo Found: %DETECTED_R%
echo.
pause
exit /b
) else (
echo [SUCCESS] R Engine Version Verified: 4.5.1 "Great Square Root"
)
echo ----------------------------------------------------------------------
echo [SUCCESS] Everything matches perfectly!
echo ----------------------------------------------------------------------
:: 5. Force RStudio to use the flash drive's R binary version (R 4.5)
set "R_HOME=%~dp0R-Portable"
set "R_ARCH=x64"
set "PATH=%R_HOME%\bin\x64;%PATH%"
set "RSTUDIO_WHICH_R=%PORTABLE_R_EXE%"
:: 6. POINT THE LIBRARY EXPLICITLY TO THE SHARED MASTER DIRECTORY
set "RENV_PATHS_LIBRARY=%~dp0renv\library"
set "R_LIBS_USER=%~dp0renv\library"
set "R_LIBS_SITE="
set "RENV_CONFIG_SANDBOX_ENABLED=false"
:: 7. FORCE SPATIAL PACKAGES TO USE THE BUNDLE'S GEOSPATIAL DATABASES
set "PROJ_LIB=%~dp0renv\library\sf\proj"
set "GDAL_DATA=%~dp0renv\library\sf\gdal"
:: 8. Launch the project
echo Launching STEP 5.3 with Portable RStudio and Portable R 4.5.1...
start "" "%PORTABLE_RSTUDIO%" "%TARGET_DIR%\SWATfarmR_input.Rproj"