在 markdown 中循环打印 r 评论

Print r comments in a loop in markdown

我正在使用 for 循环生成模型结果并在 r markdown 中打印它们。为了保持整洁,最好在打印模型结果之前打印注释。

有没有办法在 R 中的主题标签后面打印评论文本?

例如

for(i in c(1:10)){
#this is the number
print(i)}

#this is the number
print(1)
#this is the number
print(2)
#this is the number
print(3)
#this is the number
print(4)

我认为无需尝试打印评论。您可以在循环中使用 cat("this is the number", i, "\n")。例如:

for (i in 1:5)
  cat("this is number", i, "\n")

this is number 1 
this is number 2 
this is number 3 
this is number 4 
this is number 5 

message 而不是 cat 往往更受欢迎,因为我们可以使用 suppressMessages 或更好的 message=FALSE in knitr/rmarkdown 轻松摆脱它们] chunks.