[R] Object-oriented programming in R for Java programmers?
Hi, I was wondering if anybody might have a reference for me: My R code is growing and getting more and more confusing. Thus, I figure it's time to switch to object-oriented again. I have done oo programming in C++ and Java before but the first few tutorial on R oo were a bit confusing for me. Is there any brief tutorial on oo programming in R especially for people who have done oo in Java or C++ before? That would be really helpful. Many thanks and have a great Sunday, Werner __ Dem pfiffigeren Posteingang. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Object-oriented programming in R for Java programmers?
Werner Wernersen <[EMAIL PROTECTED]> [Sun, Jul 27, 2008 at 01:55:26PM CEST]: [...] > Is there any brief tutorial on oo programming in R > especially for people who have done oo in Java or C++ > before? That would be really helpful. "How S4 methods work" highlights the differences between R's function-centric approach to OO and the class-centric approach highlighted by languages such as C++. This 10-page article is written by John Chambers. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:[EMAIL PROTECTED] from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi") __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Object-oriented programming in R for Java programmers?
Werner Wernersen wrote: > > I have done oo programming in C++ and Java before but the first few > tutorial on R oo were a bit confusing for me. > My personal experience is that the type of OO programming that makes for example Java code nice and easy to structure is not possible in R. The biggest problem for me is, correct me if i'm wrong, that R does not store memory references in its identifiers (variables), but a creates new 'object' for every identifier. For example, if you do in R: a <- 123 b <- 456 a <- b a <- 789 b If you would do a similar thing in Java, bot the variables 'a' and 'b' would have changed to the value 789, because both the variables now refer to the same object. So manipulating one also manipulates the other. However, in R, variable 'b' still stores the value of 456 at the end of this example. What this means for OO programming is that there is no easy way to reference to objects. For example, if you have want to access a variable which is part of a dataframe object, which is nested in a list object, you can only reference this object every time using list$dataframe$varname, where in Java, you could create a new variable that references to this specific object. Once datastructures become more complex, this handicap gets bigger and bigger. However, please don't take this for granted since I am only a beginning R programmer (and slightly more advanced Java programmer). I am also really curious what others have to say because I am having the same problem of my R-code quickly getting messy and confusing. -- View this message in context: http://www.nabble.com/Object-oriented-programming-in-R-for-Java-programmers--tp18675688p18679872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Object-oriented programming in R for Java programmers?
I've never used it myself but I recall reading about this R.oo package a while ago - might be worth considering? http://www1.maths.lth.se/help/R/R.oo/ - Original Message From: Werner Wernersen <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Sent: Sunday, July 27, 2008 4:55:26 AM Subject: [R] Object-oriented programming in R for Java programmers? Hi, I was wondering if anybody might have a reference for me: My R code is growing and getting more and more confusing. Thus, I figure it's time to switch to object-oriented again. I have done oo programming in C++ and Java before but the first few tutorial on R oo were a bit confusing for me. Is there any brief tutorial on oo programming in R especially for people who have done oo in Java or C++ before? That would be really helpful. Many thanks and have a great Sunday, Werner __ Dem pfiffigeren Posteingang. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Object-oriented programming in R for Java programmers?
This page is also a brief introduction to the S3 classes: http://www.ibm.com/developerworks/linux/library/l-r3.html (see section on 'Object-oriented R') and for S4, in addition to "How S4 methods work": http://developer.r-project.org/methodDefinition.html - Original Message From: Johannes Huesing <[EMAIL PROTECTED]> To: r-help@r-project.org Sent: Sunday, July 27, 2008 12:21:37 PM Subject: Re: [R] Object-oriented programming in R for Java programmers? Werner Wernersen <[EMAIL PROTECTED]> [Sun, Jul 27, 2008 at 01:55:26PM CEST]: [...] > Is there any brief tutorial on oo programming in R > especially for people who have done oo in Java or C++ > before? That would be really helpful. "How S4 methods work" highlights the differences between R's function-centric approach to OO and the class-centric approach highlighted by languages such as C++. This 10-page article is written by John Chambers. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:[EMAIL PROTECTED] from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi") __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.