[R] Windows: start script but keep being in R-shell after finish

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Wed Sep 22 11:44:17 CEST 2021

>>>>> Duncan Murdoch 
>>>>>     on Tue, 21 Sep 2021 09:09:40 -0400 writes:

    > On 21/09/2021 3:12 a.m., c.buhtz using posteo.jp wrote:
    >> Hello together,
    >> I was using R some years ago and I am sorry for asking such a dumb
    >> question. I found some help instructions about commandline interface but
    >> I still miss the piece of information I need. I assume it depends on my
    >> non-nativ English that I am not able to ask the correct (worded)
    >> question to the search engines.
    >> I use R-for-windows on the shell. No GUI, IDE or anything else.
    >> When I am in windows shell ("command prompt"?) I wan't to run an
    >> R-script (filename *.R). But when the script is finished or interrupted
    >> the R-prompt should do not close.
    >> In python I would do
    >> python3 -i -m myscript

    > I don't think R supports this, but the following almost works:

    > cat myscript.R - | Rterm --ess

Inside R, we use


where source() has several optional arguments in addition,
such as 'echo=TRUE' 

Probably Duncan did not mention it here, because indeed, it's
not quite equivalent to running the above semi-"batch mode"...


    > This copies your file followed by stdin into the stdin of R.  The --ess 
    > option tells R to act as if input is interactive, despite what it sees.

    > This comes kind of close, but there are a couple of problems.

    > - If I type really fast, the characters appear in the wrong order in R.
    > - At the end when I quit, it sits there for a while until I hit enter, 
    > then gives the error message "cat: write error: no more space on device".

    > Perhaps these problems can be fixed.

    > Another approach would be to set an environment variable specifying that 
    > myscript.R is a user profile file, set via environment variable

    > R_PROFILE_USER=myscript.R

    > This has the disadvantage of overriding a pre-existing user profile 
    > file, but if this is just for you, I guess you know if you have one.

    > Duncan Murdoch

    > ______________________________________________
    > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
    > https://stat.ethz.ch/mailman/listinfo/r-help
    > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    > and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list