The Trouble of .Rprofile if it Doesn’t Have a Trailing Newline

Yihui Xie 2018-04-06

Yesterday I saw a rather odd issue on Stack Overflow, in which a blogdown user said options() set in .Rprofile didn’t work. I was very much confused. Later it turned out that a trailing newline was missing in the R startup profile file .Rprofile.


Then I did a quick search, and found a similar question asked in 2013. 2013! And it is so annoying that R silently ignores the last line. Well, they may argue a line without the trailing newline is not a “line”, but it will save us so much trouble if only it issues a warning. Problems like this are so hard to debug.

Anyway, I always configure my text editors to add a newline to the end of text files (below is a screenshot of my RStudio options), so I probably would never have discovered this issue by myself.

Ensure that source files end with newline in RStudio

Update on 2018-06-05

This issue just continues to confuse more users.