Coloring only a piece of characters in a cell
Closed this issue · 8 comments
Hello,
I discovered your package thanks to a comment to a question of mine on Stackoverflow.
I'm looking for a way to color only one word in a cell, not the entire cell. Do you envisage this feature for the future?
Or maybe you have a clue to help me?
Best regards.
Hey, currently the code is expecting to color whole cells, thats correct. However, what you could do is create a color_vector with just the word function and style it with what you want and then paste the contents around it.
Sounds like you kind of want syntax coloring?
Thanks. I will try.
This is for my packages findInFiles and findInGit. On the gifs you can see, the results are displayed in HTML. But these packages also allow to return the results in a dataframe, and I'd like to color the matched pattern in the dataframe, as in the HTML.
Hello,
I've tried something but no luck. This does not work:
paste0("f <-", color_vctr("function", text_color = "red"), "(x)")
What do you mean by pasting around the color vector?
This gives something interesting but there's a white space between the two components:
c(color_vctr("function", text_color = "red"), color_vctr("(x)", text_color = "white"))
Not bad:
> cv <- c(color_vctr("function", text_color = "red"), color_vctr("(x)", text_color = "white"))
> cat(paste0(format(cv, method="console"), collapse = ""))
function(x)
Easier:
cat(sub("function", format(color_vctr("function", text_color = "red")), "function(x)"))
That's fine. I've managed to do what I wanted with the help of the packages vctrs, crayon and tibble.