I have written a programme in Stata that calls R to run an R script (SLS.R). This works fine on a Mac operating system but when I try this in a Windows operating system the user has to manually click to close the shell. Is there a way to automatically close the shell window instead of having to manually click?
Any help is much appreciated!
Code:
if "`c(os)'" == "MacOSX" {
shell "/usr/local/bin/r" CMD BATCH SLS.R
}
else{
// Write batch file to find R.exe path and R version
set more off
qui: file close _all
qui: file open bat using setup.bat, write replace
qui: file write bat ///
`"@echo off"' _newline ///
`"SET PATHROOT=C:\Program Files\R\"' _newline ///
`"echo Locating path of R..."' _newline ///
`"echo."' _newline ///
`"if not exist "%PATHROOT%" goto:NO_R"' _newline ///
`"for /f "delims=" %%r in (' dir /b "%PATHROOT%R*" ') do ("' _newline ///
`"echo Found %%r"' _newline ///
`"echo shell "%PATHROOT%%%r\bin\x64\R.exe" CMD BATCH SLS.R > runr.do"' _newline ///
`"echo All set!"' _newline ///
`"goto:DONE"' _newline ///
`")"' _newline ///
`":NO_R"' _newline ///
`"echo R is not installed in your system."' _newline ///
`"echo."' _newline ///
`"echo Download it from https://cran.r-project.org/bin/windows/base/"' _newline ///
`"echo Install it and re-run this script"' _newline ///
`":DONE"' _newline ///
`"echo."' _newline ///
`"pause"'
qui: file close bat
//Run batch
shell setup.bat
//Run R
do runr.do
}

Comment