关于R包开发,当函数应该返回错误信息或警告时,最好使用哪种方法?:
cat()
print()
message()
error()
warning()
例如,在这个函数中,如果a或b不是数字,应该使用哪一个来返回错误信息。
function_sum_two_nums <- function(a, b){
## Check if the a and b are numbers
if(is.numeric(a) & is.numeric(b)){
return(a+b)
} else{
print/cat/message/error/warning('a or b are not numbers')
}
}
stop
而不是error
。 - shadowtalker