<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Checks if a class is currently being initiated initiated</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="R.css" />
</head><body>

<table width="100%" summary="page for isBeingCreated.Class"><tr><td>isBeingCreated.Class</td><td style="text-align: right;">R Documentation</td></tr></table>

<h2>Checks if a class is currently being initiated initiated</h2>

<h3>Description</h3>

<p>Checks if a class is currently being initiated initiated.
When extending a class for the first time, which is
typically done in a constructor, a static instance of the class is
created by calling the constructor without parameters.
This method provides a way to detect that second call inside the
constructor.
</p>


<h3>Usage</h3>

<pre>
## S3 method for class 'Class'
isBeingCreated(this, ...)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>...</code></td>
<td>
<p>Not used.</p>
</td></tr>
</table>


<h3>Value</h3>

<p>Returns <code>TRUE</code> if a static instance exists, otherwise <code>FALSE</code>.
</p>


<h3>Author(s)</h3>

<p>Henrik Bengtsson</p>


<h3>See Also</h3>

<p>For more information see <code>Class</code>.
</p>


<h3>Examples</h3>

<pre>
setConstructorS3("Car", function(brand=NULL, nbrOfWheels=0) {
  if(!isBeingCreated(Car)) {
    if (is.null(brand))
      throw("A car must have a brand")
     
    if (nbrOfWheels &lt;= 0)
      throw("A car must have one or more wheels: ", nbrOfWheels)
  }

  extend(Object(), "Car",
    .brand = brand,
    .nbrOfWheels = nbrOfWheels
  )
})

setMethodS3("as.character", "Car", function(this, ...) {
  cat(class(this)[1], ":", this$.brand, " with ",
                     this$.nbrOfWheels, " wheels.", sep="")
})

print(Car("Volvo", 4))
print(Car("BMW", 4))
print(Car("Tyrrell P34", 6))
print(Car("T-Rex", 3))
</pre>


</body></html>
