Find a function
get_fun(fn, default = identity)
A function name, either a character string or an unquoted function name, with or without colons.
If fn
is NULL
, the default
function is returned.
Defaults to identity()
.
A function
get_fun(plu_ral)
#> function (x, vector = NULL, n = NULL, pl = NULL, irregulars = c("moderate",
#> "conservative", "liberal", "none"), replace_n = TRUE, open = "{",
#> close = "}", n_fn = lifecycle::deprecated(), ...)
#> {
#> if (length(x) == 0) {
#> return(character(0))
#> }
#> mode(x) <- "character"
#> derived_plurality <- derive_plurality(x, vector, n, pl)
#> pl <- derived_plurality$pl
#> n <- derived_plurality$n
#> x <- recycle(x, n)
#> validate_delimeters(open, close)
#> open <- escape(open)
#> close <- escape(close)
#> mat <- matrix(x, nrow = 1)
#> boundaries <- paste0("((?=[^[:alnum:]'\\-", open, "])", "|",
#> "(?<=[^[:alnum:]'\\-", open, "]))", "(?![^", open, "]*",
#> close, ")")
#> split_in <- plu_split(mat, boundaries, perl = TRUE)
#> braced <- str_detect(split_in, regex(paste0(open, ".*", close),
#> multiline = TRUE, dotall = TRUE))
#> assert_length_1(replace_n)
#> assert_t_or_f(replace_n)
#> if (replace_n) {
#> replace_n <- str_detect(split_in, "\\bn\\b")
#> }
#> if (lifecycle::is_present(n_fn)) {
#> lifecycle::deprecate_warn(when = "0.2.4", what = "plu_ral(n_fn)")
#> }
#> split_out <- split_in
#> if (any(pl)) {
#> pl <- rep(pl, each = nrow(split_out))
#> split_out[pl & !braced & !replace_n] <- plu_ralize(split_in[pl &
#> !braced & !replace_n], irregulars = irregulars)
#> removed <- which(split_out == "" & split_in != "")
#> removed <- removed[removed%%nrow(split_out) != 0]
#> if (any(removed)) {
#> caps <- which(is_capitalized(split_in))
#> caps <- caps[caps %in% removed]
#> after_caps <- vapply(caps, function(i) {
#> idx <- which(str_detect(split_out[seq(i, (i%/%nrow(split_out) +
#> 1) * nrow(split_out))], "[[:alpha:]]"))
#> idx[1] + i - 1L
#> }, integer(1))
#> split_out[after_caps] <- capitalize(split_out[after_caps])
#> after_removed <- removed + 1
#> split_out[after_removed][split_out[after_removed] ==
#> " "] <- ""
#> }
#> }
#> n <- rep(n, each = nrow(split_out))
#> split_out[braced] <- pluralize_braces(split_out[braced],
#> n[braced], open, close)
#> split_out[replace_n] <- str_replace_all(split_out[replace_n],
#> pattern = "\\bn\\b", replacement = n[replace_n])
#> mat[] <- apply(split_out, 2, paste, collapse = "")
#> x[] <- apply(mat, 2, paste, collapse = "")
#> x
#> }
#> <bytecode: 0x564ed6b23d40>
#> <environment: namespace:plu>
get_fun(plu::ral)
#> function (x, vector = NULL, n = NULL, pl = NULL, irregulars = c("moderate",
#> "conservative", "liberal", "none"), replace_n = TRUE, open = "{",
#> close = "}", n_fn = lifecycle::deprecated(), ...)
#> {
#> if (length(x) == 0) {
#> return(character(0))
#> }
#> mode(x) <- "character"
#> derived_plurality <- derive_plurality(x, vector, n, pl)
#> pl <- derived_plurality$pl
#> n <- derived_plurality$n
#> x <- recycle(x, n)
#> validate_delimeters(open, close)
#> open <- escape(open)
#> close <- escape(close)
#> mat <- matrix(x, nrow = 1)
#> boundaries <- paste0("((?=[^[:alnum:]'\\-", open, "])", "|",
#> "(?<=[^[:alnum:]'\\-", open, "]))", "(?![^", open, "]*",
#> close, ")")
#> split_in <- plu_split(mat, boundaries, perl = TRUE)
#> braced <- str_detect(split_in, regex(paste0(open, ".*", close),
#> multiline = TRUE, dotall = TRUE))
#> assert_length_1(replace_n)
#> assert_t_or_f(replace_n)
#> if (replace_n) {
#> replace_n <- str_detect(split_in, "\\bn\\b")
#> }
#> if (lifecycle::is_present(n_fn)) {
#> lifecycle::deprecate_warn(when = "0.2.4", what = "plu_ral(n_fn)")
#> }
#> split_out <- split_in
#> if (any(pl)) {
#> pl <- rep(pl, each = nrow(split_out))
#> split_out[pl & !braced & !replace_n] <- plu_ralize(split_in[pl &
#> !braced & !replace_n], irregulars = irregulars)
#> removed <- which(split_out == "" & split_in != "")
#> removed <- removed[removed%%nrow(split_out) != 0]
#> if (any(removed)) {
#> caps <- which(is_capitalized(split_in))
#> caps <- caps[caps %in% removed]
#> after_caps <- vapply(caps, function(i) {
#> idx <- which(str_detect(split_out[seq(i, (i%/%nrow(split_out) +
#> 1) * nrow(split_out))], "[[:alpha:]]"))
#> idx[1] + i - 1L
#> }, integer(1))
#> split_out[after_caps] <- capitalize(split_out[after_caps])
#> after_removed <- removed + 1
#> split_out[after_removed][split_out[after_removed] ==
#> " "] <- ""
#> }
#> }
#> n <- rep(n, each = nrow(split_out))
#> split_out[braced] <- pluralize_braces(split_out[braced],
#> n[braced], open, close)
#> split_out[replace_n] <- str_replace_all(split_out[replace_n],
#> pattern = "\\bn\\b", replacement = n[replace_n])
#> mat[] <- apply(split_out, 2, paste, collapse = "")
#> x[] <- apply(mat, 2, paste, collapse = "")
#> x
#> }
#> <bytecode: 0x564ed6b7f6c0>
#> <environment: namespace:plu>
get_fun("plu_ral")
#> function (x, vector = NULL, n = NULL, pl = NULL, irregulars = c("moderate",
#> "conservative", "liberal", "none"), replace_n = TRUE, open = "{",
#> close = "}", n_fn = lifecycle::deprecated(), ...)
#> {
#> if (length(x) == 0) {
#> return(character(0))
#> }
#> mode(x) <- "character"
#> derived_plurality <- derive_plurality(x, vector, n, pl)
#> pl <- derived_plurality$pl
#> n <- derived_plurality$n
#> x <- recycle(x, n)
#> validate_delimeters(open, close)
#> open <- escape(open)
#> close <- escape(close)
#> mat <- matrix(x, nrow = 1)
#> boundaries <- paste0("((?=[^[:alnum:]'\\-", open, "])", "|",
#> "(?<=[^[:alnum:]'\\-", open, "]))", "(?![^", open, "]*",
#> close, ")")
#> split_in <- plu_split(mat, boundaries, perl = TRUE)
#> braced <- str_detect(split_in, regex(paste0(open, ".*", close),
#> multiline = TRUE, dotall = TRUE))
#> assert_length_1(replace_n)
#> assert_t_or_f(replace_n)
#> if (replace_n) {
#> replace_n <- str_detect(split_in, "\\bn\\b")
#> }
#> if (lifecycle::is_present(n_fn)) {
#> lifecycle::deprecate_warn(when = "0.2.4", what = "plu_ral(n_fn)")
#> }
#> split_out <- split_in
#> if (any(pl)) {
#> pl <- rep(pl, each = nrow(split_out))
#> split_out[pl & !braced & !replace_n] <- plu_ralize(split_in[pl &
#> !braced & !replace_n], irregulars = irregulars)
#> removed <- which(split_out == "" & split_in != "")
#> removed <- removed[removed%%nrow(split_out) != 0]
#> if (any(removed)) {
#> caps <- which(is_capitalized(split_in))
#> caps <- caps[caps %in% removed]
#> after_caps <- vapply(caps, function(i) {
#> idx <- which(str_detect(split_out[seq(i, (i%/%nrow(split_out) +
#> 1) * nrow(split_out))], "[[:alpha:]]"))
#> idx[1] + i - 1L
#> }, integer(1))
#> split_out[after_caps] <- capitalize(split_out[after_caps])
#> after_removed <- removed + 1
#> split_out[after_removed][split_out[after_removed] ==
#> " "] <- ""
#> }
#> }
#> n <- rep(n, each = nrow(split_out))
#> split_out[braced] <- pluralize_braces(split_out[braced],
#> n[braced], open, close)
#> split_out[replace_n] <- str_replace_all(split_out[replace_n],
#> pattern = "\\bn\\b", replacement = n[replace_n])
#> mat[] <- apply(split_out, 2, paste, collapse = "")
#> x[] <- apply(mat, 2, paste, collapse = "")
#> x
#> }
#> <bytecode: 0x564ed6b23d40>
#> <environment: namespace:plu>
get_fun("plu::ral")
#> function (x, vector = NULL, n = NULL, pl = NULL, irregulars = c("moderate",
#> "conservative", "liberal", "none"), replace_n = TRUE, open = "{",
#> close = "}", n_fn = lifecycle::deprecated(), ...)
#> {
#> if (length(x) == 0) {
#> return(character(0))
#> }
#> mode(x) <- "character"
#> derived_plurality <- derive_plurality(x, vector, n, pl)
#> pl <- derived_plurality$pl
#> n <- derived_plurality$n
#> x <- recycle(x, n)
#> validate_delimeters(open, close)
#> open <- escape(open)
#> close <- escape(close)
#> mat <- matrix(x, nrow = 1)
#> boundaries <- paste0("((?=[^[:alnum:]'\\-", open, "])", "|",
#> "(?<=[^[:alnum:]'\\-", open, "]))", "(?![^", open, "]*",
#> close, ")")
#> split_in <- plu_split(mat, boundaries, perl = TRUE)
#> braced <- str_detect(split_in, regex(paste0(open, ".*", close),
#> multiline = TRUE, dotall = TRUE))
#> assert_length_1(replace_n)
#> assert_t_or_f(replace_n)
#> if (replace_n) {
#> replace_n <- str_detect(split_in, "\\bn\\b")
#> }
#> if (lifecycle::is_present(n_fn)) {
#> lifecycle::deprecate_warn(when = "0.2.4", what = "plu_ral(n_fn)")
#> }
#> split_out <- split_in
#> if (any(pl)) {
#> pl <- rep(pl, each = nrow(split_out))
#> split_out[pl & !braced & !replace_n] <- plu_ralize(split_in[pl &
#> !braced & !replace_n], irregulars = irregulars)
#> removed <- which(split_out == "" & split_in != "")
#> removed <- removed[removed%%nrow(split_out) != 0]
#> if (any(removed)) {
#> caps <- which(is_capitalized(split_in))
#> caps <- caps[caps %in% removed]
#> after_caps <- vapply(caps, function(i) {
#> idx <- which(str_detect(split_out[seq(i, (i%/%nrow(split_out) +
#> 1) * nrow(split_out))], "[[:alpha:]]"))
#> idx[1] + i - 1L
#> }, integer(1))
#> split_out[after_caps] <- capitalize(split_out[after_caps])
#> after_removed <- removed + 1
#> split_out[after_removed][split_out[after_removed] ==
#> " "] <- ""
#> }
#> }
#> n <- rep(n, each = nrow(split_out))
#> split_out[braced] <- pluralize_braces(split_out[braced],
#> n[braced], open, close)
#> split_out[replace_n] <- str_replace_all(split_out[replace_n],
#> pattern = "\\bn\\b", replacement = n[replace_n])
#> mat[] <- apply(split_out, 2, paste, collapse = "")
#> x[] <- apply(mat, 2, paste, collapse = "")
#> x
#> }
#> <bytecode: 0x564ed6b7f6c0>
#> <environment: namespace:plu>
get_fun(NULL)
#> function (x)
#> x
#> <bytecode: 0x564ed3b6b470>
#> <environment: namespace:base>
get_fun(NULL, default = plu_ral)
#> function (x, vector = NULL, n = NULL, pl = NULL, irregulars = c("moderate",
#> "conservative", "liberal", "none"), replace_n = TRUE, open = "{",
#> close = "}", n_fn = lifecycle::deprecated(), ...)
#> {
#> if (length(x) == 0) {
#> return(character(0))
#> }
#> mode(x) <- "character"
#> derived_plurality <- derive_plurality(x, vector, n, pl)
#> pl <- derived_plurality$pl
#> n <- derived_plurality$n
#> x <- recycle(x, n)
#> validate_delimeters(open, close)
#> open <- escape(open)
#> close <- escape(close)
#> mat <- matrix(x, nrow = 1)
#> boundaries <- paste0("((?=[^[:alnum:]'\\-", open, "])", "|",
#> "(?<=[^[:alnum:]'\\-", open, "]))", "(?![^", open, "]*",
#> close, ")")
#> split_in <- plu_split(mat, boundaries, perl = TRUE)
#> braced <- str_detect(split_in, regex(paste0(open, ".*", close),
#> multiline = TRUE, dotall = TRUE))
#> assert_length_1(replace_n)
#> assert_t_or_f(replace_n)
#> if (replace_n) {
#> replace_n <- str_detect(split_in, "\\bn\\b")
#> }
#> if (lifecycle::is_present(n_fn)) {
#> lifecycle::deprecate_warn(when = "0.2.4", what = "plu_ral(n_fn)")
#> }
#> split_out <- split_in
#> if (any(pl)) {
#> pl <- rep(pl, each = nrow(split_out))
#> split_out[pl & !braced & !replace_n] <- plu_ralize(split_in[pl &
#> !braced & !replace_n], irregulars = irregulars)
#> removed <- which(split_out == "" & split_in != "")
#> removed <- removed[removed%%nrow(split_out) != 0]
#> if (any(removed)) {
#> caps <- which(is_capitalized(split_in))
#> caps <- caps[caps %in% removed]
#> after_caps <- vapply(caps, function(i) {
#> idx <- which(str_detect(split_out[seq(i, (i%/%nrow(split_out) +
#> 1) * nrow(split_out))], "[[:alpha:]]"))
#> idx[1] + i - 1L
#> }, integer(1))
#> split_out[after_caps] <- capitalize(split_out[after_caps])
#> after_removed <- removed + 1
#> split_out[after_removed][split_out[after_removed] ==
#> " "] <- ""
#> }
#> }
#> n <- rep(n, each = nrow(split_out))
#> split_out[braced] <- pluralize_braces(split_out[braced],
#> n[braced], open, close)
#> split_out[replace_n] <- str_replace_all(split_out[replace_n],
#> pattern = "\\bn\\b", replacement = n[replace_n])
#> mat[] <- apply(split_out, 2, paste, collapse = "")
#> x[] <- apply(mat, 2, paste, collapse = "")
#> x
#> }
#> <bytecode: 0x564ed6b23d40>
#> <environment: namespace:plu>