R/generics.R

Defines functions genericFuns s3Generics s4Generics isS3Generic isS4Generic

# what about none standard generic calls
isS4Generic = function(x) if(is.function(x)) length(findCallsTo(body(x), "standardGeneric")) > 0 else FALSE
isS3Generic = function(x) if(is.function(x)) length(findCallsTo(body(x), "UseMethod")) > 0 else FALSE

s4Generics =
function(env, asNames = TRUE)
    genericFuns(env, asNames, isS4Generic)

s3Generics =
function(env, asNames = TRUE)
  genericFuns(env, asNames, isS3Generic)

genericFuns =
function(env, asNames = TRUE, predicate = isS3Generic)            
{
    if(is.character(env))
	   env = getNamespace(gsub("^package:", "", env))
	   
    generic = sapply(as.list(env, TRUE), predicate)
	# table(generic)
    if(asNames)
    	names(generic)[generic]
    else
        generic	  
}
duncantl/CodeAnalysis documentation built on April 28, 2024, 6:01 p.m.