在 Rmarkdown 中为 Word 文档循环使用粗体文本 [英] Using bold text in a loop for a Word document in Rmarkdown
本文介绍了在 Rmarkdown 中为 Word 文档循环使用粗体文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Rmarkdown 的新手.我有一个循环,从中我为每次迭代提取一组结果.这可以.但是,我无法将文本打印为粗体.下面是一些示例代码:
I'm new to using Rmarkdown. I have a loop from which I extract a set of results for each iteration. This is fine. However, I am unable to get the text to print as bold. Here is some example code:
```{r echo=FALSE}
x <- data.frame(var1 = c(1,0.99,0.98,0.97,0.95),
var2 = c(1,0.995,0.99,0.98,0.97),
var3 = c(1,0.98,0.96,0.94,0.90)
)
year <- 1980:2010
# Do stuff across the loop:
for(j in 1:nrow(x)){
temp_var1 <- constant1 * var1[j] * var2[j] * var3[j]
temp_var2 <- constant2 * var1[j] * var2[j] * var3[j]
q025 <- round(sapply(temp_var1[, ], quantile, probs=0.025))
q975 <- round(sapply(temp_var2[, ], quantile, probs=0.975))
proj <- as.data.frame(cbind(year, q025, q975))
row.names(proj) <- NULL
# Print stuff:
**print(x[j,])**
print(proj)
cat('\n\n\n\n')
} # close j loop
```
感谢您的帮助.
推荐答案
我不太确定您想用 for 循环代码做什么,但您可以将此简短的 Rmarkdown 代码片段复制到您自己的新 Rmarkdown 文档中进行渲染代码块中的粗体文本:
I'm not really sure what you want to do with the for-loop code but you can copy this short Rmarkdown snippet to your own new Rmarkdown document to render bold text from within a code chunk:
## Display some bold text from inside a chunk
```{r results='asis'}
cat("I am a normal statement")
cat("**some bold text**")
```
## Bold text with a for loop
```{r results='asis'}
for(i in 1:5){
cat("Number: **", i, "**\n\n", sep = "")
}
```
这篇关于在 Rmarkdown 中为 Word 文档循环使用粗体文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文