Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:运行debugSource时fBody[[i]]中出错_R_Debugging_Error Handling - Fatal编程技术网

R:运行debugSource时fBody[[i]]中出错

R:运行debugSource时fBody[[i]]中出错,r,debugging,error-handling,R,Debugging,Error Handling,我有一个大约1400行的R脚本。我最近开始收到以下错误消息。我可以通过高亮显示并使用ctrl-R来运行脚本,但无法在调试模式下运行脚本。关于如何定位错误有什么建议吗 > debugSource('~/working/R/h60_maintenance/do_mega_analysis.R') Error in fBody[[i]] : subscript out of bounds > options(error=recover) > debugSource('~/workin

我有一个大约1400行的R脚本。我最近开始收到以下错误消息。我可以通过高亮显示并使用ctrl-R来运行脚本,但无法在调试模式下运行脚本。关于如何定位错误有什么建议吗

> debugSource('~/working/R/h60_maintenance/do_mega_analysis.R')
Error in fBody[[i]] : subscript out of bounds
> options(error=recover)
> debugSource('~/working/R/h60_maintenance/do_mega_analysis.R')
Error in fBody[[i]] : subscript out of bounds
Enter a frame number, or 0 to exit   
 1: debugSource("~/working/R/h60_maintenance/do_mega_analysis.R")
 2: (function (fileName, encoding, breaklines) 
{
    env <- new.env(parent = emptyenv())
    env$fun <- 
 3: suppressWarnings(.rs.setFunctionBreakpoints("fun", env, lapply(steps, function(step) {
    step$at
}
 4: withCallingHandlers(expr, warning = function(w) invokeRestart("muffleWarning"))
 5: .rs.setFunctionBreakpoints("fun", env, lapply(steps, function(step) {
    step$at
}))
 6: suppressMessages(trace(what = functionName, where = envir, at = lapply(strsplit(as.character(steps
 7: withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage"))
 8: trace(what = functionName, where = envir, at = lapply(strsplit(as.character(steps), ","), as.numer
 9: eval.parent(call)
10: eval(expr, p)
11: eval(expr, envir, enclos)
12: methods::.TraceWithMethods(what = functionName, where = <environment>, at = lapply(strsplit(as.cha
13: new(traceClass, def = if (doEdit) def else original, tracer = tracer, exit = exit, at = at, print 
14: initialize(value, ...)
15: initialize(value, ...)
16: .initTraceable(.Object, ...)
17: .makeTracedFunction(def, tracer, exit, at, print, doEdit)
>debugSource(“~/working/R/h60\u maintenance/do\u mega\u analysis.R”)
fBody[[i]]中出错:下标超出范围
>选项(错误=恢复)
>debugSource(“~/working/R/h60\u maintenance/do\u mega\u analysis.R”)
fBody[[i]]中出错:下标超出范围
输入帧编号,或输入0退出
1:debugSource(“~/working/R/h60\u maintenance/do\u mega\u analysis.R”)
2:(函数(文件名、编码、特征线)
{

免责声明:我对R完全是个新手

我在Rstudio中调试我收到的一个代码。我得到了同样的错误。 我清理了环境。我注释了除第一行之外的所有行,并逐渐取消了大部分代码的注释,直到保留了原始代码。错误从未出现

这发生在我身上,有两种不同的脚本


因此,我不知道错误的原因,但您可能有解决方法。

这是R studio的小故障,而不是代码中的错误。我通过关闭R studio项目(不保存项目工作区)解决了此问题然后重新打开它。

我也遇到了这个问题。它是由无效断点引起的:当设置断点,然后修改代码,例如将断点移动到注释或空行时,就会发生这种情况


只需清除所有断点并重新源代码。

我已经做过两次了

另一次重启RStudio修复了它


另一次,由于某种原因,断点被分配到空行,在空行中似乎不可能放置断点。似乎有时会出现一些小故障。在这种情况下,删除有问题的断点是有帮助的。

在RStudio中查找错误的一种方法是使用shift-ctrl-c到c删除代码块以隔离错误源。我想知道是否可以修改debugSource的源代码以打印检测到错误的行号。我认为RStudio通常也会在错误消息中显示行号。如果查找导致错误的行号时遇到问题,可以使用my(新)包
tryCatchLog
()它丰富了行号,甚至可以将转储写入磁盘以允许对错误进行事后分析。这是一个比IMO接受的更好的答案——我宁愿重置断点也不愿丢失会话。这对我来说是有效的。我同意这应该是可接受的答案。这对Shiny也有效。可接受的答案没有清除错误但是这确实发生了。非常感谢。哇,现在是2020年,在
调试源代码(…)
过程中仍然会弹出这条消息,有点烦人
imds_rollup <- imds_detail_dt[,{
  ## if there's just one row in the group of ID's, return nothing
  list(
    count_every_fault = .N,
    max_ci_value = max(CI.Value),
    max_rotor_turn_time_air_sec = max(Rotor.Turn.Time...In.Air..s.),
    max_rotor_turn_time_ground_sec = max(Rotor.Turn.Time...On.Ground..s.)
  )}, by = c("BUNO","fileEventIndex")]
setkeyv(imds_rollup,c("BUNO","fileEventIndex"))
imds_rollup$max_ci_value <- NULL   # max_ci_value has all NA