具有相同功能名称的软件包 [英] Packages with the same function name

查看:137
本文介绍了具有相同功能名称的软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中具有相同功能名称的库似乎非常讨厌。解决以下问题的最简单方法是什么?

 附件包:'dplyr'

以下对象从package:stats中被屏蔽:
filter,lag
以下对象从package:base中被屏蔽:
intersect,setdiff,setequal,union

添加库(stats)或调用过滤器函数为 stats :: filter ,其他功能如下所示,并不适用于我。

 库(ggplot2)
库(dplyr)
库(stats)
stats: :filter
stats :: lag
base :: union
base :: setdiff
base :: setequal
base :: intersect

#读取数据
data< - read.csv(data.csv,header = FALSE)

#绘图
dataSummary< - data%>% group_by(id)%>%summaryize(data_count = x())
dataSummary
plotTest< - ggplot(dataSummary,aes(id,data_count))+ geom_bar(stat ='identity')+ ggtitle(Test Title)
plot(plotTest)

但是,执行绘图功能之前的警告消息。任何指针?或者有没有反对抑制这些警告和做绘图?

解决方案


  1. 如果你只是不想要显示警告,通过

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

    然而,主要的缺点是它只是隐藏了问题,它不会停止执行。如果您需要实际使用其中一个屏蔽功能,可以像 stats :: lag (@alistaire)一样调用。


  2. 不要使用掩盖基本功能的软件包。一般想法如果运行 example(filter)(说)在加载包后给出不同的答案是反社会


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


  4. 加载包的顺序很重要。首先加载的包是
    首先在搜索路径中,如果您使用已被
    屏蔽的函数。有关一些见解,请参阅此答案







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


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?

解决方案

  1. 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).

  2. 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.

  3. Some packages "improve" the base functions, so masking isn't an issue.

  4. 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.

这篇关于具有相同功能名称的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆