[R] paste workable code to R 4.0.0 cause error
Jinsong Zhao
j@zh@o @end|ng |rom ye@h@net
Wed Apr 29 04:25:03 CEST 2020
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
More information about the R-help
mailing list