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

Jeroen Ooms j.c.l.ooms at uu.nl
Sun Jul 27 21:51:20 CEST 2008

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

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.

More information about the R-help mailing list