Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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 获取在应用程序中调用的函数的堆栈跟踪_R_Shiny - Fatal编程技术网

R 获取在应用程序中调用的函数的堆栈跟踪

R 获取在应用程序中调用的函数的堆栈跟踪,r,shiny,R,Shiny,当一个包含许多多层调用的长而复杂的函数抛出错误时,如果看不到堆栈跟踪,就很难理解错误。但是,当一个闪亮的应用程序调用这样一个函数来处理其输入时,堆栈跟踪似乎只显示应用程序中发生的事情,而不显示它调用的函数中发生的事情。这是一个reprex,基于Hadley Wickham著作第6.3.1节中的代码: 因此,我可以看到错误发生在h()中,但不是由g()表示的一系列调用导致我进入h()。使用包含命令的文件run.R运行应用程序时 runApp('T://someNetworkDirectory//A

当一个包含许多多层调用的长而复杂的函数抛出错误时,如果看不到堆栈跟踪,就很难理解错误。但是,当一个闪亮的应用程序调用这样一个函数来处理其输入时,堆栈跟踪似乎只显示应用程序中发生的事情,而不显示它调用的函数中发生的事情。这是一个reprex,基于Hadley Wickham著作第6.3.1节中的代码:

因此,我可以看到错误发生在h()中,但不是由g()表示的一系列调用导致我进入h()。使用包含命令的文件run.R运行应用程序时

runApp('T://someNetworkDirectory//App-1', launch.browser=TRUE)
由于App-1包含一个文件App.R,细节有所不同,但是 结果是一样的回溯()仅显示到
应用程序开始运行的点。捕获堆栈跟踪(显示应用程序调用的函数如何出错)的最佳方法是什么?

诀窍是保存您的闪亮应用程序,然后使用
runApp(“path\u to\u app\u dir”)
(如本章末尾所述)启动应用程序。然后我得到以下堆栈跟踪:

Warning: Error in h: Value of 3 not allowed
  171: stop
  170: h [C:\path\Shiny\shiny_example/app.R#20]
  169: g [C:\path\Shiny\shiny_example/app.R#13]
  168: f [C:\path\Shiny\shiny_example/app.R#6]
  167: renderPlot [C:\path\Shiny\shiny_example/app.R#31]
  165: func
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$plot
    1: runApp

诀窍是保存您的闪亮应用程序,然后使用
runApp(“path\u to\u app\u dir”)
启动该应用程序(如本章末尾所述)。然后我得到以下堆栈跟踪:

Warning: Error in h: Value of 3 not allowed
  171: stop
  170: h [C:\path\Shiny\shiny_example/app.R#20]
  169: g [C:\path\Shiny\shiny_example/app.R#13]
  168: f [C:\path\Shiny\shiny_example/app.R#6]
  167: renderPlot [C:\path\Shiny\shiny_example/app.R#31]
  165: func
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$plot
    1: runApp

这就是我在屏幕上看到的。然而,
traceback()
显示了,更重要的是,出于我的目的,
错误报告就是我在屏幕上看到的。然而,
traceback()
显示了,更重要的是,出于我的目的,
bugReport
Warning: Error in h: Value of 3 not allowed
  171: stop
  170: h [C:\path\Shiny\shiny_example/app.R#20]
  169: g [C:\path\Shiny\shiny_example/app.R#13]
  168: f [C:\path\Shiny\shiny_example/app.R#6]
  167: renderPlot [C:\path\Shiny\shiny_example/app.R#31]
  165: func
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$plot
    1: runApp
 Error in h(y_new) : Value of 3 not allowed 
4.
stop("Value of 3 not allowed") 
3.
h(y_new) 
2.
g(x_new) 
1.
f(3)