diff --git a/DESCRIPTION b/DESCRIPTION index 6794be7..0569efc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,3 +10,4 @@ License: MIT + file LICENSE Encoding: UTF-8 LazyData: true RoxygenNote: 6.1.0 +Imports: prettycode diff --git a/NAMESPACE b/NAMESPACE index c30a04b..6292661 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ S3method("?","function") S3method("?",default) export("?") export(felp) +importFrom(prettycode,highlight) importFrom(utils,"?") importFrom(utils,help) importFrom(utils,savehistory) diff --git a/NEWS.md b/NEWS.md index 9e29014..4b1aefa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# felp 0.1.2 + +- Use `prettycode:::print.function()` + # felp 0.1.1 - Added S3 version of `?` diff --git a/R/felp.R b/R/felp.R index dd6cf9c..a2c8792 100644 --- a/R/felp.R +++ b/R/felp.R @@ -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)) )) } - -