Prevent short comments from packaging in R Markdown / knitr output

Is it possible to get the tidy ed code snippet up, leaving only comments?

Let's say I want to put ASCII art in some comments in a function, I could just set tidy = F , but then the rest of the code snippet is β€œmessy”, as in the next release:

 myfun=function(a,b){ ## ^_^ ## {o,o} ## |)__) ##-----mm----- c=sum(a,b) return(c) } 

If I set tidy = T , then the short comments all wrap together, and I get the following as output:

 myfun = function(a, b) { ## ^_^ {o,o} |)__) -----mm----- c = sum(a, b) return(c) } 

What I would like to see is as follows:

 myfun = function(a, b) { ## ^_^ ## {o,o} ## |)__) ## -----mm----- c = sum(a, b) return(c) } 
+4
source share
1 answer

As stated in the comments, I will answer my question.

If you look at the Yihui documentation for formatR , you will notice that the roxygen comments (which look like this: #' ) will not be wrapped in any way.

So using a piece of code

 ```{r, tidy = T} myfun=function(a,b){ #' ^_^ #' {o,o} #' |)__) #'-----mm----- c=sum(a,b) return(c) } ``` 

will give me the desired result:

 myfun = function(a, b) { #' ^_^ #' {o,o} #' |)__) #'-----mm----- c = sum(a, b) return(c) } 
+6
source

Source: https://habr.com/ru/post/1489522/


All Articles