How to know to which package a particular function

2020-06-16 09:03发布

Example, I know many popular functions, to name one like tbl_df(). I usually do not remember which package it belongs to i.e. data.table or dplyr. So I have to always remember and load a package and I can not do ?tbl_df unless I have loaded the correct package.

Is there a way to know to which package a particular function belongs to, prior to loading or installing of the package in R console itself.

Any help is highly appreciated. Thanks.

标签: r package
2条回答
2楼-- · 2020-06-16 09:30

Inspired by @J_F who suggested ??tbl_df: I was looking for 'arima' and had dozens if not hundreds of hits; I narrowed them down using

help.search('arima', fields=c('name'), ignore.case=FALSE, agrep=FALSE)

(most importantly, agrep=FALSE turns off fuzzy matching)

查看更多
▲ chillily
3楼-- · 2020-06-16 09:31

sos package can help! Try:

install.packages("sos")
library(sos)
findFn("str_replace")

Try this as well

lsp <- function(package, all.names = FALSE, pattern) 
{ package <- deparse(substitute(package)) ls( pos = paste("package", package, sep = ":"),
all.names = all.names, pattern = pattern ) }

after running this function, if you want to search for str_replace function in stringr package- lsp(stringr, pattern="*replace")

查看更多
登录 后发表回答