代码错误导致编织HTML无法输出

时间:2016-04-25 18:38:16

标签: r knitr r-markdown boxplot

我的R脚本创建了一系列矩阵的矩阵和箱线图。其中一个矩阵可能是空的。执行空矩阵的boxplot会产生错误。那不是问题。问题是,当在R Markdown中运行此代码来编织HTML文件时,此错误会暂停执行并导致不生成HTML文件。

作为补丁,我只有在矩阵不是所有NA的情况下运行boxplot。这样可行。然而,我想知道我是否可以让knitr简单地忽略这个错误,而不是修补我的代码。谢谢。

这是错误消息:

Error in plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) : 
  need finite 'ylim' values
Calls: <Anonymous> ... boxplot -> boxplot.default -> do.call -> bxp -> plot.window
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
Execution halted

可重复的代码:

```{r,echo = FALSE, warning = FALSE, message=FALSE}
knitr::opts_chunk$set(cache=TRUE)

#MatrixPos - not empty
MatrixPos <- structure(list(difFwd1 = 0, difFwd2 = 0.200000000000045, difFwd3 = 0.100000000000136,difFwd4 = 0, difFwd5 = 0.200000000000045), .Names = c("difFwd1","difFwd2", "difFwd3", "difFwd4", "difFwd5"), row.names = "155", class = "data.frame") 

#MatrixNeg - empty
MatrixNeg <- structure(list(difFwd1 = NA_real_, difFwd2 = NA_real_, difFwd3 = NA_real_,difFwd4 = NA_real_, difFwd5 = NA_real_), .Names = c("difFwd1","difFwd2", "difFwd3", "difFwd4", "difFwd5"), row.names = "NA", class = "data.frame") 

boxplot(MatrixPos, notch = TRUE, outline = TRUE)
boxplot(MatrixNeg, notch = TRUE, outline = TRUE)

```
###note must remove the four spaces for the code to work in R-Studio


#Solution attempt:
if(!all(is.na(MatrixNeg))) boxplot(MatrixNeg, notch = TRUE, outline = TRUE)

1 个答案:

答案 0 :(得分:3)

尝试在块选项中设置var empIds = (from a in GetUsers(EmployeeID) select a.EmployeeID).Distinct(); from s in _repository.GenericRepository<STG_WDUsers>().GetAll() .Where(u => empIds.Contains(u.Employee_ID));

error=TRUE

给出了这个结果: enter image description here

knitr options:“错误:(TRUE;逻辑)是否保留错误(来自stop());默认情况下,即使出现错误,评估也不会停止!!如果我们想要R到停止错误,我们需要将此选项设置为FALSE“

相关问题