Question
Within a code chunk in an R Markdown (.Rmd) document how do you parse a string containing new line characters \n
, to display the text on new lines?
Data and example
I would like to parse text <- "this is\nsome\ntext"
to be displayed as:
this is
some
text
Here is an example code chunk with a few attempts (that don't produce the desired output):
```{r, echo=FALSE, results='asis'}
text <- "this is\nsome\ntext" # This is the text I would like displayed
cat(text, sep="\n") # combines all to one line
print(text) # ignores everything after the first \n
text # same as print
```
Additional Information
The text will come from a user input on a shiny app.
e.g ui.R
tags$textarea(name="txt_comment") ## comment box for user input
I then have a download
button that uses a .Rmd
document to render the input:
```{r, echo=FALSE, results='asis'}
input$txt_comment
```
An example of this is here in the R Studio gallery