Click here to Skip to main content
15,886,088 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
My code is-
cd C:\Program Files\R\R-3.2.0\bin\i386
"C:\Program Files\R\R-3.2.0\bin\i386\R.exe" CMD BATCH "C:\Users\Dell\Desktop\demo.R"
It shows wrong Output,generates file in wrong extension
Posted
Updated 9-Feb-22 20:42pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Dec-15 21:01pm    
How "CMD", ever, in any sense, can do anything with the batch?!
—SA

This is an example using a hybrid file.bat + script.r
@;echo off && setlocal 
@;
@;pushd "C:\Program Files\R\R-4.0.5\bin\i386\." 2>nul && (
@;
@;    %__APPDIR__%findstr.exe /vb @; ^<"%~f0" >"%temp%\RScr.r"
@;    R.exe --vanilla <"%tmp%\RScr.r">nul 2>&1 ) || ( 
@;
@;   echo\Error: script.r not found^!! )
@;
@;2>nul del/q "%tmp%\RScr.r" & endlocal & goto :eof
@;
@;rem :: below you can insert your R codes without start lines with "@;"

require(tcltk)

msgBox <- tkmessageBox(title = "tc/ltk SO Q431647",
                       message = "Hello, world! by tcltk!", icon = "info", type = "ok")

msgBox <- tkmessageBox(title = "zOk Click..",
                       message = "z0k", type = "ok")


Try:
cd /d "C:\Program Files\R\R-3.6.1\bin\i386" && Rscript.exe ScriptCode.R

https://i.stack.imgur.com/SRRnc.gif[^]

bat - Gerar uma janela de pop-up no R - Stack Overflow em Português[^]
 
Share this answer
 
v2
An excerpt from Run R script from command line - Stack Overflow[^]

If you want the output to print to the terminal it is best to use Rscript

BAT
Rscript a.R

Note that when using R CMD BATCH a.R that instead of redirecting output to standard out and displaying on the terminal a new file called a.Rout will be created.

BAT
R CMD BATCH a.R
# Check the output
cat a.Rout
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900