从源脚本中删除消息
remove messages from sourced script
我正在尝试获取一个使用 raster::extract(raster,spatialpolygons)
的脚本,以便它打印有关正在使用哪个多边形进行提取的消息。该文件的最终输出是一个我想显示的 ggplot,但我不想显示来自 R 的任何消息。
```{r percent of avg, echo=FALSE,message=FALSE,warning=FALSE,fig.width=15}
source('src/analysis/extract_huc4_elev.R')
```
none 块选项 echo、message 或 warning 似乎抑制了此输出。如果我使用 include=F
则绘图不会显示。
编辑:我有一个打印语句,所以解释了其中的一些:-/ 一些额外的侦查发现它实际上是这一行:
> huc4=readOGR('data/gis','UpperCRB')
## OGR data source with driver: ESRI Shapefile
## Source: "data/gis", layer: "UpperCRB"
## with 8 features
## It has 9 fields
您可以在脚本中隐藏消息:
> huc4=readOGR('data/gis','UpperCRB',verbose=F)
我仍然希望有一种方法可以在降价输出中隐藏所有脚本消息,例如在这种情况下,我正在采购一个 R 文件,因为我认为它更易于维护(这是我的第一个可重现的报告)——这意味着我仍然希望在我处理脚本本身。
此外,这里是 sessionInfo()
以防万一:
## 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
基于@RobertH评论http://yihui.name/knitr/demo/output的link,我测试发现可以使用results='hide',fig.keep='high',fig.show='asis'
和文本输出如print()和cat()语句' 在 html 中打印,但图表仍然存在!
再弄乱这个之后,我意识到另一种方法是使用 include=F
并在 R 脚本中将绘图保存到磁盘,然后在 r 块之外使用 
我正在尝试获取一个使用 raster::extract(raster,spatialpolygons)
的脚本,以便它打印有关正在使用哪个多边形进行提取的消息。该文件的最终输出是一个我想显示的 ggplot,但我不想显示来自 R 的任何消息。
```{r percent of avg, echo=FALSE,message=FALSE,warning=FALSE,fig.width=15}
source('src/analysis/extract_huc4_elev.R')
```
none 块选项 echo、message 或 warning 似乎抑制了此输出。如果我使用 include=F
则绘图不会显示。
编辑:我有一个打印语句,所以解释了其中的一些:-/ 一些额外的侦查发现它实际上是这一行:
> huc4=readOGR('data/gis','UpperCRB')
## OGR data source with driver: ESRI Shapefile
## Source: "data/gis", layer: "UpperCRB"
## with 8 features
## It has 9 fields
您可以在脚本中隐藏消息:
> huc4=readOGR('data/gis','UpperCRB',verbose=F)
我仍然希望有一种方法可以在降价输出中隐藏所有脚本消息,例如在这种情况下,我正在采购一个 R 文件,因为我认为它更易于维护(这是我的第一个可重现的报告)——这意味着我仍然希望在我处理脚本本身。
此外,这里是 sessionInfo()
以防万一:
## 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
基于@RobertH评论http://yihui.name/knitr/demo/output的link,我测试发现可以使用results='hide',fig.keep='high',fig.show='asis'
和文本输出如print()和cat()语句' 在 html 中打印,但图表仍然存在!
再弄乱这个之后,我意识到另一种方法是使用 include=F
并在 R 脚本中将绘图保存到磁盘,然后在 r 块之外使用 