Book Image

R Object-oriented Programming

By : Kelly Black
Book Image

R Object-oriented Programming

By: Kelly Black

Overview of this book

Table of Contents (19 chapters)
R Object-oriented Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
4
Calculating Probabilities and Random Numbers
Package Management
Index

The simulation classes


The simulation classes consist of three parts. The Simulation class is the base class, and two classes, DiscreteSimulation and ContinuousSimulation, are derived from the base class. We assume that the definitions for these classes are kept in a separate file, simulationS3.R.

The base class, Simulation, is used to manage the parameters and results for a single simulation. The data includes the final time used in the simulation and accessor methods are defined for the data:

########################Create the base simulation class
##
## This is used to represent a single simulation
Simulation <- function()
  {
      
      ## Create the list used to represent an
      ## object for this class
      me = list(
          simulationResults = matrix(0)
          )

      ## Set the name for the class
      class(me) <- append(class(me),"Simulation")
      return(me)


  }# Set the data values that are the result of a simulation.
setSimulation <- function(theSimulation...