ropensci / taxa

taxonomic classes for R
https://docs.ropensci.org/taxa
Other
48 stars 12 forks source link

Add color/formatting to output of print methods #124

Closed zachary-foster closed 6 years ago

zachary-foster commented 6 years ago

@sckott, what do you think of adding color/formatting to the output of print methods using the crayon package? Do have any experience with this? Do you know of potential problems with consoles that do not understand the color codes?

I was trying to figure out how the tibbles are color coded now, but I don't see that code in the tibble package even though it imports crayon.

sckott commented 6 years ago

sounds good to me. not sure how it works - we should do it if possible

zachary-foster commented 6 years ago

Cool, I made a few things bold already. Its really easy, but I don't know if it will introduce edge case problems

sckott commented 6 years ago

cool to see the colors 🌈

zachary-foster commented 6 years ago

Nice! I think the colors will help with these complex print methods. Feel free to change the specific styles here:

https://github.com/ropensci/taxa/blob/a7ac6b3fdf33e24d777d0e066461dd074599bf32/R/taxmap--printers.R#L357-L413

I am still not sure about the best styles to use for each part

sckott commented 6 years ago

I'm not sure what's best either. maybe they have best practices docs somehwere?

zachary-foster commented 6 years ago

I searched for best practices after you suggested it and did not find any. Currently, my strategy is to copy the tibble print methods. Unfortunately, I cant seem to find a way to print a indented tibble with colors. That would be nice for displaying tibbles stored in taxmap objects.

sckott commented 6 years ago

okay. i guess if can't indent the table, just a newline or two to set it off visually?

zachary-foster commented 6 years ago

That would work. Although I can get them to indent without color using :

https://github.com/ropensci/taxa/blob/cac27b112f6fa89851c00ac332467ee49d4878e4/R/taxmap--printers.R#L37-L47

I then was trying to add some color back, but I doubt it would be worth the trouble to completely replicate the color. I mostly just want the taxon IDs highlighted. I managed to highlight the taxon ID column name, so thats something at least.

zachary-foster commented 6 years ago

It would be especially cool if only valid taxon IDs were colored as taxon IDs so people can tell quickly which datasets are mapped to taxa and if there is anything wrong with the IDs (e.g. a taxonless data after filtering with drop_taxa = FALSE). However, I am not sure if it would be too much of a performance cost to check if IDs are valid every time a big object is printed.

sckott commented 6 years ago

valid in what sense?

zachary-foster commented 6 years ago

All should be either an ID in the edge list / names(obj$taxa) or NA.

sckott commented 6 years ago

ah, okay, yeah, seems like it'd be fast enough

zachary-foster commented 6 years ago

Ok cool

zachary-foster commented 6 years ago

Seems to be working now. Things now only get the "taxon ID" green font if the are all valid taxon ids. If there is a "taxon_id" column, but there are invalid ids, then the column header gets an angry red color.