R parse() function fails if text contains \r (carriage return)

Viewed 37

I'm using R3.4.4 for Windows. I parse multi-line text containing R code to be feed into eval(). When the lines are separated by line feed ('\n') parsing is successful. But if they are seperated by carriage return ('\r') or ('\r\n') then the function fails, reporting 'unexpected input'. To repro save the text

code = "print('1')\nprint('2')"
parse(text = code)

to simple_script.r. Then running it suceeds:

C:\R\R-3.4.4\bin>Rscript.exe simple_script.r
expression(print("1"), print("2"))

C:\R\R-3.4.4\bin>

Changing '\n' to '\r' in simple_script.r fails:

C:\R\R-3.4.4\bin>Rscript.exe simple_script.r
Error in parse(text = code) : <text>:1:11: unexpected input
1: print('1')
              ^
Execution halted

C:\R\R-3.4.4\bin>

According to parse() doc both LF, CR or CRLF are supported, so why does using CR fails?

0 Answers
Related