I am running an R function within a third-party software package. (The third-party package uses an older version of R, version 3.6). The output I am passing along is:
library(tidyverse)
theOutput <- x %>%
left_join(y, by = "id")
However, the output I am getting from the package is this notification, which I see in RStudio whenever I do a join, Joining, by = "id"
. How do I silence this message such that it will not be passed along as output? I tried
options(tidyverse.quiet = TRUE)
but it does not seem to stop the join message.
(Also, if the only answer is "your third party needs to use the newest version of R," I understand, but that is unfortunately impossible.)
CodePudding user response:
We can use suppressMessages
. First, let's recreate your issue:
library(dplyr)
df1 <- data.frame(letter = c("A", "B", "C"), data = 1:3)
df2 <- data.frame(letter = c("A", "B", "C"), value = 4:6)
df1 %>%
left_join(df2)
#> Joining, by = "letter"
#> letter data value
#> 1 A 1 4
#> 2 B 2 5
#> 3 C 3 6
Note we have the "Joining, by" message. But if we add suppressMessages
to the pipe after our left join
df1 %>%
left_join(df2) %>%
suppressMessages()
#> letter data value
#> 1 A 1 4
#> 2 B 2 5
#> 3 C 3 6
It disappears.
Created on 2022-09-15 with reprex v2.0.2