0

I am trying to map a bunch of countries with the following code.

require(mapdata)

# get the names
cc <- map('world', names = TRUE, plot = FALSE)

take <- unlist(sapply(c("iran", "malaysia", "saudi arabia", "united arab emirates", "kuwait", "bahrain", "indonesia", "qatar", "sudan", "pakistan", "bangladesh", "turkey", "egypt", "united kingdom", "jordan", "brunei", "sri lanka", "oman", "yemen", "lebanon", "kenya"), grep, tolower(cc), value = TRUE))

suppressWarnings(map())

suppressWarnings(map('world', regions=take, fill=TRUE, col='red', add = TRUE))

I get what I want, however, the Pdf version has the following warning printed on page

####  # maps v3.1: updated 'world': all lakes moved to separate new ###  # 'lakes' database. Type '?world' or 'news(package="maps")'.  #

I use suppressWarnings, but the warning is still printed. How can I hide this when I knit the document with knitr?

RookiePie
  • 1
  • 3
  • The `suppressWarnings` may need to be put around the `require(mapdata)` as I think that is what is generating the warning (not an error!). Or load the package outside of the part of code that is sent to the pdf. – thelatemail May 30 '16 at 04:14
  • Thanks--I did both, but I still get the warning on the page... – RookiePie May 30 '16 at 04:32
  • I figured it out. Need to type `suppressPackageStartupMessages(library(maps))` before the code. – RookiePie May 30 '16 at 04:54
  • According to the help file, just `suppressMessages(...)` should do it, as they are still messages. I stuffed up by referring to them as warnings, they are messages instead. – thelatemail May 30 '16 at 04:57
  • Hi--many thanks for the follow up--I tried `suppressMessages()` but that did not work. Apparently, this is a startup message when I load the package, and the help file suggests `suppressPackageStartupMessages()` to avoid this expression. – RookiePie May 30 '16 at 05:03
  • A direct quote from the help file - "‘packageStartupMessage’ is a variant whose messages can be suppressed separately by ‘suppressPackageStartupMessages’. (They are still messages, **so can be suppressed by ‘suppressMessages’.**)" Interesting to know if that isn't always the case. Just tested it on `suppressMessages(library(dplyr))` and it worked as expected to load the package silently. – thelatemail May 30 '16 at 05:06

0 Answers0