[R] Trouble with Functions

Peter Ehlers ehlers at ucalgary.ca
Thu Jun 7 18:37:58 CEST 2012


On 2012-06-06 12:45, dougmcintosh wrote:
> Haha no, TextWrangler.
>
> And that was definitely it...I think what was happening is that when I
> opened the text version of the book it opened in Notepad, which was
> probably opened the txt file in RTF. Then I copied and pasted the function
> code into TextWrangler and didn't even think about Smart Quotes. So I used
> the "Straighten Quote" feature. It got through all the way to the last line
> where I got an unexpected string error:
>
> Error in source("/Documents/score.txt") :
>    /Documents/score.txt:13:25: unexpected INCOMPLETE_STRING
> 32: return(scores.df)
> 33: }
>
> Is there a debug version I could be running or something that lists more
> descriptive error explanations? That way I don't have to bother you guys
> and embarrass myself so. :-)

You don't need debug - you just need to get the original file in
plain text mode. All this "rich" text crud may look pretty, but
it's the text equivalent of chartjunk.

Anyway, the "INCOMPLETE_STRING" error is a pretty good hint that
R is reading part of your input as a string and that it doesn't
find a closing quote to match an opening quote. I'm pretty sure
that TextWrangler will have replaced all single "smart" quotes
appropriately, but it will have missed the double quotes in the
three gsub() lines like this one:

sentence = gsub(‘[[:punct:]]’, ”, sentence)

where the double quote actually started life as a pair of single
quotes. Thus you have an unequal number of double quotes still
in your input to source(). Just replace them by hand.

Peter Ehlers

[snip]



More information about the R-help mailing list