R 语言 stop(),message(),warning() 均能完成信息提示功能,传入需要的提示的字符串信息。
Warning Messages
Description
Generates a warning message that corresponds to its argument(s) and (optionally) the expression or function from which it was called.
Usage
warning(..., call. = TRUE, immediate. = FALSE, noBreaks. = FALSE, domain = NULL) suppressWarnings(expr, classes = "warning")
### 1. message,warning ,stop 函数
demo <- function(){
for (i in 1:5) {
if (i == 1){
message("开始")
}
if (i==4){
warning("快结束了")
}
if (i==5){
stop("结束了")
}
print (i)
Sys.sleep(1)
}
}
demo()
### 2. suppressWarnings/suppressMessages 函数
# 不输出warning/Messages信息
suppressWarnings(demo())
suppressMessages(demo())
### 3. 关闭打开全局警告信息
# 注意,全局关闭警告信息可能不是一个好主意.
options(warn=-1)
# 要重新打开警告,请使用
options(warn=0)
oldw <- getOption("warn")
options(warn = -1)
# [your code]
options(warn = oldw)