Libraries with the same function name in R seem to be very annoying. What is the easiest way to resolve issues like the following?
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
adding library(stats)
or calling the filter function as stats::filter
and the other functions as it is shown below didn't work out for me.
library(ggplot2)
library(dplyr)
library(stats)
stats::filter
stats::lag
base::union
base::setdiff
base::setequal
base::intersect
# Reading in the data
data <- read.csv("data.csv", header = FALSE)
# Plots
dataSummary <- data %>% group_by(id) %>% summarise(data_count = x())
dataSummary
plotTest <- ggplot(dataSummary, aes(id, data_count)) + geom_bar(stat = 'identity') + ggtitle("Test Title")
plot(plotTest)
But this keeps giving the previous warning message before executing the plot function. Any pointers? or is there anyway to suppress these warnings and do the plotting?
If you just don't want the warnings to show up, load the package via
library(dplyr, warn.conflicts = FALSE)
However the major downside is that it just hides the problem, it doesn't stop the execution. If you need to actually use one of the masked functions, you can call it like stats::lag
(@alistaire).
Don't use packages that mask base functions. The general idea if running example("filter")
(say) gives a different answer after loading a package is anti-social
.
Some packages "improve" the base functions, so masking isn't an issue.
Order of loading the packages matters. First loaded package is the first in the search path if you are using a function that has been masked. See this answer for some insight.
This answer attempted to summarise the many comments that will (eventually) deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With