[R] Does S inherit the enhancements in R language?
Thomas Lumley
tlumley at u.washington.edu
Fri Mar 19 22:06:17 CET 2010
On Fri, 19 Mar 2010, Paul Johnson wrote:
> I don't know anybody who has S-plus these days, but I expect some of
> you might, and perhaps you won't mind telling me something.
>
> I'm working on my presentation about R for the general audience. As I
> survey the suggestions from this list about that project, I find
> myself wondering whether S-plus benefits from R. Does S-plus syntax
> change like R's does. I can take code for S and run it through R, but
> if I took some R code to an S-plus system, would it work?
>
> Example 1. _, <-, =
>
> The old S documents I find emphasize assigment with "_".
>
> When I started with R, that was deprecated, then forbidden. "_" was
> not allowed in file names, now it is. It was absolutely necessary to
> use <-. = caused errors. Around the time of R-2.1 or so, it became
> possible to run R code that has = for assignments. It's not encouraged
> by R core team, but = is allowed.
I don't think that the R core team has any position on this. Some of them use =, some don't
> Does S+ now accept either
>
> <-
>
> or
>
> =
> ?
Yes. This change happened in S4, then S-PLUS, then R.
> Example 2. Semicolons now discouraged in R code.
>
> We used to require ; to end commands.
>
> Now the R parser is smart enough to spot line breaks and interpret
> them accordingly. R's been that way for as long as I can remember, but
> I think the ; was required in earliest R releases.
>
I really don't think so. Now, I didn't use the *earliest* releases, but I did use R 0.16, which was quite a long time ago, and I don't remember semicolons being required or even encouraged.
They are permitted in both S and R, but most people seem to use them only when writing one-line functions.
> Example 3. Namespace. Does S-plus get better as R does?
>
> Years ago, I was modeling US Democrats and Republicans and I created
> an indicator variable called "rep". regression models would not work
> after that because the rep function had been blocked. It was very
> frustrating to me.
> Professor Ripley spotted the error and posed a message called "Don't
> use the names of R functions as variable names"
> http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg11585.html.
>
> After that, I was terrified that any name I used might conflict with a
> built in R function name.
>
> Last month, i saw a student here with a political model and he used
> rep as a variable in a regression model, it seemed to work just fine.
> I surmise that the rise in usage of namespaces in R packages accounts
> for that?
No, this was fixed much, much earlier than package namespaces. Symbol lookup when a function is needed can specify that a function is desired. I think this has also been true in S-PLUS for a long time, but I'm not completely sure.
There are just a few places where problems can occur, such as do.call() with an unquoted function name, where a user-defined variable can get in the way.
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list