问题
我试图使用新的flow包浏览一个函数,如下所示:
功能定义
library(tibble)
calculate_decc <- function(initial_DV,
initial_frspacing,
standstill_frspacing,
t,
nrows,
LV_acc_mps2,
den){
D_first <- ((initial_DV)^2) / (den * (standstill_frspacing - initial_frspacing)) + LV_acc_mps2[1]
# D_reqd <- existing_decc + D_first
DV <- vector(mode = "double", length = nrows)
DV[1] <- initial_DV
D <- vector(mode = "double", length = nrows)
D[1] <- D_first
Z <- vector(mode = "double", length = nrows)
Z[1] <- initial_frspacing
for (i in 2:nrows) {
DV[i] <- DV[i-1] + ((D[i-1] - LV_acc_mps2[i-1]) * t)
Z[i] <- Z[i-1] - ((DV[i-1] * t) + (0.5 * (D[i-1]-LV_acc_mps2[i-1]) * t^2))
D[i] <- ((DV[i])^2) / (den * (standstill_frspacing - Z[i])) + LV_acc_mps2[i]
}
return(tibble(DV, Z, D))
}使用flow浏览该函数
flow_run(calculate_decc(initial_DV = 25,
initial_frspacing =200,
standstill_frspacing=10,
t=1/60,
nrows=1000,
LV_acc_mps2=vector(mode = "double", length = 1000),
den=2),
, browse = TRUE) 错误:
> flow_run(calculate_decc(initial_DV = 25,
+ initial_frspacing =200,
+ standstill_frspacing=10,
+ t=1/60,
+ nrows=1000,
+ LV_acc_mps2=vector(mode = "double", length = 1000),
+ den=2),
+ , browse = TRUE)
Next block: standard
D_first <- ((initial_DV)^2)/(den * (standstill_frspacing - initial_frspacing)) + ; LV_acc_mps2[1];DV <- vector(mode = "double", length = nrows);DV[1] <- initial_DV;D <- vector(mode = "double", length = nrows);D[1] <- D_first;Z <- vector(mode = "double", length = nrows);Z[1] <- initial_frspacing
flow_browser[1]>
Next block: for
for (i in 2:nrows)
flow_browser[2]>
Error: object 'DV' not found 我试过的是:
在flow之外运行时,我的函数可以工作
> calculate_decc(initial_DV = 25,
+ initial_frspacing =200,
+ standstill_frspacing=10,
+ t=1/60,
+ nrows=1000,
+ LV_acc_mps2=vector(mode = "double", length = 1000),
+ den=2)
# A tibble: 1,000 x 3
DV Z D
<dbl> <dbl> <dbl>
1 25 200 -1.64
2 25.0 200. -1.64
3 24.9 199. -1.64
4 24.9 199. -1.64
5 24.9 198. -1.64
6 24.9 198. -1.64
7 24.8 198. -1.64
8 24.8 197. -1.64
9 24.8 197. -1.64
10 24.8 196. -1.64
# ... with 990 more rows ,我在这里错过了什么?
发布于 2020-08-25 07:52:57
不幸的是,flow::flow_run()遇到了很多问题,很抱歉。
请重新安装这个软件包,下面的程序应该可以工作。
library(tibble)
# remotes::install_github("moodymudskipper/flow")
library(flow)
flow_run(calculate_decc(initial_DV = 25,
initial_frspacing =200,
standstill_frspacing=10,
t=1/60,
nrows=1000,
LV_acc_mps2=vector(mode = "double", length = 1000),
den=2), browse = TRUE)它将触发函数体内的浏览器,只是您会注意到一些flow::update()调用,这些调用无声地更新了图表的数据。

每当您想要绘制当前情况的图表时,调用d,不带括号(如果d被变量覆盖,则使用flow_draw()实现同样的效果)。


https://stackoverflow.com/questions/63570879
复制相似问题