【问题标题】:Why the behaviour of tryCatch doesn't coincide in Rstudio and Jupyter with R Kernel?为什么 tryCatch 的行为在 Rstudio 和 Jupyter 中与 R 内核不一致?
【发布时间】:2019-11-14 11:12:44
【问题描述】:

在 R 或 Rstudio 中运行以下代码 sn-p 提供以下结果

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 不会用 tryCatch() 包装 t(data)

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]])

如果有人有想法就好了?

谢谢 卡特琳娜

【问题讨论】:

    标签: r jupyter-notebook try-catch jupyter-irkernel


    【解决方案1】:

    这肯定是一个 IRkernel 错误。

    https://github.com/IRkernel/IRkernel/issues/646

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2022-10-05
      • 2011-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      相关资源
      最近更新 更多