Skip to content

Instantly share code, notes, and snippets.

@PietrH
Created June 26, 2025 10:31
Show Gist options
  • Save PietrH/80d255cbf3d7c07e21d99741fd60acaa to your computer and use it in GitHub Desktop.
Save PietrH/80d255cbf3d7c07e21d99741fd60acaa to your computer and use it in GitHub Desktop.
Use object name (symbol) in cli message in R
object_name_message <- function(x){
  cli::cli_inform("The object you passed is called {substitute(x)}")
}

object_name_message(letters)
#> The object you passed is called letters

Created on 2025-06-26 with reprex v2.1.1

object_name_message <- function(x){
cli::cli_inform("The object you passed is called {substitute(x)}")
}
object_name_message(letters)
@PietrH
Copy link
Author

PietrH commented Jun 26, 2025

Example of pluralisation, field name (argument) formatting, and a filepath:

cli::cli_warn(
      "No observations found for {length(missing_years)} year{?s}: {.field {missing_years}} in {.file {filepath}}."
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment