Shambho
Shambho

Reputation: 3280

R - How to output a partially colored string in R?

I want to output a partially colored string. e.g. something like:

print(paste("This is how", style("Red","red", "bold"), "looks."))

[1] "This is how Red looks."

The string Red should be colored in red.

Any help will be much appreciated!!

Upvotes: 4

Views: 6706

Answers (2)

Waldir Leoncio
Waldir Leoncio

Reputation: 11413

Perhaps the crayon package can help you:

library(crayon)
cat("This is how", red("Red"), "looks.\n")

Output:

enter image description here

If you want more features, perhaps the xterm256 package will be helpful.

Upvotes: 0

agstudy
agstudy

Reputation: 121608

You can hack it using text:

plot(1:10,1:10,type='n',frame.plot=F,axes=F,xlab="",ylab="")
text(5,1,"This is how")
text(5.8,1,"Red",col='red',font=2)
text(6.3,1,"looks.")

enter image description here

Upvotes: 1

Related Questions