Rev 44243 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/seemsS4Object.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{seemsS4Object}\alias{seemsS4Object}\title{Heuristic test for an object from an S4 class}\description{Returns \code{TRUE} if \code{object} has been generated froma formally defined (\sQuote{S4}) class. DEPRECATED: use\code{isS4(object)} instead.}\usage{seemsS4Object(object)}\arguments{\item{object}{Any object.}}\details{The \code{\link{class}} of the object is examined for the \code{"package"}attribute included when objects are generated from an S4 class. Thetest in this function has been superseded by an internal bit setwhen S4 objects are generated.The \code{seemsS4Object} function is deprecated and will be removed.The test can be fooled in at least two ways:\enumerate{\item It will give \code{TRUE} incorrectly if someone puts a\code{"package"} string attribute on the class of an S3 object.Presumably unlikely.\item It will give \code{FALSE} incorrectly for class definitions andcertain other objects for packages that have not been \code{INSTALL}edsince the \code{seemsS4Object} was added to R. See the Warning below.}}\value{Always \code{TRUE} or \code{FALSE} for any object.}\section{Warnings}{One motivation for this function is to prevent standard S3 vectoroperations from being applied to S4 objects that are not vectors.Note that \code{seemsS4Object()} alone is \emph{not} that test. Onealso needs to check that the object does not inherit from class\code{"vector"}. See the examples.The existence of a class definition for the object's class is also notequivalent. S4 class definitions are recorded for S3 classes registeredvia \code{\link{setOldClass}}, but registering does not change the classof such objects, so they are not judged to be S4 objects (and should notbe).Certain other S4 objects used to be generated without the\code{"package"} attribute in earlier builds of R, notably classdefinitions. Packages using S4 objects \emph{must} be reinstalled witha version of R recent enough to contain the \code{seemsS4Object}function (e.g., \R 2.3.0 or later).}\examples{\dontrun{## this is deprecatedseemsS4Object(1) # FALSEseemsS4Object(getClass(class(1))) #TRUE## how to test for an S4 object that is not a vectorS4NotVector <-function(object) seemsS4Object(object) && !is(object, "vector")setClass("classNotNumeric", representation(x="numeric", y="numeric"))setClass("classWithNumeric", representation(y="numeric"),contains = "numeric")obj1 <- new("classNotNumeric", x=1, y=2)obj2 <- new("classWithNumeric", 1, y=2)seemsS4Object(obj1); seemsS4Object(obj2) # TRUE, TRUES4NotVector(obj1); S4NotVector(obj2) # TRUE, FALSEremoveClass("classNotNumeric")removeClass("classWithNumeric")}}\keyword{programming}\keyword{classes}