如何防止使用 nvim-r 和 rstan 使用 knitr 打开 /tmp 文件

How to prevent opening /tmp files with knitr using nvim-r and rstan

我在 neovim 中使用 R 和 nvim-r 来使用 \kh\kp 命令编织 Rmd 文档。问题是当我编织一个适合 Rstan 模型的 Rmd 时,它打印 Rstan sampling() 调用的输出,包括链的进度在一个单独的临时文件中,位于这个位置:

file:///tmp/RtmpMmXreV/file27067eb3452f_StanProgress.html

包含此输出:

Click the Refresh button to see progress of the chains starting worker pid=17045 on localhost:11515 at 14:31:54.447 starting worker pid=17070 on localhost:11515 at 14:31:54.670

并在我的浏览器中打开 html 文件。结果是每次新模型开始采样时,我的浏览器都会弹出。只有当我使用 options(mc.cores = parallel::detectCores()) 并行化链时才会发生这种情况。如果没有该命令,html 文件不会弹出。

是否有可能阻止 nvim-r 打开这些临时 html 文件,或者是否有可能使 Rstan 的链输出静音?

最小示例:

library(rstan)

options(mc.cores = parallel::detectCores())

data(DNase)

model <- stan_model(model_code = "
data {
    int n;
    vector[n] conc;
    vector[n] density;
}
parameters {
    real b0;
    real b1;
    real<lower=0> sigma;
}
model {
    conc ~ normal(b0 + b1 * (density), sigma);
    b0 ~ normal(0, 10);
    b1 ~ normal(0, 10);
    sigma ~ normal(0, 10);
}")

fit <- sampling(model, data = list(n = nrow(DNase),
                       conc = DNase$conc, 
                       density = DNase$density))

编辑: 我尝试将 results="hide" 添加到块 header 并将 refresh = 0 添加到基于 sampling() 调用,但无济于事。 refresh = 0 确实成功删除了消息的 starting worker... 部分,但它仍会打开一个 html 文件,上面写着 Click the Refresh button to see progress of the chains.

open_progress = FALSE 添加到 sampling() 可防止 stan 将链的进度保存到日志文件中。默认,open_progress = TRUE只在cores > 1时生效。来自rstan reference。示例:

sampling(model, open_progress = FALSE)