Nothing
set_no_print(TRUE)
# Resolving single macro variable
year <- 2026
text <- macro("The current year is &year")
expect_equal(text, "The current year is 2026", info = "Resolving single macro variable")
# Resolving combination of macro variables
year <- 2026
some_variable <- "current"
current2026 <- "The current year is"
text <- macro("&&some_variable&year &year")
expect_equal(text, "The current year is 2026", info = "Resolving combination of macro variables")
# Resolving character vector containing macro variables
year <- 2026
some_variable <- "current"
current2026 <- "The current year is"
char_vector <- c("The current year is &year", "The &some_variable year is &year", "&&some_variable&year &year")
text_vector <- apply_macro(char_vector)
expect_equal(text_vector, c("The current year is 2026",
"The current year is 2026",
"The current year is 2026"), info = "Resolving character vector containing macro variables")
###############################################################################
# Warning checks
###############################################################################
# Resolving macro variable throws a warning if text is a vector
year <- 2026
text <- macro(c("The current year is &year", "The current year is &year"))
expect_warning(print_stack_as_messages("WARNING"), "<Text> may only be of length one. The first Element will be used.",
info = "Resolving macro variable throws a warning if text is a vector")
expect_equal(text, "The current year is 2026", info = "Resolving macro variable throws a warning if text is a vector")
# Resolving macro variable throws a warning if macro variable is a vector
year <- c(2026, 2025)
text <- macro("The current year is &year")
expect_warning(print_stack_as_messages("WARNING"), "Macro variable \'&year\' may only be of length one. The first Element will be used.",
info = "Resolving macro variable throws a warning if macro variable is a vector")
expect_equal(text, "The current year is 2026", info = "Resolving macro variable throws a warning if macro variable is a vector")
# Resolving macro variable throws a warning if macro variable is neither character nor numeric
year <- TRUE
text <- macro("The current year is &year")
expect_warning(print_stack_as_messages("WARNING"), "Macro variable \'&year\' is a complex object. Macro variables may only be character or numeric.",
info = "Resolving macro variable throws a warning if macro variable is neither character nor numeric")
expect_equal(text, "The current year is year", info = "Resolving macro variable throws a warning if macro variable is neither character nor numeric")
###############################################################################
# Abort checks
###############################################################################
# Resolving macro aborts if something other than a text is provided
text <- macro(1)
expect_error(print_stack_as_messages("ERROR"), "<Text> must be a character. Macro will be aborted.",
info = "Resolving macro aborts if something other than a text is provided")
set_no_print()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.