-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `felp()` has more consistent arguments to `utils::help` by changing a name of first argument to "topic" from "x". - Pseudo-postfix operator `?.` supports arguments other than fucntions.
- Loading branch information
Showing
8 changed files
with
48 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
#' Returns source and help of a function simultaneously | ||
#' | ||
#' @param x a name or character string specifying the function for which help and source are sought. Package to be sought can also be defined simultaneously if x is specified in the style of package::name or package:::name | ||
#' @param package a name or character string specifying the package for which help and source are sought. If the package is specified by x, this parameter is neglected, or NULL (default). | ||
#' @param ... other arguments passed to help | ||
#' @param topic A name or character string specifying the function for which help and source are sought. Package to be sought can also be defined simultaneously if x is specified in the style of package::name or package:::name | ||
#' @param package A name or character string specifying the package for which help and source are sought. If the package is specified by x, this parameter is neglected, or NULL (default). | ||
#' @param ... Other arguments passed to help | ||
#' @importFrom utils help | ||
#' @export | ||
#' | ||
felp <- function (x, package = NULL, ...) { | ||
# convert package::name to list("name", "package", "`::`) | ||
# if x = name or "name", input = list("name") | ||
input <- if (is.character(x)) { | ||
list(x) | ||
} else { | ||
rev(lapply(substitute(x), deparse)) | ||
} | ||
|
||
# Package to look for help of the function | ||
if (is.name(p <- substitute(package))) { | ||
package <- as.character(p) | ||
} | ||
package <- c(package, input[2][[1]]) | ||
felp <- function(topic, package = NULL, ...) { | ||
# 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 | ||
|
||
# Print source of the function | ||
prettycode:::print.function(get( | ||
input[[1]], | ||
envir = `if`(is.null(package), parent.frame(), asNamespace(package)) | ||
t[1L], envir = `if`(is.null(p), parent.frame(), asNamespace(p)) | ||
)) | ||
|
||
try(help(input[[1]], package = package[1], ...)) | ||
try(help(t[1L], p[1L], ...)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
#' S3 version of [utils::`?`] | ||
#' | ||
#' @inheritParams ? | ||
#' @param e1 | ||
#' A topic ought to be documented. Refer to `topic` argument described in `` utils::`?` ``. | ||
#' @param e2 | ||
#' `.` equals to `missing(e2)`. If else, see `type` argument described in `` utils::`?` ``. | ||
#' @rdname question | ||
#' @aliases ? | ||
#' @export | ||
`?` <- function() UseMethod("?") | ||
`?` <- function(e1, e2) UseMethod("?") | ||
|
||
#' @rdname question | ||
#' @aliases ? | ||
#' @inheritParams ? | ||
#' @export | ||
`?.function` <- function() { | ||
if(!missing(e2) && as.character(substitute(e2)) != ".") { | ||
NextMethod() | ||
} | ||
.felp <- felp | ||
formals(.felp)$x <- substitute(e1) | ||
.felp() | ||
`?.function` <- function(e1, e2) { | ||
if (!missing(e2) && as.character(substitute(e2)) != ".") NextMethod() | ||
do.call(felp, list(topic = substitute(e1))) | ||
} | ||
|
||
#' @rdname question | ||
#' @aliases ? | ||
#' @inheritParams ? | ||
#' @importFrom utils ? | ||
#' @export | ||
`?.default` <- utils::"?" | ||
|
||
formals(`?`) <- formals(`?.function`) <- formals(`?.default`) | ||
`?.default` <- function(e1, e2) { | ||
.arg <- list(e1 = substitute(e1)) | ||
.e2 <- substitute(e2) | ||
if (!missing(.e2) && as.character(.e2) != ".") .arg$e2 <- .e2 | ||
do.call(utils::"?", .arg) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.