Skip to content

Commit

Permalink
Merge pull request #77 from jmbarbone/70-set-note
Browse files Browse the repository at this point in the history
add `set_note()`
  • Loading branch information
jmbarbone committed Jan 14, 2022
2 parents d541cf8 + 34104c4 commit 38bcd7b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export(save_source)
export(select_na_cols)
export(set_names0)
export(set_not_available)
export(set_note)
export(shell_exec)
export(simpleTimeReport)
export(smallest_file)
Expand Down
15 changes: 10 additions & 5 deletions R/note.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
#' The type of object assigned to the note is not restricted, so user beware of
#' odd prints or additional features added to the notes fun.
#'
#' When assigning a note (with `note<-`) the `noted` class is added to the
#' object. This allows the `print.noted` class to be dispatched and for the
#' note to be printed every time the object is called/printed and the next print
#' method used. However, it will not be called when not `interactive()`
#' When assigning a note (with `note<-`, and its alias `set_note()`) the `noted`
#' class is added to the object. This allows the `print.noted` class to be
#' dispatched and for the note to be printed every time the object is
#' called/printed and the next print method used. However, it will not be
#' called when not `interactive()`
#'
#' @param x An object
#' @param value The note to attach; if `NULL` will remove the note and the class
#' `noted` from the object.
#' @return
#' * `note<-` will return `x` (with the `"note"` attribute assigned)
#' * `note<-`, `set_note()` will return `x` (with the `"note"` attribute assigned)
#' * `note()` will retrieve the `"note"` attribute
#'
#' @examples
Expand Down Expand Up @@ -63,6 +64,10 @@
x
}

#' @export
#' @rdname note
set_note <- `note<-`

#' @export
#' @rdname note
note <- function(x) {
Expand Down
14 changes: 9 additions & 5 deletions man/note.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-note.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ test_that("note() work", {
note(x) <- NULL
expect_null(attr(x, "note"))
expect_identical(class(x), "character")

x <- "x"
y <- set_note(x, "this note")
note(x) <- "this note"
expect_identical(x, y)
})

test_that("print.noted() passes to next methods [67]", {
Expand Down

0 comments on commit 38bcd7b

Please sign in to comment.