简体   繁体   English

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

[英]R: Error in fBody[[i]] while running debugSource

I have an R script with about 1400 lines.我有一个大约 1400 行的 R 脚本。 I recently started to get the following error message.我最近开始收到以下错误消息。 I am able to run the script by highlighting and using ctrl-R, but I can't run the script in debug mode.我可以通过突出显示和使用 ctrl-R 来运行脚本,但我无法在调试模式下运行脚本。 Any suggestions on how to locate the error?关于如何定位错误的任何建议?

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

The error may be related to the following lines, since these lines are associated with option 10: eval(expr,p).该错误可能与以下几行有关,因为这些行与选项 10 相关联:eval(expr,p)。

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

I also had this problem.我也有这个问题。 It was caused by invalid breakpoints: This happens when you set a breakpoint, and then modify the code moving the breakpoint to a comment or a blank line for example.这是由无效断点引起的:例如,当您设置断点,然后修改代码将断点移动到注释或空行时,就会发生这种情况。

Just clear all breakpoints and re-Source.只需清除所有断点并重新启动。

It's an R studio glitch, not a bug in your code.这是 R 工作室的故障,而不是代码中的错误。 I resolved it by closing my R Studio project (without saving the project workspace) and then reopening it.我通过关闭我的 R Studio 项目(不保存项目工作区)然后重新打开它来解决它。

Disclaimer: I am a complete newbie to R.免责声明:我是 R 的完全新手。

I was debugging a code that I received, in Rstudio.我正在 Rstudio 中调试收到的代码。 I got the same error.我得到了同样的错误。 I cleaned the environment.我打扫了环境。 I commented all lines but the first, and gradually uncommented larger portions of the code, until I was left with the original code.我注释了除第一行之外的所有行,并逐渐取消注释大部分代码,直到留下原始代码。 The error never popped.错误从未出现。

This happened to me with two different scripts.这发生在我身上,有两个不同的脚本。

So, I do not know the reason for the error, but you may have a workaround for it.所以,我不知道错误的原因,但您可能有解决方法。

I've had this two times.我有过两次这种情况。

The other time restarting RStudio fixed it.另一次重新启动 RStudio 修复了它。

The other time it was caused by for some reason a breakpoint having become assigned to an empty line, where it seems that it's not possible to place a breakpoint.另一次是由于某种原因断点被分配到一个空行,在那里似乎不可能放置断点。 Seems like some glitch that may occur sometimes.似乎有时可能会出现一些故障。 In this case what helped was removing the offending breakpoints.在这种情况下,有帮助的是删除有问题的断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM