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!).

R coding and lots of Googling

I’ve been working in R long enough to have Googled the same things multiple times. It’s time to blog these things so they stick in my brain. Or failing that (let’s be honest!) I can look up my own blog.

I hope these linked posts help you learn about R coding or shortcut your frustration.

  1. Why doesn’t the assignment operator shortcut work?

Thanks to Jen Richmond, RLadies Sydney and the Macquarie Uni R Users Group for the idea and motivation to share thoughts on things that I stumble over so others can learn too.

Source: Image by 377053 from Pixabay