11

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.

Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30

3 Answers3

3

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")

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
anoopdk
  • 31
  • 3
  • 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") – anoopdk Nov 12 '18 at 12:08
  • it's a bit intimidating as it's still a big string search and can return many hits... but you can sort the resulting HTML table by clicking any of the headers, including to sort by Function name and then quickly see those options. – Mike M Aug 20 '20 at 06:01
2

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)

James
  • 673
  • 6
  • 19
0

Try highlighting the function then click the "fn + F1" buttons on your keyboard.

This works when packages are installed already and not loaded, but won't work if the packages aren't installed yet.

This way you don't have to type any more code, super easy!