-
-
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.
- Loading branch information
Showing
30 changed files
with
2,575 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ vignettes/*.pdf | |
*.utf8.md | ||
*.knit.md | ||
.Rproj.user | ||
inst/doc |
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,12 +1,22 @@ | ||
Package: felp | ||
Type: Package | ||
Title: Print function and its help simultaneously | ||
Version: 0.1.3 | ||
Title: Functional help for functions, objects, and packages | ||
Version: 0.2.0 | ||
Author: YASUMOTO Atsushi | ||
Maintainer: YASUMOTO Atsushi <[email protected]> | ||
Description: Try `?help` and `help?.`. | ||
Description: This package extends utils::`?` by pseudo-postfix operators `?.` for objects and `?p` for packages. For objects, a result of `str` or `print.function` is also displayed. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 6.1.1 | ||
Imports: prettycode | ||
Imports: | ||
prettycode | ||
Suggests: | ||
knitr, | ||
pkgdown, | ||
printr, | ||
rmarkdown, | ||
roxygen2 | ||
VignetteBuilder: | ||
knitr |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#' A dummy data for felp | ||
#' | ||
#' @docType data | ||
dummy <- list(a = "a", b = 1) |
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,24 +1,25 @@ | ||
#' Returns source and help of a function simultaneously | ||
#' Functional help which displays structure of an object in addition 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 | ||
#' 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 | ||
#' @importFrom utils help | ||
#' @export | ||
#' | ||
felp <- function(topic, package = NULL, ...) { | ||
# convert package::name to c("name", "package", "`::`") | ||
# or name to "name" | ||
# 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 | ||
|
||
# Print source of the function | ||
prettycode:::print.function(get( | ||
t[1L], envir = `if`(is.null(p), parent.frame(), asNamespace(p)) | ||
)) | ||
# 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], ...)) | ||
|
||
} |
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,29 +1,28 @@ | ||
#' S3 version of [utils::`?`] | ||
#' Functional help with `?` operator | ||
#' | ||
#' Displays help and structure of an object, or help of a package. | ||
#' Two syntaxes are added to those of `utils::?`. | ||
#' One is `object?.` which works as if `?object`. | ||
#' Another is `package?p` which works as if `help(package = package)` | ||
#' | ||
#' @param e1 | ||
#' A topic ought to be documented. Refer to `topic` argument described in `` utils::`?` ``. | ||
#' A topic of document. | ||
#' 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(e1, e2) UseMethod("?") | ||
|
||
#' @rdname question | ||
#' @aliases ? | ||
#' @export | ||
`?.function` <- function(e1, e2) { | ||
if (!missing(e2) && as.character(substitute(e2)) != ".") NextMethod() | ||
do.call(felp, list(topic = substitute(e1))) | ||
} | ||
|
||
#' `.` and `p` have special meanings as documented above. | ||
#' Otherwise, `e2` is same as `type` argument of `` utils::`?` ``. | ||
#' | ||
#' @rdname question | ||
#' @aliases ? | ||
#' | ||
#' @importFrom utils ? | ||
#' @export | ||
`?.default` <- function(e1, e2) { | ||
.arg <- list(e1 = substitute(e1)) | ||
`?` <- function(e1, e2) { | ||
.e1 <- substitute(e1) | ||
.e2 <- substitute(e2) | ||
if (!missing(.e2) && as.character(.e2) != ".") .arg$e2 <- .e2 | ||
do.call(utils::"?", .arg) | ||
if (missing(e2)) return(do.call(felp, list(topic = .e1))) | ||
.e2_chr <- as.character(.e2) | ||
if (.e2_chr == ".") return(do.call(felp, list(topic = .e1))) | ||
if (.e2_chr == "p") return(do.call(help, list(package = .e1))) | ||
do.call(utils::`?`, list(e1 = .e1, e2 = .e2)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#' str for function | ||
#' @noRd | ||
str.function <- function(object, ...) { | ||
prettycode:::print.function(object, ...) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.