找出使用了某个包中的哪些函数

Find out which function(s) from certain package were used

有没有办法找出在当前会话中调用了某个包中的哪些函数?

(我正在以不同的顺序采购各种脚本,由于加载-plyr-after-dplyr-问题,我想停止使用任何 plyr 函数,但它通过所有脚本找出我实际使用的 plyr-函数似乎有点乏味。)

函数 list.functions.in.file from the {NCmisc}package 似乎可以满足您的需求。它 returns 脚本中使用的所有函数的列表和 returns 它们由它们来自的包分隔。

一个例子:当你 运行 这个虚拟代码(保存为 R 脚本)的函数时,运行 有几个例子来自 {ggplot2}{dplyr},以及 {tidyr}...

# ggplot2 examples
library(ggplot2) 
ggplot(data = cars, aes(x = speed, y = dist)) + geom_point()
qplot(data = diamonds, x = carat, y = price, color = color)

#dplyr examples
library(dplyr)
filter(mtcars, cyl == 8)
select_(iris, "Petal.Length")

#tidyr examples
library(tidyr)
gather(iris, key = flower_att, value = measurement,
       Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)

df <- data.frame(x = c("a", "b"), y = c(3, 4), z = c(5, 6))
df %>% spread(x, y) %>% gather(x, y, a:b, na.rm = TRUE)

您将获得以下列表作为输出:

$`c("package:dplyr", "package:stats")`
[1] "filter"

$`package:base`
[1] "c"          "data.frame" "library"   

$`package:dplyr`
[1] "select_"

$`package:ggplot2`
[1] "aes"        "geom_point" "ggplot"     "qplot"     

$`package:tidyr`
[1] "gather" "spread"