0

Let's say I want to print the shrugface emoji in R.

How do I get a string to ignore the escaping backslash, to contain "¯\_(ツ)_/¯", like so:

example <- "This is a test ¯\_(ツ)_/¯"

So that I can render it as

utf8::utf8_print(example)
[1] "This is a test ‍♀️"
Christopher Costello
  • 1,186
  • 2
  • 16
  • 30
  • backslashes need to be escaped (doubled): `example <- "This is a test ¯\\_(ツ)_/¯"` – MichaelChirico Jan 08 '18 at 21:31
  • [The following post](https://stackoverflow.com/questions/4685737/ignore-escape-characters-backslashes-in-r-strings) is discussing similar problem (allowing backslash inside a string in R). – Hrant Davtyan Jan 08 '18 at 21:37
  • @MichaelChirico They do if I want the text to _mean_ "¯\\_(ツ)_/¯". But I don't, because in the example I gave above the function won't work as intended if I feed it "¯\\\_(ツ)_/¯". See my previous inquiry, https://stackoverflow.com/questions/48105103/coverting-unicode-codeepoint-format/48117455?noredirect=1#comment83256485_48117455. – Christopher Costello Jan 08 '18 at 21:38
  • @HrantDavtyan. Thank you. I can't, however, find an applicable solution from those examples. :( – Christopher Costello Jan 08 '18 at 21:43
  • 1
    That's not a valid string representation in the R console, so R will never `print()` that, but you can `cat()` that value. You need to build the string as previously mentioned: `example <- "This is a test ¯\\_(ツ)_/¯"` and then you can display it without the escape with `cat(example)`. – MrFlick Jan 08 '18 at 22:02
  • @ChristopherCostello: What MrFlick says. There is only one backslash in `'\\'`. (Downvote for failure to use a library()-call for non-base function. – IRTFM Jan 08 '18 at 23:10

0 Answers0