Rstudio Terminal Output to Object

137 Views Asked by At

I am using the rstudioapi package to run a command in the Rstudio terminal, like so:

myTerm <- rstudioapi::terminalCreate()
rstudioapi::terminalSend(myTerm, "echo Hello\n")

This gives me the following in the Rstudio terminal:

user@devicenum:~$ echo Hello
Hello

I would like to have the output available as an object in my Rstudio environment. Is there a simple way to do this? Thank you!

Edit: I can apparently do this by using | clip.exe:

myTerm <- rstudioapi::terminalCreate()
rstudioapi::terminalSend(myTerm, "echo Hello |clip.exe\n")
x <- readClipboard()
x

I can also use |& tee to save output and stderr to a file.

It's slower than system() or system2() but at least it works.

0

There are 0 best solutions below