[R] help with oop in R - class structure and syntex

From: tom soyer <tom.soyer_at_gmail.com>
Date: Tue, 5 Feb 2008 07:21:52 -0600


I read section 5, oop, of the R lang doc, and I am still not sure I understand how to build a class in R for oop. I thought that since I understand the oop syntex of Java and VB, I am wondering if the R programmig experts could help me out by comparing and contrasting the oop syntex in R with that of Java. For example, the basic class structure in Java is like this:

public class Bicycle {

    // *the Bicycle class has three fields*     public int cadence;
    public int gear;
    public int speed;

    // *the Bicycle class has one constructor*     public Bicycle(int startCadence, int startSpeed, int startGear) {

        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;


    // *the Bicycle class has four methods*     public void setCadence(int newValue) {

        cadence = newValue;

    public void setGear(int newValue) {

        gear = newValue;

    public void applyBrake(int decrement) {

        speed -= decrement;

    public void speedUp(int increment) {

        speed += increment;


Could one of the R experts please illustrate the R class syntex for writing the R equivalent of the Java Bicycle class above?

Also, in Java, inheritance is done like this:

public class MountainBike extends Bicycle {

    // *the MountainBike subclass has one field*     public int seatHeight;

    // *the MountainBike subclass has one constructor*     public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {

        super(startCadence, startSpeed, startGear);
        seatHeight = startHeight;


    // *the MountainBike subclass has one method*     public void setHeight(int newValue) {

        seatHeight = newValue;


What would be the R oop syntex for inheritance in the case of the MontainBike class?



	[[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 05 Feb 2008 - 13:24:25 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 Tue 05 Feb 2008 - 14:30:11 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