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

If you are using st_read instead of readOGR use quiet=TRUE as an additional parameter to hide the logs


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)
```

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")
```

Tags:

R

Ogr

Knitr