Find a function

get_fun(fn, default = identity)

Arguments

fn

A function name, either a character string or an unquoted function name, with or without colons.

default

If fn is NULL, the default function is returned. Defaults to identity().

Value

A function

Examples

get_fun(plu_ral)
#> function (x, vector = NULL, n_fn = NULL, ..., n = NULL, pl = NULL, #> irregulars = c("moderate", "conservative", "liberal", "none"), #> replace_n = TRUE, open = "{", close = "}") #> { #> if (!length(x)) { #> return(character(0)) #> } #> assert_type(x, "character") #> assert_length_1(replace_n) #> assert_t_or_f(replace_n) #> pl <- derive_pl(pl, n, vector) #> n <- derive_n(pl, n, vector) #> 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 <- grepl(paste0(open, ".*", close), split_in) #> if (replace_n) { #> replace_n <- grepl("\\bn\\b", split_in) #> } #> n_fn <- get_fun(n_fn) #> split_out <- split_in #> if (pl) { #> split_out[!braced & !replace_n] <- plu_ralize(split_in[!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(grepl("[[:alpha:]]", split_out[seq(i, #> (i%/%nrow(split_out) + 1) * nrow(split_out))])) #> 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] == #> " "] <- "" #> } #> } #> split_out[braced] <- pluralize_braces(split_out[braced], #> n, open, close) #> split_out[replace_n] <- gsub("\\bn\\b", n_fn(n, ...), split_out[replace_n]) #> mat[] <- apply(split_out, 2, paste, collapse = "") #> x[] <- apply(mat, 2, paste, collapse = "") #> x #> } #> <bytecode: 0x7ffd84319ae0> #> <environment: namespace:plu>
get_fun(plu::ral)
#> function (x, vector = NULL, n_fn = NULL, ..., n = NULL, pl = NULL, #> irregulars = c("moderate", "conservative", "liberal", "none"), #> replace_n = TRUE, open = "{", close = "}") #> { #> if (!length(x)) { #> return(character(0)) #> } #> assert_type(x, "character") #> assert_length_1(replace_n) #> assert_t_or_f(replace_n) #> pl <- derive_pl(pl, n, vector) #> n <- derive_n(pl, n, vector) #> 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 <- grepl(paste0(open, ".*", close), split_in) #> if (replace_n) { #> replace_n <- grepl("\\bn\\b", split_in) #> } #> n_fn <- get_fun(n_fn) #> split_out <- split_in #> if (pl) { #> split_out[!braced & !replace_n] <- plu_ralize(split_in[!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(grepl("[[:alpha:]]", split_out[seq(i, #> (i%/%nrow(split_out) + 1) * nrow(split_out))])) #> 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] == #> " "] <- "" #> } #> } #> split_out[braced] <- pluralize_braces(split_out[braced], #> n, open, close) #> split_out[replace_n] <- gsub("\\bn\\b", n_fn(n, ...), split_out[replace_n]) #> mat[] <- apply(split_out, 2, paste, collapse = "") #> x[] <- apply(mat, 2, paste, collapse = "") #> x #> } #> <bytecode: 0x7ffd84373290> #> <environment: namespace:plu>
get_fun("plu_ral")
#> function (x, vector = NULL, n_fn = NULL, ..., n = NULL, pl = NULL, #> irregulars = c("moderate", "conservative", "liberal", "none"), #> replace_n = TRUE, open = "{", close = "}") #> { #> if (!length(x)) { #> return(character(0)) #> } #> assert_type(x, "character") #> assert_length_1(replace_n) #> assert_t_or_f(replace_n) #> pl <- derive_pl(pl, n, vector) #> n <- derive_n(pl, n, vector) #> 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 <- grepl(paste0(open, ".*", close), split_in) #> if (replace_n) { #> replace_n <- grepl("\\bn\\b", split_in) #> } #> n_fn <- get_fun(n_fn) #> split_out <- split_in #> if (pl) { #> split_out[!braced & !replace_n] <- plu_ralize(split_in[!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(grepl("[[:alpha:]]", split_out[seq(i, #> (i%/%nrow(split_out) + 1) * nrow(split_out))])) #> 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] == #> " "] <- "" #> } #> } #> split_out[braced] <- pluralize_braces(split_out[braced], #> n, open, close) #> split_out[replace_n] <- gsub("\\bn\\b", n_fn(n, ...), split_out[replace_n]) #> mat[] <- apply(split_out, 2, paste, collapse = "") #> x[] <- apply(mat, 2, paste, collapse = "") #> x #> } #> <bytecode: 0x7ffd84319ae0> #> <environment: namespace:plu>
get_fun("plu::ral")
#> function (x, vector = NULL, n_fn = NULL, ..., n = NULL, pl = NULL, #> irregulars = c("moderate", "conservative", "liberal", "none"), #> replace_n = TRUE, open = "{", close = "}") #> { #> if (!length(x)) { #> return(character(0)) #> } #> assert_type(x, "character") #> assert_length_1(replace_n) #> assert_t_or_f(replace_n) #> pl <- derive_pl(pl, n, vector) #> n <- derive_n(pl, n, vector) #> 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 <- grepl(paste0(open, ".*", close), split_in) #> if (replace_n) { #> replace_n <- grepl("\\bn\\b", split_in) #> } #> n_fn <- get_fun(n_fn) #> split_out <- split_in #> if (pl) { #> split_out[!braced & !replace_n] <- plu_ralize(split_in[!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(grepl("[[:alpha:]]", split_out[seq(i, #> (i%/%nrow(split_out) + 1) * nrow(split_out))])) #> 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] == #> " "] <- "" #> } #> } #> split_out[braced] <- pluralize_braces(split_out[braced], #> n, open, close) #> split_out[replace_n] <- gsub("\\bn\\b", n_fn(n, ...), split_out[replace_n]) #> mat[] <- apply(split_out, 2, paste, collapse = "") #> x[] <- apply(mat, 2, paste, collapse = "") #> x #> } #> <bytecode: 0x7ffd84373290> #> <environment: namespace:plu>
get_fun(NULL)
#> function (x) #> x #> <bytecode: 0x7ffd7fb5bd80> #> <environment: namespace:base>
get_fun(NULL, default = plu_ral)
#> function (x, vector = NULL, n_fn = NULL, ..., n = NULL, pl = NULL, #> irregulars = c("moderate", "conservative", "liberal", "none"), #> replace_n = TRUE, open = "{", close = "}") #> { #> if (!length(x)) { #> return(character(0)) #> } #> assert_type(x, "character") #> assert_length_1(replace_n) #> assert_t_or_f(replace_n) #> pl <- derive_pl(pl, n, vector) #> n <- derive_n(pl, n, vector) #> 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 <- grepl(paste0(open, ".*", close), split_in) #> if (replace_n) { #> replace_n <- grepl("\\bn\\b", split_in) #> } #> n_fn <- get_fun(n_fn) #> split_out <- split_in #> if (pl) { #> split_out[!braced & !replace_n] <- plu_ralize(split_in[!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(grepl("[[:alpha:]]", split_out[seq(i, #> (i%/%nrow(split_out) + 1) * nrow(split_out))])) #> 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] == #> " "] <- "" #> } #> } #> split_out[braced] <- pluralize_braces(split_out[braced], #> n, open, close) #> split_out[replace_n] <- gsub("\\bn\\b", n_fn(n, ...), split_out[replace_n]) #> mat[] <- apply(split_out, 2, paste, collapse = "") #> x[] <- apply(mat, 2, paste, collapse = "") #> x #> } #> <bytecode: 0x7ffd84319ae0> #> <environment: namespace:plu>