This question might be over-answered but I could not find one. Basically I am using RStudio and the keyboard shortcut cmd + shift + c for inserting comments. Is there an other combination to insert directly the roxygen tags #'
? Or a way to modify RStudio to tell it to add the '
when I press cmd + shift + c?
Inserting a skeleton - Do this by placing your cursor anywhere in the function you want to document and click Code Tools -> Insert Roxygen Skeleton (default keyboard shortcut Ctrl+Shift+Alt+R ).
Make the shortcut available Now go to „Tools“ > „Modify Keyboard Shortcuts…“ and search for „dashes“. Here you can define the keyboard combination by clicking inside the empty „Shortcut“ field and pressing the desired key-combination on your keyboard. Click „Apply“, and that's it!
You could use an RStudio addin, you'll need a fairly recent version of RStudio. I've just created an RStudio addin that comments/uncomments using roxygen2 tags, i.e. works just like code commenting, but with #'
. The addin is hosted on github.
Just install and attach a convenient keyboard shortcut.
If you are interested in other available addins, see the addinmanager addin.
This isn't exactly what you're looking for. But you can add an ROxygen2 skeleton for a function by placing your cursor inside the function then pressing ctr+alt+shift+R
. Then if you hit enter in the ROxygen2 codeblock it will automatically add the backtick. So an alternate workflow, edit the function, then insert the skeleton and do the documentation that way.
Select text to comment out, tick regex
option and specify:
^(.+)
#' \1
Above means to find all characters (.+)
following beginning of the line ^
and replace them by the #'
and the first captured group \1
.
I find this option the easiest as I use Rstudio in vim mode. To replace text one only need to:
:
keys/^/#'
and hit enter.s/
stands for "substitute", ^
stands for beginning of the line and #'
is the text we are inserting.
This is not a default Rstudio option. Make sure you have Keybindings set to "vim" in RStudio "Global Options"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With