मैं उपयोग कर रहा हूँ में प्रस्तुत नहीं हो कुछ भूखंडों: Ubuntu 12.04 64-बिट, आर 3.0.2, RStudio 0.98.312, knitr 1.5, markdown 0.6.3, mgcv1.7 -27Rstudio, knitr, Rmarkdown
मेरे पास एकाधिक कोड भाग के साथ एक रमार्कडाउन दस्तावेज़ है। एक खंड के बीच में कोड के कुछ बिट्स हैं जहां मैं एक गैम फिट करता हूं, फिट को सारांशित करता हूं और फिट प्लॉट करता हूं। समस्या यह है कि पहली साजिश आउटपुट फ़ाइल में प्रस्तुत होती है लेकिन दूसरी साजिश नहीं है। यहाँ हिस्सा से एक स्वच्छ कोड टुकड़ा है: सिवाय इसके कि उत्पादन साधनों पर निम्नलिखित गणना गूंज से पीछे साजिश बयान गूंज से सीधे चला जाता है के रूप में उम्मीद
fit <- gam(y ~ s(x), data=j0, subset= !is.na(x))
summary(fit) # look at non-missing only
plot(fit)
fit <- gam(y ~ s(sqrt(x)), data=j0, subset= !is.na(x))
summary(fit)
plot(fit)
mean(y[is.na(x)]) - mean(y[!is.na(x)])
सब कुछ बना देता है। साधन गणना का परिणाम सही ढंग से प्रस्तुत किया जाता है।
यदि मैं बाद में खंड में 7 लाइनों को एक और प्लॉट कॉल पर टिप्पणी करता हूं, तो गायब साजिश सही ढंग से प्रस्तुत की जाती है।
क्या किसी के पास कोई सुझाव है कि यहां क्या हो रहा है?
अद्यतन नीचे
सारांश - प्लॉट 2 के लिए कॉल के बाद कई लाइनों वहाँ कुछ आर कोड है कि एक निष्पादन त्रुटि (चर नहीं मिला) और कई लाइनों उत्पन्न करता है कि उसके बाद वहाँ प्लॉट 3. अगर के लिए एक कॉल है कोड त्रुटि तय की जाती है तो प्लॉट 2 प्रस्तुत किया जाता है। यदि कोड त्रुटि unfixed है और प्लॉट 3 पर कॉल टिप्पणी की है, तो प्लॉट 2 प्रस्तुत किया जाता है। समस्या अलग-अलग फिट के परिणामों को संग्रहीत करने के लिए उपयोग की जाने वाली वही चर 'फिट' पर निर्भर करती है। यदि मैं प्रत्येक फिट को एक अलग चर प्लॉट 2 को ठीक करता हूं तो ठीक है।
मुझे समझ में नहीं आता कि सफलतापूर्वक निष्पादित कोड की कई पंक्तियों के बाद किए गए परिवर्तन (स्पष्ट रूप से पीछे से) प्लॉट 2 को प्रतिपादन से रोक सकते हैं।
प्रतिलिपि प्रस्तुत करने योग्य उदाहरण:
Some text.
```{r setup}
require(mgcv)
mkdata <- function(n=100) {
x <- rnorm(n) + 5
y <- x + 0.3 * rnorm(n)
x[sample(ceiling(n/2), ceiling(n/10))] <- NA
x <- x^2
data.frame(x, y)
}
```
Example 1
=========
Plot 2 fails to render. (Using the same fit object for each fit.)
```{r example_1}
j0 <- mkdata()
attach(j0)
mx <- min(x, na.rm=TRUE)
fit <- gam(y ~ s(x), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) # plot 1
fit <- gam(y ~ s(sqrt(x)), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) #plot 2
mean(y[is.na(x)]) - mean(y[!is.na(x)]) # means calculation
# recode the missing values
j0$x.na <- is.na(x)
j0$x.c <- ifelse(x.na, mx, x) # ERROR in recode
detach()
attach(j0)
fit <- gam(y ~ s(sqrt(x.c)) + x.na, data=j0) # doesn't run because of error in recode
summary(fit) # this is actually fit 2
plot(fit) # plot 3 (this is actually fit 2)
detach()
```
Example 2
=========
Use separate fit objects for each fit. Plot 2 renders OK.
```{r example_2}
j0 <- mkdata()
attach(j0)
mx <- min(x, na.rm=TRUE)
fit1 <- gam(y ~ s(x), data=j0, subset= !is.na(x))
summary(fit1)
plot(fit1) # plot 1
fit2 <- gam(y ~ s(sqrt(x)), data=j0, subset= !is.na(x))
summary(fit2)
plot(fit2) #plot 2
mean(y[is.na(x)]) - mean(y[!is.na(x)]) # means calculation
# recode the missing values
j0$x.na <- is.na(x)
j0$x.c <- ifelse(x.na, mx, x) # ERROR in recode
detach()
attach(j0)
fit3 <- gam(y ~ s(sqrt(x.c)) + x.na, data=j0) # doesn't run because of error in recode
summary(fit3)
plot(fit3) # plot 3
detach()
```
Example 3
=========
Revert to using the same fit object for each fit. Plot 2 renders because plot 3 is commented out.
```{r example_3}
j0 <- mkdata()
attach(j0)
mx <- min(x, na.rm=TRUE)
fit <- gam(y ~ s(x), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) # plot 1
fit <- gam(y ~ s(sqrt(x)), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) #plot 2
mean(y[is.na(x)]) - mean(y[!is.na(x)]) # means calculation
# recode the missing values
j0$x.na <- is.na(x)
j0$x.c <- ifelse(x.na, mx, x) # ERROR in recode
detach()
attach(j0)
fit <- gam(y ~ s(sqrt(x.c)) + x.na, data=j0)
summary(fit) # this is actually fit 2
# plot(fit) # plot 3 (this is actually fit 2)
detach()
```
Example 4
=========
Plot 2 renders because later recode error is fixed.
```{r example_4}
j0 <- mkdata()
attach(j0)
mx <- min(x, na.rm=TRUE)
fit <- gam(y ~ s(x), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) # plot 1
fit <- gam(y ~ s(sqrt(x)), data=j0, subset= !is.na(x))
summary(fit)
plot(fit) #plot 2
mean(y[is.na(x)]) - mean(y[!is.na(x)]) # means calculation
# recode the missing values
j0$x.na <- is.na(x)
j0$x.c <- ifelse(j0$x.na, mx, x) # error in recode fixed
detach()
attach(j0)
fit <- gam(y ~ s(sqrt(x.c)) + x.na, data=j0)
summary(fit)
plot(fit) # plot 3
detach()
```
लॉग फ़ाइल:
> require(knitr); knit('reproduce.Rmd', encoding='UTF-8');
Loading required package: knitr
processing file: reproduce.Rmd
|...... | 9%
ordinary text without R code
|............ | 18%
label: setup
|.................. | 27%
ordinary text without R code
|........................ | 36%
label: example_1
|.............................. | 45%
ordinary text without R code
|................................... | 55%
label: example_2
|......................................... | 64%
ordinary text without R code
|............................................... | 73%
label: example_3
|..................................................... | 82%
ordinary text without R code
|........................................................... | 91%
label: example_4
|.................................................................| 100%
ordinary text without R code
output file: reproduce.md
[1] "reproduce.md"
कृपया एक पुन: उत्पन्न उदाहरण पोस्ट करें। आपकी समस्या शायद आपके पास चंक विकल्प 'fig.keep' सेट के कारण है, लेकिन इस जानकारी के बिना यह पूरी तरह से अनुमान है। – mnel
लॉग क्या कहता है? –