Skip to contents

A shrthnd_tbl() has three sets of annotations that can be defined: a title, a source_note and a set of general notes. This family of functions allows you to view and modify these notes.

Usage

annotations(x)

shrthnd_title(x)

shrthnd_title(x) <- value

set_title(x, value, .overwrite = FALSE)

shrthnd_source_note(x)

shrthnd_source_note(x) <- value

set_source_note(x, value, .overwrite = FALSE)

shrthnd_notes(x)

shrthnd_notes(x) <- value

set_notes(x, value, .overwrite = FALSE)

add_notes(x, value, .add_before = Inf)

add_notes(x) <- value

set_tbl_antn(
  x,
  what = c("title", "source_note", "notes"),
  value,
  .overwrite = FALSE,
  .add = FALSE,
  .add_before = Inf
)

Arguments

x

A shrthnd_tbl() object

value

The value to set

.overwrite

Whether an existing value should be overwritten

.add_before

When adding notes, where to add the note (defaults to the end of the current set of notes)

what

Which note to set, one of title, source_note or notes

.add

When what = "notes", whether to append to the existing set of notes

Value

For shrthnd_title(), shrthnd_source_note() and shrthnd_notes()

a character vector of the note(s). For the setting functions returns invisibly either x if the attribute was set or NULL if not.

Details

Use annotations() to see the all the annotations associated with a shrthnd_tbl() object.

Use shrthnd_title(), shrthnd_source_note() and shrthnd_notes() get the relevant annotations(s) of a shrthnd_tbl() object. Passing a value to these functions (e.g. shrthnd_title(x) <- "My title") will set the value of these annotation, overwriting the existing value(s).

set_title(), set_source_note(), and set_notes() also allow you to set the value of these annotations. By default they will not permit overwriting of existing values, setting .overwrite = TRUE permits this.

add_notes() allows you to append notes to the existing set of general notes.

set_tbl_antn() is a low level helper function that powers the assignment operations.

Examples

x <- c("12", "34.567", "[c]", "NA", "56.78[e]", "78.9", "90.123[e]")
sh_x <- shrthnd_num(x, c("[c]", "[e]"))
tbl <- tibble::tibble(x = x, sh_x = sh_x)

sh_tbl <- shrthnd_tbl(tbl) |>
  set_title("My Example Table") |>
  set_source_note("Shrthnd documentation (2023)") |>
  set_notes(c("Note 1", "Note 2"))

sh_tbl
#> # Title:    My Example Table
#> # A tibble: 7 × 2
#>   x              sh_x
#>   <chr>      <sh_dbl>
#> 1 12        12.00    
#> 2 34.567    34.57    
#> 3 [c]          NA [c]
#> 4 NA           NA    
#> 5 56.78[e]  56.78 [e]
#> 6 78.9      78.90    
#> 7 90.123[e] 90.12 [e]
#> # ☰ Source: Shrthnd documentation (2023)
#> # ☰ There are 2 notes, use `annotations(x)` to view

annotations(sh_tbl)
#> ── Notes for `sh_tbl` ──────────────────────────────────────────────────────────
#> Title: My Example Table
#> Source: Shrthnd documentation (2023)
#> Notes:
#> • Note 1
#> • Note 2

shrthnd_title(sh_tbl)
#> [1] "My Example Table"
shrthnd_source_note(sh_tbl)
#> [1] "Shrthnd documentation (2023)"
shrthnd_notes(sh_tbl)
#> [1] "Note 1" "Note 2"

add_notes(sh_tbl) <- "Note 3"
shrthnd_notes(sh_tbl)
#> [1] "Note 1" "Note 2" "Note 3"