Skip to content
Back to formatted view

Raw Message

Message-ID: <011e9847-c4a8-c064-4944-49d9fe8f8201@gmail.com>
Date: 2021-09-21T13:09:40Z
From: Duncan Murdoch
Subject: Windows: start script but keep being in R-shell after finish
In-Reply-To: <c9bf6a264166d3184026b4dece4210a4@posteo.de>

On 21/09/2021 3:12 a.m., c.buhtz at 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

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