3

How to make newlines in inline chunks ? Rendering a word document

---
title: "R Notebook"
output: word_document
---

Cat `r cat("not \n working")`

writeLines `r writeLines("not \n working")`

print `r print("not \n working")`

capture.output + cat `r capture.output(cat("not \n working"))`

```{r results='asis'}
cat("not \n working")
```

EDIT Solution based on shafee and gaut's answers uses triple escape character \

---
title: "R Notebook"
output: word_document
---

Text `r "Simple \\\n is \\\n better"`
Samuel Allain
  • 344
  • 1
  • 7

2 Answers2

3

You can use combine_words from {knitr} to do this in inline code.

`r knitr::combine_words(c("it is", "working"), sep = "\\\n", and = "")`
shafee
  • 15,566
  • 3
  • 19
  • 47
2

We can use:

```{r results='asis'}

cat(paste("it is", "\\\n", "working"))

```
gaut
  • 5,771
  • 1
  • 14
  • 45