The comment by @Khashaaa indicates one way to prevent the message, useful and succinct if you know in advance the binding variables. See ?dplyr::join
for how to do this with one or more variables. The syntax for the given example would be
left_join(airlines,by="carrier")
Because the dplyr
code is using R's message()
function to emit the Joining by: *
message, you could use R's suppressMessages()
wrapper around the left_join
(or any other dplyr
join) to suppress these messages. See ?message
for more info. The OP example in fact returns two kinds of messages,
>library("nycflights13")
>library("dplyr")
>result <- flights %>%
+ select(year:day, hour, origin, dest, tailnum, carrier) %>%
+ left_join(airlines)
Joining by: "carrier"
Warning message:
In left_join_impl(x, y, by$x, by$y) :
joining factor and character vector, coercing into character vector
One can suppress the first message with the suppressMessages()
wrapper
>suppressMessages(result <- flights %>%
+ select(year:day, hour, origin, dest, tailnum, carrier) %>%
+ left_join(airlines))
Warning message:
In left_join_impl(x, y, by$x, by$y) :
joining factor and character vector, coercing into character vector
The second message is a diagnostic warning message. See ?warning
for more information; there are several ways to handle this case. One way, if you choose to suppress it like the previous message, is to add another wrapper,
> suppressWarnings(suppressMessages(result <- flights %>%
+ select(year:day, hour, origin, dest, tailnum, carrier) %>%
+ left_join(airlines)))
>