Libraries with the same function name in R seem to be very annoying. What is the easiest way to resolve issues like the following?
R中具有相同功能名称的库似乎非常烦人。解决以下问题的最简单方法是什么?
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.
添加库(统计信息)或调用过滤器函数作为stats :: filter和下面显示的其他函数对我来说没有用。
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?
但是这会在执行绘图功能之前不断给出先前的警告消息。有什么指针吗?或者无论如何要抑制这些警告并进行绘图?
1 个解决方案
#1
14
-
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).然而,主要的缺点是它只是隐藏了问题,它并没有停止执行。如果你需要实际使用其中一个蒙版函数,你可以像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 isanti-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.
这个答案试图总结将(最终)删除的许多评论。
#1
14
-
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).然而,主要的缺点是它只是隐藏了问题,它并没有停止执行。如果你需要实际使用其中一个蒙版函数,你可以像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 isanti-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.
这个答案试图总结将(最终)删除的许多评论。