Reputation: 792
I am trying to source a script that uses raster::extract(raster,spatialpolygons)
so it prints the message about which polygon it is using for extracting. The final output from the file is a ggplot which I want to show, but I don't want any messages from R to show.
```{r percent of avg, echo=FALSE,message=FALSE,warning=FALSE,fig.width=15}
source('src/analysis/extract_huc4_elev.R')
```
none of the chunk options echo, message or warning seem to suppress this output. if I use include=F
then the plot doesn't show.
EDIT: I had a print statement so that explains some of it :-/ and some additional sleuthing discovered it was actually this line:
> huc4=readOGR('data/gis','UpperCRB')
## OGR data source with driver: ESRI Shapefile
## Source: "data/gis", layer: "UpperCRB"
## with 8 features
## It has 9 fields
and you can hide the message in the script with:
> huc4=readOGR('data/gis','UpperCRB',verbose=F)
I do still wish there were a way to hide all script messages in the markdown output, e.g. in this case I'm sourcing an R file because I think it'll be more maintainable (this is my first reproducible report)- meaning I still would like to see those messages (print statements, verbose output, etc) when I'm working on the script itself.
also, here is the sessionInfo()
just in case:
## R version 3.2.2 (2015-08-14)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: OS X 10.9.5 (Mavericks)
##
## 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] parallel stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] ncdf4_1.13 gstat_1.0-26 doMC_1.3.3 iterators_1.0.7
## [5] foreach_1.4.2 ipred_0.9-5 MASS_7.3-44 rgdal_1.0-7
## [9] readr_0.1.1 dplyr_0.4.3 plyr_1.8.3 tidyr_0.3.1
## [13] raster_2.4-20 sp_1.2-0 ggplot2_1.0.1
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.1 formatR_1.2.1 xts_0.9-7 class_7.3-13
## [5] tools_3.2.2 rpart_4.1-10 digest_0.6.8 evaluate_0.8
## [9] gtable_0.1.2 lattice_0.20-33 DBI_0.3.1 yaml_2.1.13
## [13] prodlim_1.5.5 proto_0.3-10 stringr_1.0.0 knitr_1.11
## [17] grid_3.2.2 nnet_7.3-11 spacetime_1.1-4 R6_2.1.1
## [21] survival_2.38-3 rmarkdown_0.8 lava_1.4.1 reshape2_1.4.1
## [25] magrittr_1.5 intervals_0.15.1 codetools_0.2-14 scales_0.3.0
## [29] htmltools_0.2.6 splines_3.2.2 assertthat_0.1 colorspace_1.2-6
## [33] stringi_0.5-5 lazyeval_0.1.10 munsell_0.4.2 FNN_1.1
## [37] zoo_1.7-12
Upvotes: 2
Views: 453
Reputation: 792
After messing with this some more, I realized another way to do it was use include=F
and save the plot to disk in the R script and then outside the r chunk use 
Upvotes: 0
Reputation: 792
Based on the link that @RobertH commented http://yihui.name/knitr/demo/output, I tested and found that you can use results='hide',fig.keep='high',fig.show='asis'
and text output such as print() and cat() statements don't get printed in the html but the graph still comes through!
Upvotes: 0