From aad1da29dcfc3dac9f7b81dcb3af68d2a4cd7142 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 7 Oct 2024 13:51:10 +0200 Subject: [PATCH 1/7] add `label_lut()` --- R/label-lut.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 R/label-lut.R diff --git a/R/label-lut.R b/R/label-lut.R new file mode 100644 index 00000000..a42382c7 --- /dev/null +++ b/R/label-lut.R @@ -0,0 +1,22 @@ + +label_lut <- function(lut = character(), nomatch = NULL) { + + if (!is.character(lut)) { + cli::cli_abort("The {.arg lut} argument must be a character vector.") + } + if (!is_named2(lut)) { + cli::cli_abort("The {.arg lut} argument must have names.") + } + names <- names(lut) + values <- unname(lut) + + force(nomatch) + + function(x) { + i <- match(x, names, nomatch = NA_integer_) + out <- values[i] + missing <- is.na(i) + out[missing] <- if (is.null(nomatch)) x[missing] else nomatch + out + } +} From e1d0e49421f1a809ad9947e0f3aeeaf39e3bd27c Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 7 Oct 2024 13:53:16 +0200 Subject: [PATCH 2/7] add test --- tests/testthat/test-label-lut.R | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/testthat/test-label-lut.R diff --git a/tests/testthat/test-label-lut.R b/tests/testthat/test-label-lut.R new file mode 100644 index 00000000..36df0670 --- /dev/null +++ b/tests/testthat/test-label-lut.R @@ -0,0 +1,11 @@ +test_that("label_lut gives correct answers", { + + short <- c("A", "B", "C") + lut <- c("A" = "Apple", "C" = "Cherry", "D" = "Date") + + expect_equal(label_lut(lut)(short), c("Apple", "B", "Cherry")) + expect_equal( + label_lut(lut, nomatch = "Banana")(short), + c("Apple", "Banana", "Cherry") + ) +}) From 1679a57b23028acb863c92f2606a76342aae59e0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 7 Oct 2024 16:57:41 +0200 Subject: [PATCH 3/7] document --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 2 ++ R/label-lut.R | 31 ++++++++++++++++++++++++++++++ man/label_lut.Rd | 47 ++++++++++++++++++++++++++++++++++++++++++++++ man/label_parse.Rd | 1 + man/label_wrap.Rd | 1 + 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 man/label_lut.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 38d99259..0ee8fe58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,4 +39,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 LazyLoad: yes Roxygen: list(markdown = TRUE, r6 = FALSE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 323e34ba..382b0205 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -117,6 +117,7 @@ export(label_date) export(label_date_short) export(label_dollar) export(label_log) +export(label_lut) export(label_math) export(label_number) export(label_number_auto) diff --git a/NEWS.md b/NEWS.md index 9646d4a5..4f29f801 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # scales (development version) +* New `label_lut()` for named lookup of labels (#458). + # scales 1.3.0 ## Better type support diff --git a/R/label-lut.R b/R/label-lut.R index a42382c7..08216b86 100644 --- a/R/label-lut.R +++ b/R/label-lut.R @@ -1,4 +1,35 @@ +#' Labels from lookup tables +#' +#' Use `label_lut()` for looking up succinct breaks in a named character vector +#' giving complete labels. +#' +#' @param lut A named character vector of labels. The names are expected to +#' match the breaks, and the values become the labels. +#' @param nomatch A string to label breaks that do not match any name in `lut`. +#' When `NULL` (default), the breaks are not translated but are kept as-is. +#' +#' @return A labeller function that takes a character vector of breaks and +#' returns a character vector of labels. +#' @export +#' @family labels for discrete scales +#' @examples +#' # Example lookup table +#' lut <- c( +#' "4" = "four wheel drive", +#' "r" = "rear wheel drive", +#' "f" = "front wheel drive" +#' ) +#' +#' # Typical usage +#' demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +#' # By default, extra values ('w') will remain as-is +#' demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +#' # Alternatively, you can relabel extra values +#' demo_discrete( +#' c("4", "r", "f", "w"), +#' labels = label_lut(lut, nomatch = "unknown") +#' ) label_lut <- function(lut = character(), nomatch = NULL) { if (!is.character(lut)) { diff --git a/man/label_lut.Rd b/man/label_lut.Rd new file mode 100644 index 00000000..21fa34a5 --- /dev/null +++ b/man/label_lut.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/label-lut.R +\name{label_lut} +\alias{label_lut} +\title{Labels from lookup tables} +\usage{ +label_lut(lut = character(), nomatch = NULL) +} +\arguments{ +\item{lut}{A named character vector of labels. The names are expected to +match the breaks, and the values become the labels.} + +\item{nomatch}{A string to label breaks that do not match any name in \code{lut}. +When \code{NULL} (default), the breaks are not translated but are kept as-is.} +} +\value{ +A labeller function that takes a character vector of breaks and +returns a character vector of labels. +} +\description{ +Use \code{label_lut()} for looking up succinct breaks in a named character vector +giving complete labels. +} +\examples{ +# Example lookup table +lut <- c( + "4" = "four wheel drive", + "r" = "rear wheel drive", + "f" = "front wheel drive" +) + +# Typical usage +demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +# By default, extra values ('w') will remain as-is +demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +# Alternatively, you can relabel extra values +demo_discrete( + c("4", "r", "f", "w"), + labels = label_lut(lut, nomatch = "unknown") +) +} +\seealso{ +Other labels for discrete scales: +\code{\link{label_parse}()}, +\code{\link{label_wrap}()} +} +\concept{labels for discrete scales} diff --git a/man/label_parse.Rd b/man/label_parse.Rd index 7dd7d29d..d9f1c6a1 100644 --- a/man/label_parse.Rd +++ b/man/label_parse.Rd @@ -56,6 +56,7 @@ Other labels for continuous scales: \code{\link{label_scientific}()} Other labels for discrete scales: +\code{\link{label_lut}()}, \code{\link{label_wrap}()} } \concept{labels for continuous scales} diff --git a/man/label_wrap.Rd b/man/label_wrap.Rd index 94862292..7e8c00f2 100644 --- a/man/label_wrap.Rd +++ b/man/label_wrap.Rd @@ -34,6 +34,7 @@ demo_discrete(x, labels = label_wrap(20)) } \seealso{ Other labels for discrete scales: +\code{\link{label_lut}()}, \code{\link{label_parse}()} } \concept{labels for discrete scales} From 29751e890024ce600d3eceb83e60c3ce6b6b0d13 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 22 Oct 2024 09:33:46 +0200 Subject: [PATCH 4/7] rename to `label_dictionary()` --- NAMESPACE | 2 +- NEWS.md | 3 +-- R/label-lut.R | 21 ++++++++++--------- man/{label_lut.Rd => label_dictionary.Rd} | 25 ++++++++++++----------- man/label_glue.Rd | 2 +- man/label_parse.Rd | 2 +- man/label_wrap.Rd | 2 +- tests/testthat/test-label-lut.R | 6 +++--- 8 files changed, 32 insertions(+), 31 deletions(-) rename man/{label_lut.Rd => label_dictionary.Rd} (55%) diff --git a/NAMESPACE b/NAMESPACE index fc16f70c..3c886227 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -120,10 +120,10 @@ export(label_comma) export(label_currency) export(label_date) export(label_date_short) +export(label_dictionary) export(label_dollar) export(label_glue) export(label_log) -export(label_lut) export(label_math) export(label_number) export(label_number_auto) diff --git a/NEWS.md b/NEWS.md index 322634b8..d2fa3e3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,8 +10,7 @@ using `get_palette()` or registered using `set_palette()` (#396). * `label_log()` has a `signed` argument for displaying negative numbers (@teunbrand, #421). - -* New `label_lut()` for named lookup of labels (#458). +* New `label_dictionary()` for named lookup of labels (#458). # scales 1.3.0 diff --git a/R/label-lut.R b/R/label-lut.R index 08216b86..0c296f86 100644 --- a/R/label-lut.R +++ b/R/label-lut.R @@ -1,13 +1,14 @@ #' Labels from lookup tables #' -#' Use `label_lut()` for looking up succinct breaks in a named character vector -#' giving complete labels. +#' Use `label_dictionary()` for looking up succinct breaks in a named character +#' vector giving complete labels. #' -#' @param lut A named character vector of labels. The names are expected to -#' match the breaks, and the values become the labels. -#' @param nomatch A string to label breaks that do not match any name in `lut`. -#' When `NULL` (default), the breaks are not translated but are kept as-is. +#' @param dictionary A named character vector of labels. The names are expected +#' to match the breaks, and the values become the labels. +#' @param nomatch A string to label breaks that do not match any name in +#' `dictionary`. When `NULL` (default), the breaks are not translated but are +#' kept as-is. #' #' @return A labeller function that takes a character vector of breaks and #' returns a character vector of labels. @@ -22,15 +23,15 @@ #' ) #' #' # Typical usage -#' demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +#' demo_discrete(c("4", "r", "f"), labels = label_dictionary(lut)) #' # By default, extra values ('w') will remain as-is -#' demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +#' demo_discrete(c("4", "r", "f", "w"), labels = label_dictionary(lut)) #' # Alternatively, you can relabel extra values #' demo_discrete( #' c("4", "r", "f", "w"), -#' labels = label_lut(lut, nomatch = "unknown") +#' labels = label_dictionary(lut, nomatch = "unknown") #' ) -label_lut <- function(lut = character(), nomatch = NULL) { +label_dictionary <- function(dictionary = character(), nomatch = NULL) { if (!is.character(lut)) { cli::cli_abort("The {.arg lut} argument must be a character vector.") diff --git a/man/label_lut.Rd b/man/label_dictionary.Rd similarity index 55% rename from man/label_lut.Rd rename to man/label_dictionary.Rd index 7729d59a..ded7a697 100644 --- a/man/label_lut.Rd +++ b/man/label_dictionary.Rd @@ -1,25 +1,26 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/label-lut.R -\name{label_lut} -\alias{label_lut} +\name{label_dictionary} +\alias{label_dictionary} \title{Labels from lookup tables} \usage{ -label_lut(lut = character(), nomatch = NULL) +label_dictionary(dictionary = character(), nomatch = NULL) } \arguments{ -\item{lut}{A named character vector of labels. The names are expected to -match the breaks, and the values become the labels.} +\item{dictionary}{A named character vector of labels. The names are expected +to match the breaks, and the values become the labels.} -\item{nomatch}{A string to label breaks that do not match any name in \code{lut}. -When \code{NULL} (default), the breaks are not translated but are kept as-is.} +\item{nomatch}{A string to label breaks that do not match any name in +\code{dictionary}. When \code{NULL} (default), the breaks are not translated but are +kept as-is.} } \value{ A labeller function that takes a character vector of breaks and returns a character vector of labels. } \description{ -Use \code{label_lut()} for looking up succinct breaks in a named character vector -giving complete labels. +Use \code{label_dictionary()} for looking up succinct breaks in a named character +vector giving complete labels. } \examples{ # Example lookup table @@ -30,13 +31,13 @@ lut <- c( ) # Typical usage -demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +demo_discrete(c("4", "r", "f"), labels = label_dictionary(lut)) # By default, extra values ('w') will remain as-is -demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +demo_discrete(c("4", "r", "f", "w"), labels = label_dictionary(lut)) # Alternatively, you can relabel extra values demo_discrete( c("4", "r", "f", "w"), - labels = label_lut(lut, nomatch = "unknown") + labels = label_dictionary(lut, nomatch = "unknown") ) } \seealso{ diff --git a/man/label_glue.Rd b/man/label_glue.Rd index cde1b02e..f4001974 100644 --- a/man/label_glue.Rd +++ b/man/label_glue.Rd @@ -51,7 +51,7 @@ Other labels for continuous scales: \code{\link{label_scientific}()} Other labels for discrete scales: -\code{\link{label_lut}()}, +\code{\link{label_dictionary}()}, \code{\link{label_parse}()}, \code{\link{label_wrap}()} } diff --git a/man/label_parse.Rd b/man/label_parse.Rd index 7e76915e..8c712aff 100644 --- a/man/label_parse.Rd +++ b/man/label_parse.Rd @@ -57,8 +57,8 @@ Other labels for continuous scales: \code{\link{label_scientific}()} Other labels for discrete scales: +\code{\link{label_dictionary}()}, \code{\link{label_glue}()}, -\code{\link{label_lut}()}, \code{\link{label_wrap}()} } \concept{labels for continuous scales} diff --git a/man/label_wrap.Rd b/man/label_wrap.Rd index 78e04a7a..f853a7bc 100644 --- a/man/label_wrap.Rd +++ b/man/label_wrap.Rd @@ -34,8 +34,8 @@ demo_discrete(x, labels = label_wrap(20)) } \seealso{ Other labels for discrete scales: +\code{\link{label_dictionary}()}, \code{\link{label_glue}()}, -\code{\link{label_lut}()}, \code{\link{label_parse}()} } \concept{labels for discrete scales} diff --git a/tests/testthat/test-label-lut.R b/tests/testthat/test-label-lut.R index 36df0670..4b692024 100644 --- a/tests/testthat/test-label-lut.R +++ b/tests/testthat/test-label-lut.R @@ -1,11 +1,11 @@ -test_that("label_lut gives correct answers", { +test_that("label_dictionary gives correct answers", { short <- c("A", "B", "C") lut <- c("A" = "Apple", "C" = "Cherry", "D" = "Date") - expect_equal(label_lut(lut)(short), c("Apple", "B", "Cherry")) + expect_equal(label__dictionary(lut)(short), c("Apple", "B", "Cherry")) expect_equal( - label_lut(lut, nomatch = "Banana")(short), + label_dictionary(lut, nomatch = "Banana")(short), c("Apple", "Banana", "Cherry") ) }) From ecaba6a6f85091535d0067d05fa4260eebe4660b Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 22 Oct 2024 09:33:46 +0200 Subject: [PATCH 5/7] rename to `label_dictionary()` --- NAMESPACE | 2 +- NEWS.md | 3 +-- R/{label-lut.R => label-dictionary.R} | 21 ++++++++++--------- man/{label_lut.Rd => label_dictionary.Rd} | 25 ++++++++++++----------- man/label_glue.Rd | 2 +- man/label_parse.Rd | 2 +- man/label_wrap.Rd | 2 +- tests/testthat/test-label-lut.R | 6 +++--- 8 files changed, 32 insertions(+), 31 deletions(-) rename R/{label-lut.R => label-dictionary.R} (62%) rename man/{label_lut.Rd => label_dictionary.Rd} (55%) diff --git a/NAMESPACE b/NAMESPACE index fc16f70c..3c886227 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -120,10 +120,10 @@ export(label_comma) export(label_currency) export(label_date) export(label_date_short) +export(label_dictionary) export(label_dollar) export(label_glue) export(label_log) -export(label_lut) export(label_math) export(label_number) export(label_number_auto) diff --git a/NEWS.md b/NEWS.md index 322634b8..d2fa3e3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,8 +10,7 @@ using `get_palette()` or registered using `set_palette()` (#396). * `label_log()` has a `signed` argument for displaying negative numbers (@teunbrand, #421). - -* New `label_lut()` for named lookup of labels (#458). +* New `label_dictionary()` for named lookup of labels (#458). # scales 1.3.0 diff --git a/R/label-lut.R b/R/label-dictionary.R similarity index 62% rename from R/label-lut.R rename to R/label-dictionary.R index 08216b86..0c296f86 100644 --- a/R/label-lut.R +++ b/R/label-dictionary.R @@ -1,13 +1,14 @@ #' Labels from lookup tables #' -#' Use `label_lut()` for looking up succinct breaks in a named character vector -#' giving complete labels. +#' Use `label_dictionary()` for looking up succinct breaks in a named character +#' vector giving complete labels. #' -#' @param lut A named character vector of labels. The names are expected to -#' match the breaks, and the values become the labels. -#' @param nomatch A string to label breaks that do not match any name in `lut`. -#' When `NULL` (default), the breaks are not translated but are kept as-is. +#' @param dictionary A named character vector of labels. The names are expected +#' to match the breaks, and the values become the labels. +#' @param nomatch A string to label breaks that do not match any name in +#' `dictionary`. When `NULL` (default), the breaks are not translated but are +#' kept as-is. #' #' @return A labeller function that takes a character vector of breaks and #' returns a character vector of labels. @@ -22,15 +23,15 @@ #' ) #' #' # Typical usage -#' demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +#' demo_discrete(c("4", "r", "f"), labels = label_dictionary(lut)) #' # By default, extra values ('w') will remain as-is -#' demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +#' demo_discrete(c("4", "r", "f", "w"), labels = label_dictionary(lut)) #' # Alternatively, you can relabel extra values #' demo_discrete( #' c("4", "r", "f", "w"), -#' labels = label_lut(lut, nomatch = "unknown") +#' labels = label_dictionary(lut, nomatch = "unknown") #' ) -label_lut <- function(lut = character(), nomatch = NULL) { +label_dictionary <- function(dictionary = character(), nomatch = NULL) { if (!is.character(lut)) { cli::cli_abort("The {.arg lut} argument must be a character vector.") diff --git a/man/label_lut.Rd b/man/label_dictionary.Rd similarity index 55% rename from man/label_lut.Rd rename to man/label_dictionary.Rd index 7729d59a..ded7a697 100644 --- a/man/label_lut.Rd +++ b/man/label_dictionary.Rd @@ -1,25 +1,26 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/label-lut.R -\name{label_lut} -\alias{label_lut} +\name{label_dictionary} +\alias{label_dictionary} \title{Labels from lookup tables} \usage{ -label_lut(lut = character(), nomatch = NULL) +label_dictionary(dictionary = character(), nomatch = NULL) } \arguments{ -\item{lut}{A named character vector of labels. The names are expected to -match the breaks, and the values become the labels.} +\item{dictionary}{A named character vector of labels. The names are expected +to match the breaks, and the values become the labels.} -\item{nomatch}{A string to label breaks that do not match any name in \code{lut}. -When \code{NULL} (default), the breaks are not translated but are kept as-is.} +\item{nomatch}{A string to label breaks that do not match any name in +\code{dictionary}. When \code{NULL} (default), the breaks are not translated but are +kept as-is.} } \value{ A labeller function that takes a character vector of breaks and returns a character vector of labels. } \description{ -Use \code{label_lut()} for looking up succinct breaks in a named character vector -giving complete labels. +Use \code{label_dictionary()} for looking up succinct breaks in a named character +vector giving complete labels. } \examples{ # Example lookup table @@ -30,13 +31,13 @@ lut <- c( ) # Typical usage -demo_discrete(c("4", "r", "f"), labels = label_lut(lut)) +demo_discrete(c("4", "r", "f"), labels = label_dictionary(lut)) # By default, extra values ('w') will remain as-is -demo_discrete(c("4", "r", "f", "w"), labels = label_lut(lut)) +demo_discrete(c("4", "r", "f", "w"), labels = label_dictionary(lut)) # Alternatively, you can relabel extra values demo_discrete( c("4", "r", "f", "w"), - labels = label_lut(lut, nomatch = "unknown") + labels = label_dictionary(lut, nomatch = "unknown") ) } \seealso{ diff --git a/man/label_glue.Rd b/man/label_glue.Rd index cde1b02e..f4001974 100644 --- a/man/label_glue.Rd +++ b/man/label_glue.Rd @@ -51,7 +51,7 @@ Other labels for continuous scales: \code{\link{label_scientific}()} Other labels for discrete scales: -\code{\link{label_lut}()}, +\code{\link{label_dictionary}()}, \code{\link{label_parse}()}, \code{\link{label_wrap}()} } diff --git a/man/label_parse.Rd b/man/label_parse.Rd index 7e76915e..8c712aff 100644 --- a/man/label_parse.Rd +++ b/man/label_parse.Rd @@ -57,8 +57,8 @@ Other labels for continuous scales: \code{\link{label_scientific}()} Other labels for discrete scales: +\code{\link{label_dictionary}()}, \code{\link{label_glue}()}, -\code{\link{label_lut}()}, \code{\link{label_wrap}()} } \concept{labels for continuous scales} diff --git a/man/label_wrap.Rd b/man/label_wrap.Rd index 78e04a7a..f853a7bc 100644 --- a/man/label_wrap.Rd +++ b/man/label_wrap.Rd @@ -34,8 +34,8 @@ demo_discrete(x, labels = label_wrap(20)) } \seealso{ Other labels for discrete scales: +\code{\link{label_dictionary}()}, \code{\link{label_glue}()}, -\code{\link{label_lut}()}, \code{\link{label_parse}()} } \concept{labels for discrete scales} diff --git a/tests/testthat/test-label-lut.R b/tests/testthat/test-label-lut.R index 36df0670..4b692024 100644 --- a/tests/testthat/test-label-lut.R +++ b/tests/testthat/test-label-lut.R @@ -1,11 +1,11 @@ -test_that("label_lut gives correct answers", { +test_that("label_dictionary gives correct answers", { short <- c("A", "B", "C") lut <- c("A" = "Apple", "C" = "Cherry", "D" = "Date") - expect_equal(label_lut(lut)(short), c("Apple", "B", "Cherry")) + expect_equal(label__dictionary(lut)(short), c("Apple", "B", "Cherry")) expect_equal( - label_lut(lut, nomatch = "Banana")(short), + label_dictionary(lut, nomatch = "Banana")(short), c("Apple", "Banana", "Cherry") ) }) From 7a179848197d88e301d221091b533bcba5facf1f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 22 Oct 2024 09:45:12 +0200 Subject: [PATCH 6/7] rename properly this time --- R/label-dictionary.R | 12 ++++++------ tests/testthat/test-label-lut.R | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/label-dictionary.R b/R/label-dictionary.R index 0c296f86..15dd12e1 100644 --- a/R/label-dictionary.R +++ b/R/label-dictionary.R @@ -33,14 +33,14 @@ #' ) label_dictionary <- function(dictionary = character(), nomatch = NULL) { - if (!is.character(lut)) { - cli::cli_abort("The {.arg lut} argument must be a character vector.") + if (!is.character(dictionary)) { + cli::cli_abort("The {.arg dictionary} argument must be a character vector.") } - if (!is_named2(lut)) { - cli::cli_abort("The {.arg lut} argument must have names.") + if (!is_named2(dictionary)) { + cli::cli_abort("The {.arg dictionary} argument must have names.") } - names <- names(lut) - values <- unname(lut) + names <- names(dictionary) + values <- unname(dictionary) force(nomatch) diff --git a/tests/testthat/test-label-lut.R b/tests/testthat/test-label-lut.R index 4b692024..eed01331 100644 --- a/tests/testthat/test-label-lut.R +++ b/tests/testthat/test-label-lut.R @@ -3,7 +3,7 @@ test_that("label_dictionary gives correct answers", { short <- c("A", "B", "C") lut <- c("A" = "Apple", "C" = "Cherry", "D" = "Date") - expect_equal(label__dictionary(lut)(short), c("Apple", "B", "Cherry")) + expect_equal(label_dictionary(lut)(short), c("Apple", "B", "Cherry")) expect_equal( label_dictionary(lut, nomatch = "Banana")(short), c("Apple", "Banana", "Cherry") From 909458ea30524cd6eeb0268aa0ef13bf7482f360 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 22 Oct 2024 09:49:03 +0200 Subject: [PATCH 7/7] rename test file --- tests/testthat/{test-label-lut.R => test-label-dictionary.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/testthat/{test-label-lut.R => test-label-dictionary.R} (100%) diff --git a/tests/testthat/test-label-lut.R b/tests/testthat/test-label-dictionary.R similarity index 100% rename from tests/testthat/test-label-lut.R rename to tests/testthat/test-label-dictionary.R