if (length(x)) "not empty" else "empty" #> [1] "empty" if (NaN) "not empty" else "empty" #> Error in if (NaN) "not empty" else "empty": argument is not interpretable as logical 如果判断语句是长度大于1的逻辑向量,程序会抛出警示: if (c(TRUE, FALSE)) 1 #> Warning in if (...
statements return(object) } arg1和arg1等是输入的参数,object是该函数返回的结果 实例 # 自己编写一个转置矩阵的函数 # 该函数功能和R中的函数t()一致 mytrans <- function(x) { ##判断输入数据x是否是一个矩阵 ##是矩阵就继续运行,否则就报警 if (!is.matrix(x)) { warning("argument is not a mat...
4## Warninginstri_split_regex(string, pattern, n = n, simplify = simplify, : 5## argument isnotan atomic vector; coercing 有了这st和wt这两个表格,现在我们要愉快地提取关键句子。 1textrank_sentences(data = st,terminology = wt) %>% 2summary(n =1)#n代表要top多少的关键句子 3## [1]...
is.logical(x)) { warning("argument is not numeric or logical: returning NA") return(...
## Warning in mean.default(gender): argument is not numeric or logical: returning ## NA ## [1] NA 1. 2. 3. 4. 5. 6. 同样,尽管在技术上是可行的,但对定量连续变量画条形图是没有意义的,因为在大多数情况下,每个值的频率都是1:
For a Mac OS X or Windows binary install, no locking is done by default. Setting argumentlocktoTRUE(it defaults to the value ofgetOption("install.lock", FALSE)) will use per-directory locking as described for source installs: if the value is"pkglock"per-package locking will be used. ...
function (x, trim = 0, na.rm = FALSE, ...){ if (!is.numeric(x) && !is.complex(x) && !is.logical(x)) { warning("argument is not numeric or logical: returning NA") return(as.numeric(NA)) } if (na.rm) x <- x[!is.na(x)] trim <- trim[1] n <- length(x) if (...
mytrans<-function(x){##判断输入数据x是否是一个矩阵 ##是矩阵就继续运行,否则就报警if(!is.matrix(x)){warning("argument is not a matrix: returningNA")return(NA_real_)}##新建一个空矩阵y用于储存后续的计算结果 ## 将行和列互换就可求出转置矩阵 ...
f2 <-function(x) {try(log(x))10}f2("a") #> Error inlog(x) : non-numeric argument to mathematical function #> [1]10 我们可以使用try(…, silent=TRUE)函数,隐藏错误异常信息。 如果大段代码中有错误,想忽略错误,可以采用try(),但大段代码需放在{ }中: ...
They rely on a special argument: ... (pronounced dot-dot-dot). This special argument captures any number of arguments that aren’t otherwise matched.commas <- function(...) stringr::str_c(..., collapse = ", ") commas(letters[1:10]) #> [1] "a, b, c, d, e, f, g, h, ...