I don't know about others but I often find myself pasting blocks of text into RStudio scripts, e.g. small paragraphs from a paper explaining the steps they took, or a chunk of an email with natural language explanations that I'd need to convert to code.
This pastes in as a single line of text, and one then has to:
comment that line
find the space before the first word which would go outside the margin
delete space
hit enter to carriage-return the rest of the text to the next line
Then repeat those steps.
It would be SO nice if there was a "paste as wrapped comment" option where RStudio would do that for us. Is that possible / a lot of work?
Cheers!
This was a fun challenge
I came up with a function that will convert any text on your clipboard to a comment once you paste it into R after running it.
Now to make it an AddIn. Potentially if we add a "paste clipboard here" line at the end then the user could copy external text then hit the addin & it'll source the function, run it, and paste the result. Looks like that could be insertText from the addins library. I'll share it here if I get it working. Cheers for your help!
Yea I don't use other OS so that's indeed something that needs to be checked before deployed. There are more ways I can think of of improving the function, but I agree it only becomes really useful once integrated in R-Studio where you can access the command by a special paste shortcut or a right-click menu option "paste as comment"
Also, I don't know the read_clip function, but be careful all the text from the clipboard is stripped of formatting and special characters are not interpreted as copying things like links/tables/... would otherwise mess up the code. That's why I wrapped it in the toString() function to make sure it's only string text.
If you find a way to integrate the function, I'm happy to add some more functionality to it.