I have created a package {chunkthis}
which provides a Rstudio Addins Chunk the code
to do this.
At first, install the package from GitHub using install_github
which is a function from {remotes}
package.
# install.packages("remotes")
remotes::install_github("shafayetShafee/chunkthis")
Doing this will add the addin in Rstudio. Then, simply copy something then use that addin to paste wrapped in a R code-chunk fence. Or even you can add a keyboard shortcut for that addin.
To add a shortcut for Rstudio Addin, navigate to Tools -> Addins -> Browse Addins -> keyboard Shortcuts...
and then add a key board shortcut for that addin.
Hope this helps.