在knitr中抑制readOGR消息

时间:2015-06-27 15:50:05

标签: r knitr sweave rgdal

我想知道如何在readOGR中抑制knitr错误消息。我的MWE如下:

\documentclass{article} 
\begin{document}
<< Test >>=
library(rgdal)
dsn <- system.file("vectors", package = "rgdal")[1]
setwd(dsn)
cities <- readOGR(dsn=dsn, layer="cities")
@ 
\end{document}

函数readOGR给出如下消息:

OGR data source with driver: ESRI Shapefile 
Source: "/home/asd/R/i686-pc-linux-gnu-library/3.2/rgdal/vectors", layer: "cities"
with 606 features
It has 4 fields

但我想压制这条消息。我试过message=FALSE,但它对我不起作用。

被修改

sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.2 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] grid      tools     stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggmap_2.4       mapproj_1.2-2   maps_2.3-9      leaflet_1.0.0   rgeos_0.3-11    rgdal_1.0-4    
 [7] maptools_0.8-36 sp_1.1-1        Hmisc_3.16-0    Formula_1.2-1   survival_2.38-2 lattice_0.20-31
[13] psych_1.5.4     ggbiplot_0.55   plyr_1.8.3      gplots_2.17.0   rsm_2.7-2       scales_0.2.5   
[19] ggplot2_1.0.1   xtable_1.7-4    highr_0.5       knitr_1.10.12   brew_1.0-6      stringr_1.0.0  

loaded via a namespace (and not attached):
 [1] RColorBrewer_1.1-2   jsonlite_0.9.16      reshape2_1.4.1       cluster_2.0.2        rstudioapi_0.3.1    
 [6] magrittr_1.5         acepack_1.3-3.3      gtable_0.1.2         htmltools_0.2.6      splines_3.2.1       
[11] dplyr_0.4.2          KernSmooth_2.23-14   htmlwidgets_0.5      gridExtra_0.9.1      R6_2.0.1            
[16] digest_0.6.8         colorspace_1.2-6     proto_0.3-10         stringi_0.5-2        yaml_2.1.13         
[21] lazyeval_0.1.10.9000 evaluate_0.7         labeling_0.3         RJSONIO_1.3-0        gdata_2.16.1        
[26] rpart_4.1-9          munsell_0.4.2        DBI_0.3.1            Rcpp_0.11.6          RgoogleMaps_1.2.0.7 
[31] png_0.1-7            MASS_7.3-41          parallel_3.2.1       assertthat_0.1       rjson_0.2.15        
[36] caTools_1.17.1       gtools_3.5.0         jpeg_0.1-8           latticeExtra_0.6-26  foreign_0.8-63      
[41] bitops_1.0-6         nnet_7.3-9           geosphere_1.3-13     formatR_1.2          mnormt_1.5-3     

2 个答案:

答案 0 :(得分:3)

只需将 void setupOpenGL() { std::cerr << "CONTEXT: OpenGL v" << glGetString(GL_VERSION) << std::endl; glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); glDepthRange(0.0, 1.0); glClearDepth(1.0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); } void display() { ++FrameCount; glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderScene(); glutSwapBuffers(); } void renderScene() { wallNorth.draw(shader); obstacle1.draw(shader); wallEast.draw(shader); wallWest.draw(shader); ship1.draw(shader); plane.draw(shader); } 添加到verbose=FALSE调用即可取消消息(这些消息在交互式会话期间很有用,但在脚本或笔记本中却很有用)。

答案 1 :(得分:0)

试试这个:

<<Test, message=FALSE, results='hide', echo=FALSE>>=