setConstructorS3 | R Documentation |
Defines a class in R.oo/S3 style. What this function currently does is simply creating a constructor function for the class.
## Default S3 method:
setConstructorS3(name, definition, private=FALSE, protected=FALSE, export=TRUE,
static=FALSE, abstract=FALSE, trial=FALSE, deprecated=FALSE, envir=parent.frame(),
enforceRCC=TRUE, ...)
name |
The name of the class. |
definition |
The constructor definition. Note: The constructor
must be able to be called with no arguments, i.e. use default values
for all arguments or make sure you use |
static |
If |
abstract |
If |
private |
If |
protected |
If |
export |
A |
trial |
If |
deprecated |
If |
envir |
The environment for where the class (constructor function) should be stored. |
enforceRCC |
If |
... |
Not used. |
Note: If a constructor is not declared to be private nor protected, it will be declared to be public.
The requirement that a constructor function should be callable without
arguments (e.g. MyConstructor()
) is because that call is used
to create the static instance of a class. The reason for this is that
a static instance of the class is created automatically when the
constructor is called the first time (only), that is,
when the first of object of that class is created.
All classes have to have a static instance.
To make a constructor callable without arguments, one can either make
sure all arguments have default values or one can test for missing
arguments using missing()
.
For instance the following definition is not correct:
setConstructorS3("Foo", function(x) extend(Object(), "Foo", x=x))
whereas this one is
setConstructorS3("Foo", function(x=NA) extend(Object(), "Foo", x=x))
If argument enforceRCC
is TRUE
,
the class name is validated so it starts with a letter and it
also gives a warning
if its first letter is not capital. The
reason for this is to enforce a naming convention that names classes
with upper-case initial letters and methods with lower-case initial
letters (this is also the case in for instance Java).
Henrik Bengtsson
To define a method see setMethodS3
.
For information about the R Coding Conventions, see
RccViolationException
.
For a thorough example of how to use this method see Object
.
## Not run: For a complete example see help(Object).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.