2016-04-25 11 views
2

Mein R-Skript erstellt eine Reihe von Matrizen und Boxplots dieser Matrizen. Es ist möglich, dass eine der Matrizen leer ist. Die Ausführung von boxplot einer leeren Matrix gibt einen Fehler. Das ist kein Problem. Das Problem ist, wenn dieser Code in R Markdown ausgeführt wird, um eine HTML-Datei zu stricken, hält dieser Fehler die Ausführung an und führt zu keiner HTML-Datei.Knit HTML schlägt bei Codefehler fehl

Als Patch, ich würde boxplot nur ausführen, wenn die Matrix nicht alle NAs ist. Das funktioniert. Aber ich würde gerne wissen, ob ich es schaffen könnte, diesen Fehler einfach zu ignorieren, anstatt meinen Code zu patchen. Vielen Dank.

Dies ist die Fehlermeldung:

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 

Reproduzierbare Code:

```{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) 

Antwort

3

error=TRUE in Ihrem chunk Optionen Versuchen

```{r,echo = FALSE, warning = FALSE, message=FALSE, error=TRUE} 
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) 

``` 

gibt dieses Ergebnis Einstellung: enter image description here

Von der knitr options: "Fehler: (TRUE; logisch) ob Fehler erhalten werden sollen (von stop()); Standardmäßig wird die Auswertung auch bei Fehlern nicht gestoppt !! Wenn wir möchten, dass R bei Fehlern aufhört, müssen wir diese Option auf FALSE setzen. "

+0

Ich wusste, dass es eine einfache Antwort geben musste. Ich konnte es einfach nicht finden. Danke vm. – Krug

+0

Ich denke, Sie können' Cache' hinzufügen Auch Chunk-Optionen: '{r, cache = TRUE, echo = FALSCH, warning = FALSE, message = FALSE, error = TRUE}' – PoGibas

+0

@Pgibas das ist wahr, ich war mir nicht sicher, ob es einen anderen Grund gab, warum er gegangen war es aus (habe den Rest seines Codes nicht gesehen) – ano