In R and knitr, can I suppress the message of readOGR?

后端 未结 2 874
自闭症患者
自闭症患者 2021-01-04 06:52

I\'m building small report using R & knitr, sending the output to pdf.

I\'m using several shape files in my analysis and whenever I use readOGR func

相关标签:
2条回答
  • 2021-01-04 07:30

    The "knitr" way to do this would be to use results = 'hide'. Borrowing from @SimonO101's example data, try:

    ```{r, results='hide', echo=FALSE, message=FALSE}
    library(rgdal)
    dsn <- system.file("vectors", package = "rgdal")[1]
    cities <- readOGR(dsn=dsn, layer="cities")
    ```
    
    0 讨论(0)
  • 2021-01-04 07:51

    Have you tried setting verbose = FALSE in the readOGR function itself?

    e.g.

    > dsn <- system.file("vectors", package = "rgdal")[1]
    > cities <- readOGR(dsn=dsn, layer="cities")
    OGR data source with driver: ESRI Shapefile 
    Source: "C:/Users/sohanlon/Dropbox/R/R64_Win_Libs/rgdal/vectors", layer: "cities"
    with 606 features and 4 fields
    Feature type: wkbPoint with 2 dimensions
    # Set verbose = FALSE
    > cities <- readOGR(dsn=dsn, layer="cities" , verbose = FALSE)
    

    The relevant knitr chunk, then, could be:

    ```{r, echo=FALSE, message=FALSE}
    library(rgdal)
    dsn <- system.file("vectors", package = "rgdal")[1]
    cities <- readOGR(dsn=dsn, layer="cities", verbose=FALSE)
    ```
    
    0 讨论(0)
提交回复
热议问题