When I compare a string literal with a non-ASCII character in R source code to the same string passed in through the command line, the two strings test as identical and have identical charToRaw representations, but serialize differently. What's going on? Aren't both strings in UTF-8?
To reproduce this, try this shell script (I'm running Dash 0.5.10.2-7 and R 4.0.2 on Ubuntu 20.10):
echo 'x="α"' > program.R
R --vanilla -q -e \
'source("program.R")
print(identical(x, "α"))
print(identical(charToRaw(x), charToRaw("α")))
print(identical(serialize(x, NULL), serialize("α", NULL)))'
which produces
> source("program.R")
> print(identical(x, "α"))
[1] TRUE
> print(identical(charToRaw(x), charToRaw("α")))
[1] TRUE
> print(identical(serialize(x, NULL), serialize("α", NULL)))
[1] FALSE