1

In RStudio I try to knit my code which produces a map into html-file and get in compiled html-file besides a map an undesired message:

"## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3".

This message is produced by the function tm_shape() which plots a map from tmap library.

I tried to surround construction with tm_shape() function by the construction invisible(capture.output(...)). It doesn't work.

I also tried to execute the function tmap_options(show.messages = FALSE) before calling tm_shape(). It doesn't work.

suppressPackageStartupMessages(library(rgdal))

suppressPackageStartupMessages(library(tmap))

tmap_options(show.messages = FALSE)

invisible(capture.output(area = readOGR("adm1.shp")))

area@data$VARNAME_1 = as.character(area@data$VARNAME_1)

suppressPackageStartupMessages(library(dplyr))

area@data = left_join(area@data, df, by = c("VARNAME_1" = "Area"))

tm_shape(area) + tm_fill("x", style = "fixed", palette = "Greens", breaks = c(0,10,20,30,40,50), labels = c("0-10", "10-20", "20-30", "30-40", "40-50")) + tm_legend(text.size = 1) + tm_layout(legend.position = c("left", "bottom")) + tm_borders("grey") + tm_layout(frame = F) 

So, the question is how to suppress this undesired message?

enter image description here

lovalery
  • 4,524
  • 3
  • 14
  • 28
Helios
  • 141
  • 1
  • 2
  • 10
  • 1
    Did you try `suppressMessages` and `suppressWarnings` – G5W Apr 14 '19 at 11:38
  • `options(warn=-1)` maybe?(Not always recommended). – NelsonGon Apr 14 '19 at 11:40
  • 1
    The message is more likely to arise because you did `library(sf)`. Add `message=FALSE` in the chunk options. – Sébastien Rochette Apr 14 '19 at 12:01
  • Yes, I tried to surround construction with tm_shape() both with suppressMessages and suppressWarnings - it doesn't work.options(warn=-1) also doesn't work. – Helios Apr 14 '19 at 12:55
  • I don't call sf library. Probably tmap library loads sf library automatically. "message=FALSE" works! Problem solved. Thank you Sébastien! – Helios Apr 14 '19 at 13:06
  • Possible duplicate of [R - Markdown avoiding package loading messages](https://stackoverflow.com/questions/13090838/r-markdown-avoiding-package-loading-messages). Also check [R for Data Science - Chunk options](https://r4ds.had.co.nz/r-markdown.html#chunk-options) – Valentin_Ștefan Apr 14 '19 at 13:40

0 Answers0