PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] How to use special characters and colours in error messages in R?

 April 27, 2022     error-handling, r, warnings     No comments   

Issue

I am writting a package in R, and I come around the warnings and error messages. In the book https://style.tidyverse.org/error-messages.html the use of ℹ and ✖ is adviced. However, it doesn't mention how to use the different special character.

On top of that, I would like to know how to colour different elements of the messages provided, such as when loading tidyverse.

Output with coloured parts

Thanks


Solution

The vctrs package is using rlang::format_error_bullets

cat(rlang::format_error_bullets(c(i = "Info", x = "Bad")))
#> ℹ Info
#> x Bad

This function is using cli::symbol$info and cli::symbol$cross which are ultimately just "ℹ" and "x"

tidyverse:::tidyverse_attach uses crayon for colours.

cat(paste0(crayon::bold("Attaching packages\n"), crayon::green("Green Text")))

colours



Answered By - Paul
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing