Access list of functions and metadata for github dev R package

Hi All,

I'm currently co-developing an R package on github which can be installed using devtools::install_github('repo/pkgname), as usual.

We have diligently used roxygen2 to document the individual functions.
We have split the functions into "internal" (@keywords internal) vs. "external" (@export)
so that the user gets to use the external functions i.e.pkgname::external_<fn_name>
and access documentation. They can also use ::: to access the internal
functions if they wish.

For some meta analysis of our package it would be nice to have a functionality
that produced a tidy tibble with the following columns:

  • function name,
  • function type i.e. internal/external (accessible by :: or ::: to the user)
  • More metadata e.g. another column containing parameter names for each function i.e. @param values
  • documentation strings for each parameter

As a crude version (non-tibble format) for say dplyr. One can do something like:

library(dplyr) # Assume installed already
ls('package:dplyr')

This produces a character vector of function names, but not a tidy tibble with more
useful metadata.

Ideally we would be able to produce this tibble after doing devtools::load_all(".") in
our package development, to track changes in real-time.

Are there any existing R packages that can help with such a query? Or can such a function be
developed for this using existing R packages?

Please note: This is now cross-posted here since it hasn't received a response here for a few days.

I have an answer to my question, which may help others. It turns out this metadata can be accessed using
the amazing pkgdown package.

See below for code to use when you have opened an RStudio project attached to a package
you are developing (using devtools):

# Setup - install required libraries
# install.packages(c("pkgdown", "here"))

# If you are in your local package directory, run the following
# to get the required package metadata
pkg <- pkgdown::as_pkgdown(pkg = here::here())

# Inspect the topics object, which contains function metadata
pkg$topics %>% dplyr::glimpse()

# Get list of all functions and just required metadata
pkg_fns_all <- pkg$topics %>%
    dplyr::select(name, file_in, internal)

# Get the non-internal functions, acccessed using pkgname::function
pkg_fns_user <- pkg_fns_all %>% dplyr::filter(!internal)

# Get the internal functions, acccessed using pkgname:::function
pkg_fns_internal <- pkg_fns_all %>% dplyr::filter(internal)

Hope this helps others :slight_smile:

A few small outstanding items:

  • I'm not sure how to get access to individual function @param values from the
    above, but if anyone can add some details around that it would be useful.
  • I'm not sure how to apply this to CRAN installed packages on my system e.g. dplyr

If anyone has the time to look into this and let me know, it would be useful for
the future to others as well.

I think using pkgdown's source code as inspiration is a good idea.

The experimental pkgreport package has a function for extracting arguments: https://github.com/ropenscilabs/pkginspector.

Your initial question also made me think of the pkgapi package by @Gabor but it doesn't access parameters.

Thanks @maelle for the great suggestions. Also thanks for all of your great blogposts. I've
learned a lot from them.

I think your pkginspector suggestion looks very useful, especially for accessing metadata for installed CRAN packages.
I was curious to see that the last commit was from a couple of years ago and it may be
that the package is not actively maintained? Still very cool tho!

Due to the inactive maintenance I was thinking perhaps pkgdown may be able to access
parameters in a tidy data format, since it must need this feature to prepare the "References"
section for each function. I think there may be some functionality here that could do this
parsing, but will have to explore more.

Appreciate the awesome prompts and new directions. If I find anything further I will be sure
to post back :slight_smile:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.