Send code from a r script to terminal

So, to run '5 + 5' in the terminal on a windows machine, I type

r -e 5 + 5

And it works.

Now, if I want to run an entire script from Rstudio - Or just a single line - I can see the windows keyboard

ctrl + alt + enter

pops it up in the terminal yet that fails, because it doesn't call

r -e.

What am I missing?

If you're talking about the terminal, as opposed to the console, I don't think it's set up to be used as an R REPL by default (since that's what the Console in RStudio is used for).

So, if I want to execute an R command in the terminal in RStudio, I first have to open R in the terminal (in the gif I show what happens if I send 5 + 5 to the terminal before and after opening R)

send R commands to terminal in RStudio

Edit Whoops, sorry that one got trimmed before I actually ran 5 + 5

1 Like

I wanted to use the terminal to execute heavy scripts, while still working in rstudio without it freezing :slight_smile:

How do you open R in the terminal? I cant follow it from the gif.

For me it's just typing in the letter r and hit enter (same way as in terminal outside of RStudio).

That drops your terminal into an R session.

1 Like

You can call the script from the terminal using Rscript, something like

  $ Rscript myscript.R

For my preference, I include at the very first line of the script the location of RScript in my computer with a shebang


and then make it executable with

$ chmod +x myscript.R

And finally run it:

$ ./myscript.R

Not sure if this could work on windows system. Certainly Rscript works, so that's what you should be looking at :slightly_smiling_face: ht_smile: