-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfelp.R
More file actions
37 lines (33 loc) · 1.03 KB
/
felp.R
File metadata and controls
37 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#' Functional help which displays structure of an object in addition to help
#'
#' Structure of object is returned by `str()`.
#' For a function, its source is returned instead of `str()`.
#'
#' @inheritParams utils::help
#' @inheritDotParams utils::help -topic -package
#'
#' @examples
#' # Identical to help(identity); print(identity)
#' felp(identity)
#'
#' # Identical to help(iris); str(iris)
#' felp(iris)
#'
#' # Identical to help(package = stats)
#' felp(package = stats)
#'
#'
#' @importFrom utils help str
#' @export
#'
felp <- function(topic, package = NULL, ...) {
# Display package document
if (missing(topic)) return(do.call(help, list(package = substitute(package), ...)))
# Convert `package::name` to c("name", "package", "`::`") or `name` to "name"
t <- rev(as.character(substitute(topic)))
p <- c(as.character(substitute(package)), t[2L])[1L]
if (is.na(p)) p <- NULL
# Display structure and document of an object
str(get(t[1L], envir = `if`(is.null(p), parent.frame(), asNamespace(p))))
try(help(t[1L], p[1L], ...))
}