我正在研究一个R包,我需要一些帮助来编写R测试函数,这些函数用于检查是否在C端代码上抛出正确的警告然后在R端捕获.让我给你一些关于我正在做的工作的背景:
到目前为止,我写了类似的东西:
counter <- 0
tryCatch({
function_im_testing()
}, warning = function(war) {
# Check if warning is as expected and if so increment counter
if(toString(war)=="The warning I'm expecting/testing for"){
print(toString(war))
counter <- counter + 1
}
}, error = function(err) {
print(toString(err))
}, finally = {
print("Leaving tryCatch")
})
# Stop if the 3 warnings we expected aren't present
stopifnot(counter == 3)
Run Code Online (Sandbox Code Playgroud)这是我正在使用的方法,到目前为止,我甚至无法通过尝试获取toString(war)和"警告我期望/测试"来获得if语句.事情.除此之外,这种方法非常草率和不可靠,这使我相信有更好的方法.那么,有没有更好的方法来做到这一点?
从MySQL表加载数据时,通常会出现以下警告:
unrecognized MySQL field type 7 in column 26 imported as character
Unsigned INTEGER in col 3 imported as numeric
Run Code Online (Sandbox Code Playgroud)
如何正确地将数据库表加载到数据帧中,以便不显示这些警告?
我看到该函数RMySQL::dbDataType()可以“确定S对象的SQL数据类型”。有没有办法告诉它哪种MySQL数据类型与数据帧中的哪种矢量类型相匹配?
我有一个源文件(在knitr中),其中包含使用特定字体系列的图形。我想禁止显示警告消息
在grid.Call(L_textBounds,as.graphicsAnnot(x $ label),...:Windows字体数据库中找不到字体系列
library(ggplot2)
ggplot(mtcars, aes(mpg, cyl, label = gear)) +
geom_text(family = "helvet")
Run Code Online (Sandbox Code Playgroud)
我知道我可以禁止脚本中的所有警告消息options(warn = -1),并且知道如何使用suppressWarnings。我也可以在中包围一个特定的块tryCatch。
有没有办法只禁止整个文件中的grid.Call上述警告?