简体   繁体   English

当 output 是来自代码块的文本时,如何在 Rmarkdown 中的每个注释之间添加一个空格?

[英]How do I add a space between each comment in Rmarkdown when the output is text from a code chunk?

I have some data which includes comments in an excel file.我有一些数据,其中包括 excel 文件中的注释。 After importing into R, I would like to add the comments at the bottom of some analysis in RMarkdown .导入 R 后,我想在RMarkdown的一些分析的底部添加注释。 I passed the column to a code chunk and it knits the output.我将该列传递给一个代码块,它编织了 output。 Here is a screenshot -这是一个屏幕截图 - 在此处输入图像描述

As you can see, it's a bit chunked up.如您所见,它有点块状。 Is there a way for me to有没有办法让我

  1. Add a space between each number line在每个数字行之间添加一个空格
  2. Possibly replace the numbers with bullet points可能用项目符号替换数字
  3. Fix the text cutting off.修复文本截断。 See highlighted.请参阅突出显示。 The word is "of", but it cuts the "f" to a new line.这个词是“of”,但它把“f”切到了一个新的行。 There are a lot of lines like this.有很多这样的行。 Is there any way to fix that too?有没有办法解决这个问题?

I know how to add spacing when type n the text, however since this is the output of a code chunk, I have no idea how to add the spacing.我知道在输入文本时如何添加间距,但是由于这是代码块的 output,我不知道如何添加间距。 I have looked online, however, all solutions show how to add spacing when you type in the text as opposed to text from a code chunk.但是,我在网上查看过,所有解决方案都显示了如何在输入文本时添加间距,而不是代码块中的文本。

Assuming you don't have any special functions or settings affecting the output from your chunk, generating a list from your text can be achieved in the following way假设您没有任何特殊功能或设置影响您的块中的 output,则可以通过以下方式从您的文本生成列表

---
output: pdf_document
---


```{r, results='asis', echo=FALSE}
textTest <- c("I have never seen our strategic plan, if we have one", 
              "Yes, to corporate partners and high net worth, I have not 
              heard about an effort to build relationships with leaders of 
              color, labor leaders, faith leaders, etc.")

cat(paste0("- ", textTest, "\n"))
```

results='asis' is needed to get the correct text output from the chunk.需要results='asis'从块中获取正确的文本 output。 As for the line cat(paste0("- ", textTest, "\n")) :至于线cat(paste0("- ", textTest, "\n"))

  • "- " generates the list structure. "- "生成列表结构。 The lagging space is necessary if using paste0() .如果使用paste0() ,则需要滞后空间。 Can be omitted if using paste() .如果使用paste()可以省略。
  • "\n" generates new lines. "\n"生成新行。 Use double ( "\n\n" ) to get more space between list entries.使用 double ( "\n\n" ) 在列表条目之间获得更多空间。

Consequently, the output in R will look like this因此,R 中的 output 将如下所示

- I have never seen our strategic plan, if we have one
 - Yes, to corporate partners and high net worth, I have not 
              heard about an effort to build relationships with leaders of 
              color, labor leaders, faith leaders, etc.

Which will be knitted into这将被编织成

  • I have never seen our strategic plan, if we have one我从未见过我们的战略计划,如果我们有的话
  • Yes, to corporate partners and high net worth, I have not heard about an effort to build relationships with leaders of color, labor leaders, faith leaders, etc.是的,对于企业合作伙伴和高净值人士来说,我还没有听说过与有色人种领袖、劳工领袖、信仰领袖等建立关系的努力。

for pdf, word and html对于 pdf、字和 html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从代码块中的数据框中获取数字(或文本)到 RMarkdown html 输出中的文本? - How do I get a number (or text) from a data frame in a code chunk in to text in RMarkdown html output? 如何在控制台中打印 RMarkdown 块代码 output? - How to print RMarkdown chunk code output in Console? 在已编译的pdf中的文档文本和knitr代码块之间添加空间 - add space between document text and knitr code chunk in compiled pdf Rmarkdown:如何显示chunk的部分输出? - Rmarkdown: how to show partial output from chunk? 使用RMarkdown和knitr时可以更改MSWord Normal样式而不影响R代码块输出 - Can I change MSWord Normal style when using RMarkdown and knitr without affecting R code chunk output 防止knitr / Rmarkdown与代码交错块输出 - prevent knitr/Rmarkdown from interleaving chunk output with code 如何在Rmarkdown演示(slidy)中回显代码之前显示块输出? - How to display chunk output before echoing code in Rmarkdown presentation (slidy)? 如何在 Rmarkdown 中参数化内联代码、文本以及 R 代码块 - How to parameterize the inline code, text, together with R code chunk in Rmarkdown 如何在 rmarkdown 代码块的字符串中呈现 Z25F7E525B5C0641E1EB1FB3BDEBEB15B5Z 代码? - How to render latex code in a string from an rmarkdown code chunk? 在RMarkdown的输出中显示代码块名称 - Showing code chunk name in output in RMarkdown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM