Why doesn’t the assignment operator shortcut work?

I’ve recently moved from exclusively using R scripts to incorporating RMarkdown files and came across (what I perceived as) a problem with the assignment operator shortcut.

I used the Mac shortcut of Option + – and RStudio gave me an equals sign (=) instead of the assignment operator (<-). I tried a bunch of other key combinations and managed to resize my RStudio display and get a bunch of other characters returned, but no assignment operator.

Source: Image by fancycrave1 from Pixabay 

Up to now I’ve only used R scripts, so I had a small panic about versions changing and new shortcuts (not sure why seeing I haven’t installed a new version). Then to Google!

Not many helpful options. Mostly links telling me the RStudio keyboard shortcut for the assignment operator (thanks, but I already know this) and other RStudio shortcuts.

After reading through the comments on a RStudio GitHub issue this comment gave me a lightbulb moment:

“In an R markdown document, do you by chance get = when composing text but <- within a code chunk?”

ronblum – https://github.com/rstudio/rstudio/issues/2486#issuecomment-663187110

I was trying to create an assignment operator in the text section of a markdown file so the shortcut wasn’t working. Tried out the shortcut in a code chunk and it’s fixed. That is to say, it was never broken – a case of operator error (ha!).