-
Notifications
You must be signed in to change notification settings - Fork 4
Color coded errors/warnings/messages/printed text #61
Comments
Fun idea. Packages like https://github.com/r-lib/usethis/blob/bb191e95ef1b0e3aa304e7267d1d968975414450/R/style.R#L11-L13 Off the top of my head I can't quite think of a way that you could modify errors, warnings and message other than I do really love coloured output though and I do think it is worth the effort. |
It's all just standard ANSI colour codes. Even
Probably best not to mess with |
@boshek thanks for the usethis reference. I can imagine a bright future for a package focusing solely on formatting messages and maybe use that in @mpadge yes, maybe this would be a tiny package but I see value in tiny single purpose packages. And I can imagine that even if you have one core function like From a development perspective I can see a way to do the formatting when creating the error/warning etc. But if possible I would welcome an option for maybe globally setting style on the user side like |
Yes we do have a "todo" to extract the whole style.R file from usethis and, probably, put it in a package to facilitate making consistent user interfaces that meet the style guide. There have been multiple requests to export those functions from usethis, but we've declined, because we don't want packages to depend on usethis for that functionality. Something I've been meaning to write down but have not is a map between, say, a function in style.R and identifiable concepts. As in, "always apply this style to a path and that style when referring to an argument name and this other style for a string ...". I think, right now, you have to use common sense or look around at usage elsewhere in the package, which is slow and inconsistent. |
The long term plans for color styling in the tidyverse is to use cli to style the outputs, which would allow us to define a default style, but would also allow users to define a custom style that would automatically be used throughout our packages. Also there are a few RStudio IDE issues related to automatically coloring messages / warnings / errors in red rstudio/rstudio#2733, rstudio/rstudio#2574, so at least there this behavior will likely change in the future. |
Hi. I'm just curious if you've checked https://github.com/jalvesaq/colorout and if whether this solves part of the problem you describe. |
Summary: package for styling messages (color errors/warnings differently + style in usethis) (( @jimhester thanks, sounds great. Though not sure whether this means we should not bother with this at the unconf or it means that there's a clear way and we could. Maybe discuss in person? )) |
This would be great! So far I see that the tidyverse style guide includes advice about errors messages but omits colour (http://style.tidyverse.org/error-messages.html). This would be great guidance and most useful before too much of the code includes coloured output. |
@jimhester : I took some more time to read the issues you linked. Good to see Rstudio already thinking @lcolladotor thanks, I haven't used |
By default errors, warnings and messages are all printed red in R which can be confusing as red usually means something wrong but a message can be just informative. I think it would be nice to provide an easy way to create colored messages, like by default red for error, yellow for warning, blue for friendly information etc. With the crayon package this should not be too difficult.
I am thinking about a way that maybe the end-user should be able to control this, or the creator of the package. We could distinguish style further based on the class of the condition.
The text was updated successfully, but these errors were encountered: