15

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 function of rgdal package I get information on what is being read, for instance:

OGR data source with driver: ESRI Shapefile 
Source: "__PATH_HERE__", layer: "__NAME__OF__LAYER__HERE__"
with 148 features and 5 fields
Feature type: wkbPolygon with 2 dimensions

Normally, it's useful thing to have.. but unfortunately it also prints out in my pdf output.

I tried setting knitr's chunk options to echo=FALSE, message=FALSE but unfortunately it did't help.

Any better solution to that?

Cœur
  • 32,421
  • 21
  • 173
  • 232
radek
  • 6,256
  • 7
  • 48
  • 74
  • you got two better solutions, but when everything else fails (ie print message in C code, and knitr chunk that you want to see other output from), I found that `capture.output` can be useful. – baptiste Apr 15 '13 at 10:41

2 Answers2

30

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)
```
A5C1D2H2I1M1N2O1R2T1
  • 177,446
  • 27
  • 370
  • 450
Simon O'Hanlon
  • 54,383
  • 9
  • 127
  • 173
9

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")
```
A5C1D2H2I1M1N2O1R2T1
  • 177,446
  • 27
  • 370
  • 450