How to copy from R console without using mouse

So, I'm a keyboard/shortcut fanatic and want to copy text from the console without to fall back on to mouse. With Ctrl+2 I can obviously put the focus on the console but only scroll through the executed code via arrow up and down keys. Is it possible to somehow instead put the focus on the output? Like let's say I execute typeof(variable)and R Studio returns [1] "double" - how do I copy that?

Hi there,

There might be a way to do that with some sort of custom add on but you can also just formally assign that output to an object and use it as you want to within the session/script.

variable <- 3

#> [1] "double"

what_type <- typeof(variable)

#> [1] "double"

Created on 2021-10-26 by the reprex package (v2.0.1)

Oh well, that's the obvious solution that I didn't think of! Thanks for that. However, it's not exactly what I was looking for: It requires another line of code. I just want to copy the output and specifically not assign anything on top, which makes the code larger and more difficult to read.

1 Like

Speaking of that addon. You will want to look at CLIPR. See here: r - Copy text from RStudio console as "plain text" - Stack Overflow

1 Like

It doesn't work for me at this point and instead returns the error:

Error in file(file, ifelse(append, "a", "w")) :
'mode' for the clipboard must be 'r' on Unix

Sounds like something, that has to be solved at the backend as I'm working with the server version of R Studio.

Ahh that might make it more difficult then yes. Also seems like the unix version needs to be setup slightly different. I know too little of that setup to be able to advise you.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.