The (excellent) MWE that you provided runs just fine for me (in R 4.0.0
under Ubuntu 18.04) either by sourcing "aaa.R" or by using copy-and-paste.
Must be Windoze thing. Switch to Linux!
cheers,
Rolf Turner
n 29/04/20 2:25 pm, Jinsong Zhao wrote:
On 2020/4/29 8:05, Jinsong Zhao wrote:
Hi there,
I have a piece of source code with some inline comments in Chinese. It
works well when I copy it from a editor (gvim here), and paste it to
Rgui console on R 3.6.3, however, when I do the same thing, R 4.0.0
give error message:
Error: invalid multibyte character in parser at line 21
If I source() the code from Rgui console, it can run without any error.
Any hints?
BTW, I do not make a minimal workable example yet.
Here is the MWE:
D:\system\Desktop>cat aaa.R
gz <- data.frame(x1 = rnorm(100), x10 = rnorm(100))
gz <- within(gz,
{
a <- x1 #a???????
bbbbb <- x10 #b???a????
ccccc <- x10 #c????????
ddddd <- x10 #d?????b????
eeeee <- x10 #e????????
fffff <- x10 #f?????c
})
The ASCII character in the code could be replace by other ASCII
character. The Chinese character could be replace by other Chinese
character.
Calling source("aaa.R") could run normally. If you select all the code
and paste it to Rgui console, it will give error:
> gz <- data.frame(x1 = rnorm(100), x10 = rnorm(100))
> gz <- within(gz,
+ {
+ a <- x1 #a???????
+ bbbbb <- x10 #b???a????
+ ccccc <- x10 #c????????
+ ddddd <- x10 #d?????b????
+ eeeee <- x10 #e????????
+ fffff <- x10 #f?????c
Error: invalid multibyte character in parser at line 9
Error: unexpected '}' in " }"
If you delete any character from the comment, or add any character to
the comment. The code can paste to the console without any error.
If you change the length of `bbbbb`...`fffff`, the code also could be
paste and run without any error.
Best,
Jinsong
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276