Warning messages keep appearing in RStudio notebooks in chunks unrelated to the warnings

后端 未结 2 1886
旧巷少年郎
旧巷少年郎 2021-02-05 04:27

I am starting to use RStudio notebooks, and I am still trying to understand how some of the things work. I do not understand why some produced warning messages are kept and appe

相关标签:
2条回答
  • 2021-02-05 05:14

    My experience is that this occurs in RStudio while my code still has the error, even if this is not run (for example, when I leave some wrong code to be revised later). When I delete, change or convert into comments the relevant lines, this behavior ends. I guess that this is caused by the RStudio interpreter. It would be interesting to know if people using base R have the same problem.

    0 讨论(0)
  • 2021-02-05 05:22

    You will see warning messages until you clear them out. Running warnings() function does not do that. To clear warnings you can execute the following command:

    assign("last.warning", NULL, envir = baseenv())
    

    The best approach though is to fix your code so the warnings are not produced. One way to deal with it is to use tryCatch() in R.

    You can also disable all warnings by using supressWarnings() function, but this is not recommended since this will prevent you to see any of them.

    0 讨论(0)
提交回复
热议问题