【发布时间】:2016-12-30 04:36:31
【问题描述】:
我可以在控制台中从 SWSamp 包中运行以下示例脚本,但在编织到 PDF 时出现“isIncomplete(con)”错误。这个包需要使用至少 2 个内核,我想知道这个连接错误是否与尝试并行运行有关。
---
title: "Test"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
install.packages("http://www.statistica.it/gianluca/SWSamp/SWSamp_0.3.tar.gz", type="source", dependencies=TRUE, repos=NULL)
library(SWSamp)
```
```{r}
mu1=0.3
b.trt=-0.3875
sigma.e=1.55
J=5
K=20
sig.level=0.05
n.sims=10
rho=0.5
pow.cont <- sim.power(I=14, J=J, H=NULL, K=K, rho=rho, mu=mu1, sigma.e=sigma.e,
b.trt=b.trt, formula=NULL, n.sims=n.sims,
sig.level=sig.level, n.cores=2)
pow.cont$power
```
退出第 16-28 行 (test.Rmd) isIncomplete(con) 中的错误: 无效的连接调用:... evaluate_call -> handle_output -> -> isIncomplete 从第 16-28 行退出 (test.Rmd) isOpen(con) 中的错误:无效连接调用: ... in_dir -> 评估 -> 评估调用 -> -> isOpen close.connection(con) 中的错误:无效连接调用: -> -> 关闭 -> close.connection 执行 停止
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] SWSamp_0.3 lme4_1.1-12 Matrix_1.2-7.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 knitr_1.15.1 magrittr_1.5 splines_3.3.2 MASS_7.3-45
[6] doParallel_1.0.10 lattice_0.20-34 foreach_1.4.3 minqa_1.2.4 stringr_1.1.0
[11] tools_3.3.2 parallel_3.3.2 grid_3.3.2 nlme_3.1-128 htmltools_0.3.5
[16] iterators_1.0.8 yaml_2.1.14 rprojroot_1.1 digest_0.6.10 nloptr_1.0.4
[21] codetools_0.2-15 evaluate_0.10 rmarkdown_1.3 stringi_1.1.2 compiler_3.3.2
[26] backports_1.0.4
【问题讨论】:
-
This SO answer 提供了一些关于不同包可能关闭连接的可能方式的提示,但
evaluate()解决方案对我不起作用。 -
sim.power函数确实使用了closeAllConnections()函数,这可能会干扰 knitr。 -
我的临时解决方案是重新定义
sim.power()函数,并注释掉closeAllConnections()调用。我不知道这是否有不利影响,但似乎对我有利。更好的方法?