Brilliant stuff, thanks!
Although, intially disappointing as it doesn't work outside windows; below is the same with a couple of tiny tweaks for crossOS compatibility.
# sudo apt install xclip
library("clipr")
library("stringr")
textToComment = function(blockWidth = 80){
myText = read_clip()
myLines = list()
while(nchar(myText) > 0){
myBreak = c(str_locate_all(myText, " ")[[1]][,1], nchar(myText))
if(length(myBreak) > 0){
myBreak = myBreak[myBreak < blockWidth]
myBreak = myBreak[length(myBreak)]
myLine = substr(myText, 1, myBreak)
myText = substr(myText, (myBreak+1), nchar(myText))
} else {
myLine = myText
myText = ""
}
myLines = append(myLines, myLine)
}
write_clip(paste(paste("#", unlist(myLines), sep = " ")))
}
textToComment()
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!