Venables, Bill (CMIS, Cleveland)
2001-Jul-29 01:25 UTC
[R] style question: returning multiple arguments - structure orlist
I see Thomas has already nailed this one, so it becomes a non-issue. Nevertheless I feel moved to say I think the idea would have been a step in the wrong direction in the first place. It comes from a desire to make R behave "a bit more like matlab" and that is ultimately unhelpful. Having tried to teach generations of students how to use the system (S-PLUS, but it could equally well have been R) I can say the most difficult people to teach it to are those you have to "convert" from a long history of expertise in another system. Trying to make R behave like the previous system (SAS, Stata, SPSS, Matlab, APL, ....), as they are invariably determined to do, is ultimately futile, but you, the teacher, find yourself doing all sorts of hand-stands and cartwheels to meet these people half-way. It doesn't work. Trust me. In the end it *really* *doesn't* *work*. Seriously. I'm not sure how we can best help these people, either, but I'm working on it. It comes as a dreadful shock for them to find that R is not just SAS, or Matlab, or APL, or... in some foreign notation but a genuinely different system. They have real trouble expanding their mental outlook just enough to handle the fact that such a thing is even possible. In Adelaide where I taught with S-PLUS for about a decade I had no real problems in getting the students on board. (Some, like David Smith, even went on to have distinguished careers in the game.) But I got nowhere with my fellow staff members, some of whom just never got over Matlab, or SAS, or ... Sigh. Bill Venables. -----Original Message----- From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] Sent: Sunday, 29 July 2001 7:24 AM To: vogels at cmu.edu Cc: rhelp Subject: Re: [R] style question: returning multiple arguments - structure orlist "Thomas J Vogels" <tov at ece.cmu.edu> writes:> Hi, > > you also have the option of "throwing out" the third result by setting itto> NULL (taking your LIST option)? > > > f <- function() { > > ... > > list(x=x,y=y,z=z) > > } > > res <- f() > > names(jj) > [1] "x" "y" "z" > > res$z <- NULL > > names(res) > [1] "x" "y" > > and then work with res (res$x and res$y)?A little summer exercise: Can one write a list assignment function, i.e. "list<-" so that list(a,b,c) <- f() would be equivalent to r <- f() a <- r[[1]] b <- r[[2]] c <- r[[3]] Even better, do something useful with named list elements. (And what are the odds of finding that this is really an exercise hidden somewhere in a book by Venables and Ripley?) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Jul-29 11:45 UTC
[R] style question: returning multiple arguments - structure orlist
"Venables, Bill (CMIS, Cleveland)" <Bill.Venables at CMIS.CSIRO.AU> writes:> I see Thomas has already nailed this one, so it becomes a non-issue. > Nevertheless I feel moved to say I think the idea would have been a step in > the wrong direction in the first place. It comes from a desire to make R > behave "a bit more like matlab" and that is ultimately unhelpful. > > Having tried to teach generations of students how to use the system (S-PLUS, > but it could equally well have been R) I can say the most difficult people > to teach it to are those you have to "convert" from a long history of > expertise in another system. Trying to make R behave like the previous > system (SAS, Stata, SPSS, Matlab, APL, ....), as they are invariably > determined to do, is ultimately futile, but you, the teacher, find yourself > doing all sorts of hand-stands and cartwheels to meet these people half-way. > > It doesn't work. Trust me. In the end it *really* *doesn't* *work*. > Seriously. > > I'm not sure how we can best help these people, either, but I'm working on > it. It comes as a dreadful shock for them to find that R is not just SAS, > or Matlab, or APL, or... in some foreign notation but a genuinely different > system. They have real trouble expanding their mental outlook just enough > to handle the fact that such a thing is even possible. > > In Adelaide where I taught with S-PLUS for about a decade I had no real > problems in getting the students on board. (Some, like David Smith, even > went on to have distinguished careers in the game.) But I got nowhere with > my fellow staff members, some of whom just never got over Matlab, or SAS, or > ...The counterpoint is that I often find it extremely instructive to try and *make* R/S do some of the things it "can not do". This makes you investigate some of the esoteric corners of the semantics, and hopefully understand the whole thing a little bit better. It's not invariably the case that you actually want to use the result of the exercise, much less impose it on others. I see the pedagogical problems we're facing largely as rooted in "computational illiteracy". Basically, people have undeveloped concepts of what computer languages are and what rules govern their construction. I had the good fortune of starting at a point in time where the first year of statistics coincided with the first year of Maths and Computer Science. Later, this got changed to include a much less ambitious CS course (for some good reasons, including the fact that it is useful to teach statistics to first-year statistics students....) I only recently realized that this has become a straight Pascal programming class, which the brighter students manage with their left hand, but they learn nothing about general algorithmic topics, parser theory, and formal program verification techniques (actually, we didn't learn much about parsers and compilers either, but at least we knew that they were there). At the lower levels, people nowadays don't even realize that computer languages exist, and expect everything to work like the Windows desktop and characterize everything else as "DOS-like". As for the original challenge, I think you can actually get by with overloading "[<-", leading to syntax of the form LIST[a,b,c] <- f() (which you most certainly would not want to inflict on standard R!) LIST would want to be an object of class "foo" and "[<-.foo" a function that returns its first argument unchanged, and has its way with the other arguments. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
fharrell@virginia.edu
2001-Jul-29 12:50 UTC
[R] style question: returning multiple arguments - structure orlist
I too am troubled by the computer illiteracy of students these days. As an experiment this summer I am having incoming students who don't know at least one computer language work through the book "Beginning Programming for Dummies" by Wallace Wang. The book teaches programming through the use of Qbasic (supplied on the CD-rom that comes with the book) but introduces several other languages such as Java. It appears to be a very good book and has received good reviews. My feeling is that students who know any language such as basic, C, Python, Perl, Fortran, Java will find it easier to learn S. Many of my M.S. students have never even seen a DOS prompt nor have they thought about a "variable". There is a very good free interactive tutorial for learning Tk/Tcl where students see explanations, example code, and a window showing the results of running their own code (http://www.msen.com/~clif/Tutor2b4.exe). I wish there were something like this for other languages, especially S. -Frank "Venables, Bill (CMIS, Cleveland)" wrote:> > I see Thomas has already nailed this one, so it becomes a non-issue. > Nevertheless I feel moved to say I think the idea would have been a step in > the wrong direction in the first place. It comes from a desire to make R > behave "a bit more like matlab" and that is ultimately unhelpful. > > Having tried to teach generations of students how to use the system (S-PLUS, > but it could equally well have been R) I can say the most difficult people > to teach it to are those you have to "convert" from a long history of > expertise in another system. Trying to make R behave like the previous > system (SAS, Stata, SPSS, Matlab, APL, ....), as they are invariably > determined to do, is ultimately futile, but you, the teacher, find yourself > doing all sorts of hand-stands and cartwheels to meet these people half-way. > > It doesn't work. Trust me. In the end it *really* *doesn't* *work*. > Seriously. > > I'm not sure how we can best help these people, either, but I'm working on > it. It comes as a dreadful shock for them to find that R is not just SAS, > or Matlab, or APL, or... in some foreign notation but a genuinely different > system. They have real trouble expanding their mental outlook just enough > to handle the fact that such a thing is even possible. > > In Adelaide where I taught with S-PLUS for about a decade I had no real > problems in getting the students on board. (Some, like David Smith, even > went on to have distinguished careers in the game.) But I got nowhere with > my fellow staff members, some of whom just never got over Matlab, or SAS, or > ... > > Sigh. > > Bill Venables. > > -----Original Message----- > From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] > Sent: Sunday, 29 July 2001 7:24 AM > To: vogels at cmu.edu > Cc: rhelp > Subject: Re: [R] style question: returning multiple arguments - > structure orlist > > "Thomas J Vogels" <tov at ece.cmu.edu> writes: > > > Hi, > > > > you also have the option of "throwing out" the third result by setting it > to > > NULL (taking your LIST option)? > > > > > f <- function() { > > > ... > > > list(x=x,y=y,z=z) > > > } > > > res <- f() > > > names(jj) > > [1] "x" "y" "z" > > > res$z <- NULL > > > names(res) > > [1] "x" "y" > > > > and then work with res (res$x and res$y)? > > A little summer exercise: Can one write a list assignment function, > i.e. "list<-" so that > > list(a,b,c) <- f() > > would be equivalent to > > r <- f() > a <- r[[1]] > b <- r[[2]] > c <- r[[3]] > > Even better, do something useful with named list elements. (And what > are the odds of finding that this is really an exercise hidden > somewhere in a book by Venables and Ripley?) > > -- > O__ ---- Peter Dalgaard Blegdamsvej 3 > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._ > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jonathan Baron
2001-Jul-29 13:55 UTC
[R] style question: returning multiple arguments - structure orlist
>From owner-r-help at stat.math.ethz.ch Sun Jul 29 09:36:10 2001 >I too am troubled by the computer illiteracy of students >these days. As an experiment this summer I am having >incoming students who don't know at least one computer >language work through the book "Beginning Programming >for Dummies" by Wallace Wang.This sounds like a good book, but I want to make a pedagogical point. Although transfer of learning does occur, the last 100 years of research have tended to support the view that it is incomplete and that it also works in both directions. In my youth, they tried to get me to learn Latin because it would "make French easier." (I refused, and learned German.) The fact is that learning French would make Latin easier, just as much as the reverse. Thus, if the target is S/R, teach S/R first. It will help students learn other languages just as much as the reverse. Of course, the availability of good teaching materials is an issue. I plan to work on this in the fall, when I force the students in our introductory graduate methods class to learn R, both as a beginning cure for computer illiteracy and as a useful tool in its own right - more useful for the average psychology researcher, I think, than C or anything else. Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Venables, Bill (CMIS, Cleveland)
2001-Jul-29 23:24 UTC
[R] style question: returning multiple arguments - structure orlist
I quite agree with everything Peter says, of course and I don't think it conflicts with anything I said at all - but it is one thing to explore he possibilities of R/S by this kind of torture test and quite another to lead people to think of them as a normal and reasonable uses of the language. In similar vein I wish <<- had never been invented, as it makes an esoteric and dangerous feature of the language *seem* normal and reasonable. If you want to dumb down R/S into a macro language, this is the operator for you. Bill. -----Original Message----- From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] Sent: Sunday, 29 July 2001 9:45 PM To: Venables, Bill (CMIS, Cleveland) Cc: 'Peter Dalgaard BSA'; vogels at cmu.edu; rhelp; Thomas Lumley (E-mail) Subject: Re: [R] style question: returning multiple arguments - structure orlist "Venables, Bill (CMIS, Cleveland)" <Bill.Venables at CMIS.CSIRO.AU> writes:> I see Thomas has already nailed this one, so it becomes a non-issue. > Nevertheless I feel moved to say I think the idea would have been a stepin> the wrong direction in the first place. It comes from a desire to make R > behave "a bit more like matlab" and that is ultimately unhelpful. > > Having tried to teach generations of students how to use the system(S-PLUS,> but it could equally well have been R) I can say the most difficult people > to teach it to are those you have to "convert" from a long history of > expertise in another system. Trying to make R behave like the previous > system (SAS, Stata, SPSS, Matlab, APL, ....), as they are invariably > determined to do, is ultimately futile, but you, the teacher, findyourself> doing all sorts of hand-stands and cartwheels to meet these peoplehalf-way.> > It doesn't work. Trust me. In the end it *really* *doesn't* *work*. > Seriously. > > I'm not sure how we can best help these people, either, but I'm working on > it. It comes as a dreadful shock for them to find that R is not just SAS, > or Matlab, or APL, or... in some foreign notation but a genuinelydifferent> system. They have real trouble expanding their mental outlook just enough > to handle the fact that such a thing is even possible. > > In Adelaide where I taught with S-PLUS for about a decade I had no real > problems in getting the students on board. (Some, like David Smith, even > went on to have distinguished careers in the game.) But I got nowherewith> my fellow staff members, some of whom just never got over Matlab, or SAS,or> ...The counterpoint is that I often find it extremely instructive to try and *make* R/S do some of the things it "can not do". This makes you investigate some of the esoteric corners of the semantics, and hopefully understand the whole thing a little bit better. It's not invariably the case that you actually want to use the result of the exercise, much less impose it on others. I see the pedagogical problems we're facing largely as rooted in "computational illiteracy". Basically, people have undeveloped concepts of what computer languages are and what rules govern their construction. I had the good fortune of starting at a point in time where the first year of statistics coincided with the first year of Maths and Computer Science. Later, this got changed to include a much less ambitious CS course (for some good reasons, including the fact that it is useful to teach statistics to first-year statistics students....) I only recently realized that this has become a straight Pascal programming class, which the brighter students manage with their left hand, but they learn nothing about general algorithmic topics, parser theory, and formal program verification techniques (actually, we didn't learn much about parsers and compilers either, but at least we knew that they were there). At the lower levels, people nowadays don't even realize that computer languages exist, and expect everything to work like the Windows desktop and characterize everything else as "DOS-like". As for the original challenge, I think you can actually get by with overloading "[<-", leading to syntax of the form LIST[a,b,c] <- f() (which you most certainly would not want to inflict on standard R!) LIST would want to be an object of class "foo" and "[<-.foo" a function that returns its first argument unchanged, and has its way with the other arguments. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._