cheetahfly 发表于 2018-10-11 22:38 
simple_fun = 1L)
paste(paste0("X", seq(x)), collapse = " + ")
}
谢谢大神!我想请教一下中间这部分语句 stopifnot(is.integer(x) && x >= 1L) 是什么意思呢?如果加入了这段语句R会报错,不加入就不会。。。
> simple_fun <- function(x) {
+ stopifnot(is.integer(x) && x >= 1L)
+ paste(paste0("X", seq(x)), collapse = " + ")
+ }
>
> x <- 10
> simple_fun(x)
Error in simple_fun(x) : is.integer(x) && x >= 1L is not TRUE