Skip to content

Commit

Permalink
Use prettycode:::print.function to improve output
Browse files Browse the repository at this point in the history
In addition, the body of `felp()` is simplified.
  • Loading branch information
atusy committed Nov 17, 2018
1 parent ff9c821 commit 4979e1b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
Imports: prettycode
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method("?","function")
S3method("?",default)
export("?")
export(felp)
importFrom(prettycode,highlight)
importFrom(utils,"?")
importFrom(utils,help)
importFrom(utils,savehistory)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# felp 0.1.2

- Use `prettycode:::print.function()`

# felp 0.1.1

- Added S3 version of `?`
Expand Down
28 changes: 14 additions & 14 deletions R/felp.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#' @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
#' @importFrom prettycode highlight
#' @export
#'
felp <- function(x, package = NULL, ...) {
x_substituted <- substitute(x)
# convert package::name to list("name", "package", "`::`)
# if x = name, input = list("name")
input <- if(is.character(x))
list(x)
else
rev(lapply(as.list(substitute(x)), deparse))
input <- if(is.character(x)) {
list(x)
} else {
rev(lapply(x_substituted, deparse))
}

# Package to look for help of the function
if (!missing(package) && (p <- substitute(package))) {
package <- as.character(p)
}
package <- c(package, input[2][[1]])

# print help
if(is.null(package))
try(print(help(input[[1]], ...)))
else
try(print(help(input[[1]], package = package[1], ...)))
# Try to find help
try(print(help(input[[1]], package = package[1], ...)))

# print source of the function
base::print.function(get(
# Print source of the function
prettycode:::print.function(get(
input[[1]],
envir = if(is.null(package)) .GlobalEnv else getNamespace(package)
envir = `if`(is.null(package), parent.frame(), getNamespace(package))
))
}


0 comments on commit 4979e1b

Please sign in to comment.