Skip to content

Commit

Permalink
Doc tweaks (#131)
Browse files Browse the repository at this point in the history
* Combine set and remove docs
* Use simpler for multiple exports
* Remove full stops from headings
  • Loading branch information
hadley authored Jun 14, 2024
1 parent 9dcfe92 commit b2a2689
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 72 deletions.
2 changes: 1 addition & 1 deletion R/eval.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Evaluate input and return all details of evaluation.
#' Evaluate input and return all details of evaluation
#'
#' Compare to [eval()], `evaluate` captures all of the
#' information necessary to recreate the output as if you had copied and pasted
Expand Down
32 changes: 10 additions & 22 deletions R/hooks.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Set hooks.
#' Set and remove hooks
#'
#' This wraps the base [setHook()] function to provide a return
#' This interface wraps the base [setHook()] function to provide a return
#' value that makes it easy to undo.
#'
#' @param hooks a named list of hooks - each hook can either be a function or
Expand All @@ -9,10 +9,14 @@
#' @keywords internal
#' @export
#' @examples
#' new <- list(before.plot.new = function() print("Plotted!"))
#' hooks <- set_hooks(new)
#' new1 <- list(before.plot.new = function() print("Plotted!"))
#' new2 <- list(before.plot.new = function() print("Plotted Again!"))
#' set_hooks(new1)
#' set_hooks(new2)
#' plot(1)
#' set_hooks(hooks, "replace")
#' remove_hooks(new1)
#' plot(1)
#' remove_hooks(new2)
#' plot(1)
set_hooks <- function(hooks, action = "append") {
old <- list()
Expand All @@ -23,23 +27,8 @@ set_hooks <- function(hooks, action = "append") {
invisible(old)
}

#' Remove hooks.
#'
#' This provides a way to remove previously set hook values.
#'
#' @inheritParams set_hooks
#' @keywords internal
#' @rdname set_hooks
#' @export
#' @examples
#' new1 <- list(before.plot.new = function() print("Plotted!"))
#' new2 <- list(before.plot.new = function() print("Plotted Again!"))
#' set_hooks(new1)
#' set_hooks(new2)
#' plot(1)
#' remove_hooks(new1)
#' plot(1)
#' remove_hooks(new2)
#' plot(1)
remove_hooks <- function(hooks) {
for (hook_name in names(hooks)) {
hook <- getHook(hook_name)
Expand All @@ -49,4 +38,3 @@ remove_hooks <- function(hooks) {
setHook(hook_name, hook, "replace")
}
}

11 changes: 8 additions & 3 deletions R/output.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#' Object class tests
#' @export is.message is.warning is.error is.value is.source is.recordedplot
#' @aliases is.message is.warning is.error is.value is.source is.recordedplot
#'
#' @keywords internal
#' @rdname is.message
#' @export
is.message <- function(x) inherits(x, "message")
#' @rdname is.message
#' @export
is.warning <- function(x) inherits(x, "warning")
#' @rdname is.message
#' @export
is.error <- function(x) inherits(x, "error")
#' @rdname is.message
#' @export
is.value <- function(x) inherits(x, "value")
#' @rdname is.message
#' @export
is.source <- function(x) inherits(x, "source")
#' @rdname is.message
#' @export
is.recordedplot <- function(x) inherits(x, "recordedplot")

new_value <- function(value, visible = TRUE) {
Expand Down Expand Up @@ -42,7 +47,7 @@ classes <- function(x) vapply(x, function(x) class(x)[1], character(1))

render <- function(x) if (isS4(x)) methods::show(x) else print(x)

#' Custom output handlers.
#' Custom output handlers
#'
#' An `output_handler` handles the results of [evaluate()],
#' including the values, graphics, conditions. Each type of output is handled by
Expand Down
2 changes: 1 addition & 1 deletion R/parse.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Parse, retaining comments.
#' Parse, retaining comments
#'
#' Works very similarly to parse, but also keeps original formatting and
#' comments.
Expand Down
2 changes: 1 addition & 1 deletion R/replay.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Replay a list of evaluated results.
#' Replay a list of evaluated results
#'
#' Replay a list of evaluated results, as if you'd run them in an R
#' terminal.
Expand Down
4 changes: 2 additions & 2 deletions R/traceback.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Generate a traceback from a list of calls.
#' Generate a traceback from a list of calls
#'
#' @param callstack stack of calls, as generated by (e.g.)
#' [base::sys.calls()]
Expand All @@ -17,7 +17,7 @@ create_traceback <- function(callstack) {
calls
}

#' Try, capturing stack on error.
#' Try, capturing stack on error
#'
#' This is a variant of [tryCatch()] that also captures the call
#' stack if an error occurs.
Expand Down
2 changes: 1 addition & 1 deletion R/watcher.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Watch for changes in output, text and graphical.
#' Watch for changes in output, text and graphics
#'
#' @param debug activate debug mode where output will be both printed to
#' screen and captured.
Expand Down
4 changes: 2 additions & 2 deletions man/create_traceback.Rd

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

2 changes: 1 addition & 1 deletion man/evaluate.Rd

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

2 changes: 1 addition & 1 deletion man/new_output_handler.Rd

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

2 changes: 1 addition & 1 deletion man/parse_all.Rd

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

27 changes: 0 additions & 27 deletions man/remove_hooks.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/replay.Rd

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

17 changes: 12 additions & 5 deletions man/set_hooks.Rd

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

2 changes: 1 addition & 1 deletion man/try_capture_stack.Rd

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

4 changes: 2 additions & 2 deletions man/watchout.Rd

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

0 comments on commit b2a2689

Please sign in to comment.