在页面向下Rmarkdown中抑制来自陶瓷包的下载消息

x8goxv8g  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(106)

我有一个循环,用于剪辑不同的要素,ceramic包为每个要素下载一个底图,然后使用tmap包打印Map。在Rmarkdown的html或pdf输出中,我可以使用{r map, results = 'hide', fig.keep='all'}隐藏ceramic的“Preparing to download...”消息。Map可以打印,但消息不能打印(这正是我想要的)。然而,使用pagedreport,该方法不起作用。没有Map打印。
我试着把陶瓷部分
并将options(warn=-1)设置在数据块的开头
两个都不行。还有别的建议吗?
你需要你自己的API密钥来运行这个程序,输出很难看,但是可以理解。
可重复循环:

---
title: "nc"
date: "`r Sys.Date()`"
output: 
  pagedreport::paged_windmill:
    
knit: pagedown::chrome_print

---

{r libs, include = F}

library(raster)
library(sp)
library(tidyverse)
library(ceramic)
library(tmap)
library(maps)

{r individual-maps, echo=FALSE, error=TRUE, message=FALSE, warning=FALSE, results='asis', fig.keep='all'}

#get practice shapefile
nc <- sf::read_sf(system.file("shape/nc.shp", package="sf"))

#get list of unique trail numbers
#unique_county_names <- unique(nc$NAME)
unique_county_names <- c("Ashe", "Alleghany", "Surry") # created a short list for simplicity

#set Mapbox API key for the session
Sys.setenv(MAPBOX_API_KEY = "need your own")

for (i in 1:length(unique_county_names)) {
county <-
filter(nc, NAME == unique_county_names[i])

set basemap

basemap = ceramic::cc_location(loc =
extent(sf::st_transform(
county, 4326
)),
base_url = "https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/tiles/{zoom}/{x}/{y}")

county_map <- tm_shape(basemap) +
tm_rgb() +
tm_shape(county) +
tm_polygons()

print(county_map)

}

osh3o9ms

osh3o9ms1#

我发现这是一个cat()输出,然后我就写了这篇How to hide or disable in-function printed message文章
而哈德利·威克姆的本给出了答案:

quiet <- function(x) { 
  sink(tempfile()) 
  on.exit(sink()) 
  invisible(force(x)) 
}

然后我把它包在底图上

basemap = quiet(ceramic::cc_location(loc = 
    extent(sf::st_transform(
   county, 4326
  )),
  base_url = "https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/tiles/{zoom}/{x}/{y}"))

别再留言了!

相关问题