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
Run Code Online (Sandbox Code Playgroud)
添加library(stats)
或调用过滤器功能,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)
Run Code Online (Sandbox Code Playgroud)
但是这会在执行绘图功能之前不断给出先前的警告消息.有什么指针吗?或者无论如何要抑制这些警告并进行策划?
csg*_*pie 14
如果您只是不希望显示警告,请通过加载包
library(dplyr, warn.conflicts = FALSE)
Run Code Online (Sandbox Code Playgroud)
然而,主要的缺点是它只是隐藏了问题,它并没有停止执行.如果您需要实际使用其中一个蒙版函数,可以像stats::lag
(@alistaire)一样调用它.
不要使用掩盖基本功能的包.运行example("filter")
(说)的一般想法是在加载包之后给出不同的答案anti-social
.
一些软件包"改进"了基本功能,因此屏蔽不是问题.
加载包的顺序很重要.如果您使用的是已屏蔽的功能,则首先加载的包是搜索路径中的第一个.请参阅此答案以获得一些见解.
这个答案试图总结将(最终)删除的许多评论.