简体   繁体   English

在 R Markdown 文档中格式化 R 输出

[英]Formatting R output in an R Markdown documents

I have a code that generates a text output.我有一个生成文本输出的代码。 For example:例如:

pick <- sample(c("Alex", "Greta", "Zoe"), 1)

Is there a way of formatting the result in an R Markdown documents.有没有办法在 R Markdown 文档中格式化结果。

Say something like this if I wanted it to appear in bold on the report.如果我希望它在报告中以粗体显示,请说这样的话。

**pick**

You can execute any R command in-text in an rmarkdown document without embedding it inside a chunk by placing it within ticks prefaced by the letter r (see below).您可以在 rmarkdown 文档中以文本形式执行任何 R 命令,而无需将其嵌入块中,方法是将其放置在以字母r开头的刻度中(见下文)。 You can then surround this r code with latex code, in this \\bf{foo} for bold font, bookmarked by $ .然后你可以用乳胶代码包围这个 r 代码,在这个\\bf{foo}为粗体字体,由$标记。 Try placing尝试放置

The OP's chosen name is $\bf{`r sample(c("Alex", "Greta", "Zoe"), 1)`}$

inside an rmarkdown document.在 rmarkdown 文档中。 Or you could place the function in a chunk and then call it outside the chunk, anywhere in subsequent text, like this或者你可以将函数放在一个块中,然后在块外调用它,在后续文本中的任何地方,像这样

The OP's chosen name is $\bf{`r pick`}$

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM