Here is an example code chunk and it's output.
`{r example, message = F}
for (i in 1:5) {
print(i)
}
`
I would like this to render in my output file without the border box, and without the leading ## [1]. Is that possible?
CodePudding user response:
This solution also removes the border box.
- Use the r chunk
commentoption to remove the##character. - Use
cat()instead ofprint()to display the output without the R formatting[1]. You need to specify incat()that you want newlines added. - One method to remove the border box would be to use css. You can use an external css file, or make a dedicated hidden chunk to specify it.
- I noticed the code chunks and output chunks were both specified by the
<pre>tag, with the code chunk being of class.r, and the output chunk being.hljs. These might change with different themes, but this selector worked for me.pre.hljsmight work alternatively as a selector.
- I noticed the code chunks and output chunks were both specified by the
Below is a complete .Rmd file that can be knit to an html document
---
title: example.Rmd
output: html_document
---
```{css, echo = FALSE}
pre:not(.r) {
border: 0px;
}
```
```{r, comment = ""}
for (i in 1:5) {
cat(i, "\n")
}
```
CodePudding user response:
Use the following code
{r example, message = FALSE, comment = ''}
for (i in 1:5) {
cat(i, '\n')
}

