【问题标题】:Packages with the same function name具有相同功能名称的包
【发布时间】:2016-05-03 13:15:36
【问题描述】:

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

添加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) 

但这会在执行绘图功能之前一直给出先前的警告消息。任何指针?还是有办法抑制这些警告并进行绘图?

【问题讨论】:

    标签: r ggplot2 dplyr


    【解决方案1】:
    1. 如果您只是不想显示警告,请通过

      加载包
      library(dplyr, warn.conflicts = FALSE)
      

      但主要的缺点是它只是隐藏了问题,并没有停止执行。如果您需要实际使用其中一个被屏蔽的函数,您可以将其称为stats::lag (@alistaire)。

    2. 不要使用屏蔽基本功能的包。如果在加载包后运行example("filter")(比如说)给出不同的答案,一般的想法是anti-social

    3. 一些包“改进”了基本功能,因此屏蔽不是问题。

    4. 加载包的顺序很重要。第一个加载的包是 如果您使用的功能已 蒙面。请参阅 this answer 了解一些见解。


    此答案试图总结将(最终)删除的许多 cmets。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 2020-03-30
      相关资源
      最近更新 更多