rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.87k stars 977 forks source link

Wrapping existing text in a code block #2341

Closed jcpayne closed 2 years ago

jcpayne commented 2 years ago

Hi. I'm converting some long scripts (thousands of lines) into .Rmd files, in RStudio. The scripts contain both code and documentation, and It's tedious to have to type the code block start and end (triple backtick{r} or {sql}, ...code..., triple backtick) for every code block.

I know that the "Insert code chunk" shortcut (Option-Cmd-I on a Mac) will create a ready-made, empty code chunk; but I'm wondering if there is a way to wrap a new chunk around existing text without having to copy and paste.

It would also be great to have different pre-made chunks for R and SQL, for example, since I use them both.

Thanks.

cderv commented 2 years ago

Hi,

this would be feature for the IDE directly to allow this. You should give a 👍 in the feature request: https://github.com/rstudio/rstudio/issues/2444

However, this can easily be done with extension feature that are RStudio Addin. Current workaround is using remedy for this https://thinkr-open.github.io/remedy/#chunk

You can map that to a RStudio shortcut for ease of use.

It would also be great to have different pre-made chunks for R and SQL, for example, since I use them both.

Not sure to understand what you mean here. Juts in case it is related, know you can create some custom snippets with pre-filled chunk option that suits you: https://rstudio.github.io/rstudio-extensions/rstudio_snippets.html

Anyway, this is not directly a rmarkdown releated feature, so I'll close this as solutions exists.

Hope it helps.

jcpayne commented 2 years ago

Thanks, brilliant! I love remedy's ability to turn head(df) into a table, too.

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.