Skip to content

Commit

Permalink
merge dev and bump version to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy authored May 26, 2019
2 parents 8b4a45f + 290f5c4 commit f03cc64
Show file tree
Hide file tree
Showing 30 changed files with 2,575 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ vignettes/*.pdf
*.utf8.md
*.knit.md
.Rproj.user
inst/doc
18 changes: 14 additions & 4 deletions DESCRIPTION
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
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method("?","function")
S3method("?",default)
export("?")
export(felp)
importFrom(utils,"?")
Expand Down
29 changes: 23 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
# felp 0.1.3.9000
# felp 0.2.0

# Major changes

- `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.
- `felp()` and `?` returns structure of a value specified to the first argument
if possible. If function is specified, the source of function is returned
instead of the structure.
- `felp()`
- improves consistency with `utils::help` in terms of arguments
- supports to display package documentation just like `help(package = )`
- Pseudo-postfix operators
- `?.` supports arguments other than fucntions.
- `?p` is added to display document of a package.
- Updates on documents with `pkgdown` site

# felp 0.1.3.9000

Tagged, but not released.

## Major changes

- 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.

## Minor changes

# Minor changes
- felp() is simplified.

- `felp()` is simplified.

# felp 0.1.3

Expand Down
4 changes: 4 additions & 0 deletions R/data.R
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)
23 changes: 12 additions & 11 deletions R/felp.R
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], ...))

}
39 changes: 19 additions & 20 deletions R/question.R
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))
}
5 changes: 5 additions & 0 deletions R/str.R
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, ...)
}
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# felp

felp is a short of **f**unction h**elp**.
This package provides functions to print
source and help of a function simultaneously.
`felp` is a short of **f**unctional h**elp**

- the `?.` pseudo-post fix operator to simultaneously display a help document
and a structure of an object
- the `?p` pseudo-post fix operator to display document of a package

and more in [Syntax](#Syntax) and [Get started](https://felp.atusy.net/articles/felp.html)

## Installation

Expand All @@ -12,17 +16,24 @@ Copy & paste:
source("https://install-github.me/atusy/felp")
```

## Example

These provide same results to print help and source of `help`.
## Syntax

``` r
help?.
utils::help?.
# ? operator
?help
?utils::help

# ?. pseudo postfix operator for functions and objects
help?.
utils::help?.

# ?p pseudo postfix operator for packages
utils?.

# felp as an extention of utils::help
felp(help)
felp("help")
felp(utils::help)
felp(help, utils)
felp(package = utils)
```
146 changes: 146 additions & 0 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f03cc64

Please sign in to comment.