[R] Teaching R: To quote, or not to quote?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Mar 7 16:17:24 CET 2011


On 07/03/2011 9:52 AM, Muenchen, Robert A (Bob) wrote:
> Hi All,
>
> When I teach an intro workshop on R, I've been minimizing "quote confusion" by always using quotes around package names in function calls. For example:
>
> install.packages("Hmisc")
> update.packages("Hmisc")
> library("Hmisc")
> citation("Hmisc")
> search()  # displays package names in quotes
> detach("packages:Hmisc")  # just as search displayed it
>
> all look consistent with quotes. They're optional, of course, with library and detach and I tell them that. But for beginners, it's hard to remember when they don't need quotes. This perspective continues with function names in help:
>
> help("mean")
> ?"mean"
> help("if")
> ?"if"
>
> which avoids the fact that some important topics like control-flow words (e.g. help(if) ) generate error messages without the quotes. For help, the quotes make the string a "topic" instead of a name, but that doesn't seem to block it from finding function names in quotes.
>
> I'm about to go to press with the second edition of R for SAS and SPSS Users&  I'm wondering if there's a downside to this. No other books I've seen use library("package") or help("function") consistently. Is there a reason I should avoid it?


The only reasons I can think to avoid that recommendation is that 
people  might find typing unnecessary quotes to be irritating and they 
might be confused when they see unquoted usage elsewhere.  Those aren't 
particularly strong reasons...

Duncan Murdoch



More information about the R-help mailing list