In my documents in r
parts I use long codes like:
```{r}
output <- "very long query for example url to some website............................................."
output
```
Is there any way not to make R wrap the code automatically, let's say after 60 characters? I tried tidy=TRUE, tidy.opts=list(width.cutoff=60)
option but it doesn't work.
And I want the same with output, because the output of my query is some text. I want to display the whole content in many lines, not just the begining in one line. How can I do it?
I had this same issue until I realized that one needs to install the R package formatR
.
Once you install and load this package, use
tidy=TRUE, tidy.opts=list(width.cutoff=60)
in your chunk, or use the following line of code to set it globally:
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60), tidy = TRUE)
Things have changed since 2015, but FWIW given that you are now using rmarkdown_1.8
and knitr_1.20
:
if you are looking for a pdf
output, what you can do is
\n
will be added
(in which case you may benefit from using two different code chunks: one for displaying the code another for the outputs);results
to 'asis'
so the output is handled as if it were a regular piece of text, in which case you can also use paste()
or paste0()
to use latex tags to tweak how the text is displayed. So:
1- display the code
{r, eval = F}
output <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
output
2- get the output
{r, results = 'asis', echo = F}
output <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
output
Hope this could help.
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