The summary () function gives strange results with Knitr / RStudio
I am currently experiencing some weird problems while rendering a simple Markdown script under RStudio. The Summary () function is giving the wrong result and I can't figure out what's going on because RStudio doesn't give any error at all.
If I executed the following RMarkdown script (I put the data file here )
```{r}
load('mydata.rda')
summary(mydata$b)
head(sort(mydata$b))
```
```{r}
sessionInfo()
```
I get the following result
load("mydata.rda")
summary(mydata$b)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 6000 10000 12000 16000 35000
head(sort(mydata$b))
## [1] -0.01 -0.01 0.00 0.00 0.00 0.00
sessionInfo()
## R version 2.15.1 (2012-06-22)
## Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
##
## locale:
## [1] es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/C/es_ES.UTF-8/es_ES.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.0.5
##
## loaded via a namespace (and not attached):
## [1] digest_0.5.2 evaluate_0.4.3 formatR_0.6 plyr_1.7.1
## [5] stringr_0.6.1 tools_2.15.1
As you can see, the result is incorrect because the actual minimum value of the variable "b" is negative, which seems to ignore the execution of summary (). I've tried the same with the Knitr Rnw pdf script and it does the same thing. However, when I run it through Sweave, the result is fine.
What is the pivot function returned when called under knitr / RStudio? Is this a side effect of something I can't see or a bug?
Regards, Gus
source to share
Try adding the following to the top of your document:
```{r, echo=FALSE}
options(digits = 7)
```
To see what is the difference between an R session and a markdown -> HTML knitr session, enter the following command in your R console and include it in your markddown document and compare the output of each one:
options()
options("digits")
in R session the default is 7, but in an environment that embedding an HTML document from a markdown file (at least on my system) is 4. Not sure where this is set;)
source to share