###--- >>> `as' <<<----- Force an Object to Belong to a Class

	## alias	 help(as)
	## alias	 help(as<-)
	## alias	 help(coerce)
	## alias	 help(coerce<-)
	## alias	 help(setAs)

##___ Examples ___:

## using the definition of class "track" from Classes


setClass("track",
            representation(x="numeric", y="numeric"))
setClass("trackCurve",
            representation("track", smooth = "numeric"))


setAs("track", "numeric", function(from)from@y)

t1 <- new("track", x=1:20, y=(1:20)^2)

as(t1, "numeric")

## The next example shows:
##  1. A virtual class to define setAs for
##     several classes at once.
##  2. as() using inherited information

setClass("ca", representation(a = "character", id = "numeric"))

setClass("cb", representation(b = "character", id = "numeric"))

setClass("id")
setIs("ca", "id")
setIs("cb", "id")

setAs("id", "numeric", function(from) from@id)

CA <- new("ca", a ="A", id = 1)

CB <- new("cb", b = "B", id = 2)

setAs("cb", "ca", function(from)new("ca", a=from@b, id = from@id))

as(CB, "numeric")


## should generate an error (should have been a function of one argument)
try(setAs("track", "numeric", function(x, ...)x@y))




## Keywords: 'programming', 'classes', 'methods'.


