2

A list of all R packages on CRAN can be found here.

Is there a quick and easy way to get all the function names within all of those packages?

stevec
  • 41,291
  • 27
  • 223
  • 311
  • You might check if you can get it via the [rdocumentation api](https://www.rdocumentation.org/docs/) – phiver Mar 09 '19 at 09:08
  • Try to look here, the comments and `sos` package might be useful for you: https://stackoverflow.com/questions/11379807/list-all-functions-on-cran – DJV Mar 09 '19 at 09:22
  • @DJV definitely helpful, but `sos::findFn("dplyr")` (just as an example) identifies 4212 matches and the function only returns the first 400 of them, and it doesn't return them to the R environment, but opens a webpage displaying them. Roughly useful, but with many inconveniences and not comprehensive if it only returns some (possibly small) fraction of overall results. I appreciate the useful info, but this isn't quick and easy unfortunately – stevec Mar 09 '19 at 11:35

2 Answers2

1

You can use lsf.str function to get all the functions in a package

lsf.str("package:lubridate")

#%--% : function (start, end)  
#%m-% : Formal class 'standardGeneric' [package "methods"] with 8 slots
#%m+% : Formal class 'standardGeneric' [package "methods"] with 8 slots
#%within% : Formal class 'standardGeneric' [package "methods"] with 8 slots
#add_with_rollback : function (e1, e2, roll_to_first = FALSE, preserve_hms = TRUE) 
#....

Moreover, you can get all the packages using available.packages function.

df <- available.packages()

This returns a matrix which has a column name "Package" which you can use programmatically to get all the function names.

sapply(df[, 1], function(x) lsf.str(paste0("package:", x)))

but this I think would require you to have all the packages downloaded on your system. It works at least for

sapply(c("lubridate", "dplyr"), function(x) lsf.str(paste0("package:", x)))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Doing this for >10000 packages could work (I don't know if I'd have the disk space), but it certainly isn't quick or easy. Is there a way to get all of the function names for all packages without having to download them first? – stevec Mar 09 '19 at 09:16
  • I am not sure if you could get all the functions in a package without downloading them but I edited an answer which can help you to get all the available packages. – Ronak Shah Mar 09 '19 at 09:26
1
library(collidr)

# This data.frame is ~300k rows, here are the first 10

collidr::CRANdf[1:10, ]

# package_names     function_names
# 1             A3         A3-package
# 2             A3                 a3
# 3             A3            a3.base
# 4             A3     a3.gen.default
# 5             A3              a3.lm
# 6             A3              a3.r2
# 7             A3            housing
# 8             A3 multifunctionality
# 9             A3            plot.A3
# 10            A3    plotPredictions
...
stevec
  • 41,291
  • 27
  • 223
  • 311