Hey are you an #RStats user on Windows? Have you ever been frustrated you can't copy and paste the path to files and folders into an R string without getting an error about escaped characters?

THE ANSWER:

Put the letter r right before the opening quote for the string to disable "character constants" and turn it into a "string literal". Like this

myPath = r"c:\MyDir"

See the letter r chilling there, OUTSIDE the quote? That's the magic trick.

@rstats

Follow

@ttpphd @rstats has the same thing. It's also handy for specifying regular expressions.

Someone with deeper knowledge may correct me, but I believe it's a "string literal" either way. The r just specifies the "raw" format for specifying the value of the literal.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.