gpt4 book ai didi

r - 警告消息不断出现在 RStudio 笔记本中,与警告无关

转载 作者:行者123 更新时间:2023-12-03 11:02:54 30 4
gpt4 key购买 nike

我开始使用 RStudio 笔记本,并且我仍在尝试了解其中的一些工作原理。
我不明白为什么在执行与消息完全无关的代码时会保留并出现某些生成的警告消息。例如,我有一个包含多个块的文档,其中最后一个会产生警告

> warnings()
Warning messages:
1: Unknown or uninitialised column: 'perc.goal.met.period'.
2: Unknown or uninitialised column: 'perc.goal.met.period'.
3: Unknown or uninitialised column: 'perc.goal.met.period'.
4: Unknown or uninitialised column: 'perc.goal.met.period'.
5: Unknown or uninitialised column: 'perc.goal.met.period'.
6: Unknown or uninitialised column: 'perc.goal.met.period'.
7: Unknown or uninitialised column: 'perc.goal.met.period'.
8: Unknown or uninitialised column: 'perc.goal.met.period'.
9: Unknown or uninitialised column: 'perc.goal.met.period'.
10: Unknown or uninitialised column: 'perc.goal.met.period'.
11: Unknown or uninitialised column: 'perc.goal.met.period'.
12: Unknown or uninitialised column: 'perc.goal.met.period'.
13: Unknown or uninitialised column: 'perc.goal.met.period'.
14: Unknown or uninitialised column: 'perc.goal.met.period'.
15: Unknown or uninitialised column: 'perc.goal.met.period'.
16: Unknown or uninitialised column: 'perc.goal.met.period'.
17: Unknown or uninitialised column: 'perc.goal.met.period'.
18: Unknown or uninitialised column: 'perc.goal.met.period'.
19: Unknown or uninitialised column: 'perc.goal.met.period'.
20: Unknown or uninitialised column: 'perc.goal.met.period'.
21: Unknown or uninitialised column: 'perc.goal.met.period'.
22: Unknown or uninitialised column: 'perc.goal.met.period'.
23: Unknown or uninitialised column: 'perc.goal.met.period'.
24: Unknown or uninitialised column: 'perc.goal.met.period'.
25: Unknown or uninitialised column: 'perc.goal.met.period'.
26: Unknown or uninitialised column: 'perc.goal.met.period'.
27: Unknown or uninitialised column: 'perc.goal.met.period'.
28: Unknown or uninitialised column: 'perc.goal.met.period'.
29: Unknown or uninitialised column: 'perc.goal.met.period'.
30: Unknown or uninitialised column: 'perc.goal.met.period'.
There were 30 warnings (use warnings() to see them)

我对那个警告没意见。但后来,我想我会在第一个块(我加载它们的地方)加载一个额外的库。运行该块后,我得到:
```{r echo=F, message=F, warnings=F, include=F}
# Load libraries
library(rgdal)
library(raster)
library(openxlsx)
library(tidyverse)
library(dplyr)
library(magrittr)
library(ggplot2)
library(rasterVis)
```
There were 30 warnings (use warnings() to see them)

如果我看到警告,它们就是我之前打印的警告。
为什么我会在这里看到他们?我也在其他与变量无关的块中看到了这一点 perc.goal.met.period .如果我看到警告,它们会停止出现一段时间,但在我仍然无法预料的时刻,它们最终会在某个时候重新出现。

这种行为有合乎逻辑的解释吗?非常感谢你的帮助!

最佳答案

您将看到警告消息,直到您将其清除。运行 warnings() 函数不会这样做。
要清除警告,您可以执行以下命令:

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

最好的方法是修复你的代码,这样就不会产生警告。处理它的一种方法是使用 tryCatch()在 R。

您还可以使用 supressWarnings() 禁用所有警告。功能,但不建议这样做,因为这会阻止您看到其中的任何一个。

关于r - 警告消息不断出现在 RStudio 笔记本中,与警告无关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43613986/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com