How to convert a string to a color hex code with R? : Is there a function which converts a string to a color hex code in R?

For example:
"foo" -> "#F123FA

Converting a number with 4 digits into a hex code would be also totally fine, but the problem is that my numbers are very similar.

Does someone know a good solution in R?