问题
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
```
Thanks for any help.
回答1:
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 = "")
}
```
来源:https://stackoverflow.com/questions/47416858/using-bold-text-in-a-loop-for-a-word-document-in-rmarkdown