yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
255 stars 52 forks source link

unexpected string constant #26

Closed dougedmunds closed 11 years ago

dougedmunds commented 11 years ago

Attempted to run tidy.dir() on code from https://github.com/systematicinvestor/SIT/tree/sit.gz.

Contains one long file "code.r" (12000+ lines).

Errors out with this:

tidy.dir() tidying ./code.r Error in base::parse(text = text, srcfile = NULL) : 7438:50: unexpected string constant 9121: colnames(temp) = tickers 9122: rownames(temp) = spl('Avg Pos,Max Pos,Min Pos, %InLiNe_IdEnTiFiEr% " ^

There is no " %InLiNe_IdEnTiFiEr% " in the code.

The real text of the line it hangs on reads:

    rownames(temp) = spl('Avg Pos,Max Pos,Min Pos,# Periods')

located at approximately line 8980.

(note, the author of that code is actively updating it, so the line number may change).

yihui commented 11 years ago

Currently I do not have a reliable method to detect comments; in this case, formatR sees # as a comment instead of a literal character in a string. To solve the problem, you can use double quotes around the character string, i.e. "Avg Pos,Max Pos,Min Pos,# Periods"

I think it will be solved nicely when R 2.16.0 comes out next year. Thanks for the report.

Dasonk commented 11 years ago

Doesn't seem like R 3.0 fixed the problem. This showed up at Stackoverflow today: http://stackoverflow.com/questions/17307806/knitr-doesnt-seem-to-gracefully-tidy-hashes-e-g-a/17309254#17309254

yihui commented 11 years ago

Thanks for coming back to this issue. R 3.0 has what I need (getParseData), but I just do not have enough time for this issue at the moment.

yihui commented 11 years ago

This has been fixed under R 3.0.1 in the latest devel version here.