首页 > 解决方案 > 在R中的while循环内打印绘图

问题描述

在 R 工作室中,我无法打印 while 循环的每次迭代。

while(i < 10){
     print(plot(x, c(U[nx], U, U[1])))
     i = i + 1
     Sys.sleep(0.01)
     flush.console()
}

无论是否使用 flush.console(),都不会显示任何内容,但它会在循环之外显示一个绘图。

标签: rplotwhile-loop

解决方案


也许只是使用“for”循环。像这样的东西应该工作......

for(i in 1:10){
  print('hello')
  flush.console()
  i = i + 1
}

推荐阅读