7

Suppose I'm trying to run a script of unknown origin, and one of the functions is from a package that is not loaded by the script (an oversight, maybe it was loaded in the .Rprofile of the person who wrote it). How can I find in which package this function resides?

There's some information compiled on CRAN, that doesn't require the user to download/install all R packages locally; however as far as I could tell it only gives access to the DESCRIPTION files. RSiteSearch, and its web equivalent, seem to access an online database of all CRAN packages, where presumably a list of all functions would be available. Is there some way of accessing this information?

Thanks.

Edit: I know sos::findFn, utils::RSiteSearch and search.r-project; what I would like is to get the raw data that these tools use.

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • 2
    Did you see http://finzi.psych.upenn.edu/~baron/notes.namazu.txt. It looks like it includes the methods used to build the search.r-project DB, which looks like what sos uses as well. – Jesse Anderson Jul 08 '12 at 03:31
  • @blindJesse no I had not, thanks! It looks like they install all packages... so I guess the solution would be to ask them nicely to produce such a list as a downloadable file. – baptiste Jul 08 '12 at 03:49

2 Answers2

7

You can use the sos package, for example:

library(sos)
findFn("adply")

The output is an html including links to online documentation packages.

flodel
  • 87,577
  • 21
  • 185
  • 223
  • Yes. `sos::findFn` is both faster than the system "??" function, as well as covering hte full range of CRAN, while "??" only covers installed packages. – IRTFM Jul 08 '12 at 02:08
  • thanks, but I'm looking for a list of functions that I could download once and use without internet access. There must be some database at [search.r-project](http://search.r-project.org/). – baptiste Jul 08 '12 at 03:10
  • 1
    Looking at the body of `sos::findFn`, it seems to be using a CGI script at http://search.r-project.org/cgi-bin/namazu.cgi which does a web search within http://finzi.psych.upenn.edu/R/library/. My gut feeling is there is no such database, just this big library of unpacked packages to parse through. – flodel Jul 08 '12 at 03:52
4

collidr package will give you this

library(collidr)
collidr::CRAN_packages_and_functions()

It will return a list of packages and their functions from CRAN i.e.


#          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
#    ...             ...                           ...
# 294181            ZVCV                          getX
# 294182            ZVCV              helper_functions
# 294183            ZVCV                           VDP
# 294184            ZVCV                          zvcv
# 294185            ZVCV                  ZVCV_package
# 294186             zyp                   confint.zyp
# 294187             zyp                           zyp
# 294188             zyp                       zyp.sen
# 294189             zyp                 zyp.trend.csv
# 294190             zyp              zyp.trend.vector

Danny
  • 448
  • 3
  • 15
stevec
  • 41,291
  • 27
  • 223
  • 311
  • 1
    The function is now called `collidr::CRAN_packages_and_functions()`. – Danny Feb 24 '20 at 07:42
  • @Danny `collidr::getCRAN()` may also be useful (as it's more up to date, although it is also slower; ~10 seconds for me) – stevec Feb 24 '20 at 10:14