Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add set_note() #77

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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