Skip to content
Prev 389293 / 398506 Next

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

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