2016-05-17 128 views
0

有沒有辦法找出當前會話中某個包中的哪些函數被調用?找出使用某個包中的哪些函數

(我在不同的訂單採購各種腳本,並希望停止使用任何plyr功能由於loading- plyr -after- dplyr - 問題,但它似乎有點乏味要經過所有腳本找出哪些plyr -functions我正在使用。)

回答

3

{NCmisc}package功能list.functions.in.file似乎做你在找什麼。它返回一個腳本中使用的所有函數的列表,並以它們來自的包來分隔它們。

一個例子:當您運行在這個僞代碼(保存爲的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" 
+0

也許該功能在.Rnw文件(針對knitr,LaTeX)上不起作用? Error in parse(filename,keep.source = TRUE): 〜/ R/Projects/Baseball/baseball.Rnw:1:1:意外輸入 1:\ ^ 另外:警告信息: 在list.functions .in.file(「〜/ R/Projects/Baseball/baseball.Rnw」): 期待* .R文件,將嘗試繼續 – lawyeR

+0

是的,它目前還不能用於R-Markdown(.Rmd)文件據我所知,測試時可以看到。 – abel

相關問題