我正在使用R&knitr构建小报告,并将输出发送到pdf。

我在分析中使用了多个形状文件,每当使用readOGR包的rgdal函数时,我都会获取有关所读取内容的信息,例如:

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


通常,拥有它是很有用的..但是不幸的是,它也打印在我的pdf输出中。

我尝试将knitr的块选项设置为echo=FALSE, message=FALSE,但是不幸的是,它没有帮助。

有更好的解决方案吗?

最佳答案

您是否尝试过在verbose = FALSE函数本身中设置readOGR

例如

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


那么,相关的编织块可能是:

```{r, echo=FALSE, message=FALSE}
library(rgdal)
dsn <- system.file("vectors", package = "rgdal")[1]
cities <- readOGR(dsn=dsn, layer="cities", verbose=FALSE)
```

10-01 08:01
查看更多