Re: [R] Object-oriented programming in R for Java programmers?

From: Jeroen Ooms <j.c.l.ooms_at_uu.nl>
Date: Sun, 27 Jul 2008 12:51:20 -0700 (PDT)

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_at_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.
Received on Sun 27 Jul 2008 - 19:54:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 27 Jul 2008 - 20:34:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive