在 R 或 Rstudio 中运行以下代码片段提供以下结果
data <- NULL
data <- tryCatch(
data.frame(t(data), row.names = NULL),
error=function(e){
warning(e)
warning("NAs returned")
NA
}
)
> data
[1] NA
带有 R 内核的 jupyter notebook 不t(data)
包含tryCatch()
data <- NULL
data <- tryCatch(
data.frame(t(data), row.names = NULL),
error=function(e){
warning(e)
warning("NAs returned")
NA
}
)
Error in t.default(data): argument is not a matrix
Traceback:
1. tryCatch(data.frame(t(data), row.names = NULL), error = function(e) {
. warning(e)
. warning("NAs returned")
. NA
. })
2. tryCatchList(expr, classes, parentenv, handlers)
3. tryCatchOne(expr, names, parentenv, handlers[[1L]])
4. value[[3L]](cond)
5. warning(e) # at line 6 of file <text>
6. withRestarts({
. .Internal(.signalCondition(cond, message, call))
. .Internal(.dfltWarn(message, call))
. }, muffleWarning = function() NULL)
7. withOneRestart(expr, restarts[[1L]])
如果有人有想法会很棒吗?
谢谢卡特琳娜