Keyboard shortcut for inserting roxygen #' comment start
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.
Knitr:spin - how to add text without manually adding #' every line?
In RStudio v 1.1.28, starting a line with #'
causes the next line to start with #'
when I hit enter in a *.R
file on my machine (Ubuntu Linux 16.04LTS).
So as long as you start a text chunk with it, it will continue. But for previously existing R scripts, it looks like you would have to use find -> replace
, or write a function to modify the required file, this worked for me in a very simple test.
comment_replace <- function(in_file, out_file = in_file){
in_text <- scan(file = in_file, what = character(), sep = "\n")
out_text <- gsub("^# ", "#' ", in_text)
cat(out_text, sep = "\n", file = out_file)
}
I would note, that this function does not check for preexisting #'
, you would want to build that in. I modified it so that it shouldn't replace them too much by adding a space in the regular expression.
Remove Hashes in R Output from R Markdown and Knitr
You can include in your chunk options something like
comment=NA # to remove all hashes
or
comment='%' # to use a different character
More help on knitr available from here: http://yihui.name/knitr/options
If you are using R Markdown as you mentioned, your chunk could look like this:
```{r comment=NA}
summary(cars)
```
If you want to change this globally, you can include a chunk in your document:
```{r include=FALSE}
knitr::opts_chunk$set(comment = NA)
```
Related Topics
Using R to Fit a Sigmoidal Curve
Reshaping a Data Frame with More Than One Measure Variable
Format Latitude and Longitude Axis Labels in Ggplot
Clustered Standard Errors in R Using Plm (With Fixed Effects)
Ggplot2 Aes_String() Fails to Handle Names Starting with Numbers or Containing Spaces
How to Speed Up R Packages Installation in Docker
Apply a Function to Each Row in a Data Frame in R
R: Calculating 5 Year Averages in Panel Data
How to Save Output from Ggforce::Facet_Grid_Paginate in Only One PDF
How to Install the R Package Rgl on Ubuntu 9.10, Using R Version 2.12.1
R Ggplot Boxplot: Change Y-Axis Limit
Extract Column Name in Mutate_If Call
Ddply Multiple Quantiles by Group
Can Lapply Not Modify Variables in a Higher Scope
Multiple Filled.Contour Plots in One Graph Using with Par(Mfrow=C())