You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R Notebook行内代码块中换行?导出Word文档

在R Notebook行内代码块实现换行并导出为Word文档

问题描述

需求为在R Notebook的行内代码块中实现换行,且渲染后可导出为Word文档,但尝试以下多种方法均无效:

---
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")
## 解决方案(基于shafee和gaut的回答)
使用三重转义的换行符(`\\n`)即可实现需求,示例代码如下:

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

Text `r "Simple \\n is \\n better"`

内容的提问来源于stack exchange,提问作者Samuel Allain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 11:16:01