pacman
pacman copied to clipboard
p_functions_title: Get function titles
I used this function at work. DOn't know if it makes the cut but documenting it here for now.
#' Package Functions
#'
#' List the functions from a package.
#'
#' @rdname p_functions
#' @param package Name of the package you want the list of functions for.
#' @param all logical. If \code{TRUE} all of the functions from the package
#' will be displayed regardless of whether they're exported or not.
#' @param character.only logical. If \code{TRUE} the input is a variable
#' containing the package name.
#' @keywords function package
#' @export
#' @examples
#' p_functions_title()
#' p_funs_title()
#' p_functions_title(pacman)
p_functions_title <-
function (package, character.only = FALSE){
if (!character.only & is.name(substitute(package))) {
package <- deparse(substitute(package))
}
if (identical(package, character(0))) {
package <- "base"
}
m <- pacman::p_funs(package, character.only = TRUE)
db <- tools::Rd_db(package)
therd <- db[grep(paste(sprintf("%s.Rd", m), collapse="|"), names(db), value = TRUE)]
titles <- sapply(sprintf("%s.Rd", m), function(x) therd[[x]][[1]][[1]])
titles[grepl("^NULL$", titles)] <- NA
out <-data.frame(
'function' = m,
'title' = unlist(titles, use.names = FALSE),
stringsAsFactors = FALSE, check.names = FALSE
)
class(out) <- c("wide_table", class(out))
out
}
#' @rdname p_functions
#' @export
p_funs_title <- p_functions_title
It might be better if we just merge that into p_funs. Just like a title=TRUE
kind of parameter.