I want to invoke some R-Code by a certain Rscript.exe
via a Start-Process
-cmdlet. To do this, a powershell variable is given as -e
argument to Rscript in order to evaluate the code.
Steps to reproduce
Assuming the Powershell is opened in the bin
-Folder of a R-Installation, I can pass code as argument:
$code = "print('Nospaces');Sys.sleep(12)"
Start-Process .\Rscript.exe -ArgumentList "-e", $code
But if the code contains any spaces whatsoever, the Rscript will fire an unexpected end of input
-Error:
$code = "print('With spaces');Sys.sleep(12)"
Start-Process .\Rscript.exe -ArgumentList "-e", $code #it does not matter if code is in parenthesis or not
Start-Process .\Rscript.exe -ArgumentList "-e", "$code"
In this example, the space is located within a print statement, but hte space can be set anywhere within the code.
It does however work, if I do not invoke Rscript.exe via Start-Process
:
.\Rscript.exe -e $code
Question
Is there a way to invoke Rscript by starting the process and still being able to use code containing spaces within the $code
-Variable?
I want to invoke it via Start-Process
in order not to block the Powershell script while executing the RScript.