macOS keyboard not working

rstudio

#1

The "caret" in the code below is entered using "option-i", that is not recognized by Rstudio. Using macOS HS on 2016 MBP and input device is wireless keyboard. Have seen many older posts on this problem, is this unique to my system or is the issue as yet unresolved?

x=2
y = xˆ2
Error: unexpected input in "y = x�"


#2

You'll need to look for the 'hat' symbol ^ or use ** and then it'll work:

y = x^2
y = x**2

#3

Thanks Leon! the ** works, but not the "caret". There is no caret symbol on the keyboard, the keyboard mapper uses option-i for the "caret", but this clearly is not working on my system.


#4

This is a Unicode thing; there's a difference between a caret (^, Shift6 in my keyboard layout) and a hat/circumflex (ˆ, OptionISpace). They're two different versions of the same thing, but for different purposes; the latter is meant for accenting characters like î, whereas the former is designed to stand alone.


#5

Many thanks for this valuable information, unfortunately the "shift-6" also give the same error, maybe my keyboard is not set up for Unicode properly? The shape and size of the "caret" ^ (shift-6) looks correct as I type it here in this dialog box, different from the "hat"(which I cannot type in this box, just blank space(!). However, the Rstudio console, both keystrokes look identical (like the "hat"). And why does the "**" work? These "little" odd quirky things make progress and learning so difficult for this old guy who admittedly needs more patience! Many thanks again for your help.


#6

Weird. Are you using an unusual keyboard layout? (You can see if you go to  > System Preferences... > Keyboard > Input Sources). Mine is just called "U.S.". It could also be some third-party software messing with input, possibly bundled with the keyboard itself.

If the keyboard is, in fact, typing different characters but they look the same in RStudio, you may just need a font which differentiates them. In Fira Code and the Solarized Dark theme, they look and are highlighted differently:

circumflex

You could also try dragging the glyph in from Font Book to ensure it works with a proper caret (U+005E; confusing called "circumflex accent").


#7

This is actually quite obscure! Buried deep down the Arithmetic Operators help page, we find:

** is translated in the parser to ^, but this was undocumented for many years. It appears as an index entry in Becker et al (1988), pointing to the help for Deprecated but is not actually mentioned on that page. Even though it had been deprecated in S for 20 years, it was still accepted in R in 2008.