list_methods: List all methods associated with a generic function or a...

Description Usage Arguments Value Note See Also Examples

View source: R/list_methods.R

Description

List all S3 and/or S4 methods for a generic function or for a class. List all types for a method; types are variants for a given method defined in a way it is easy to add other variants dynamically (on the contrary to a usual type = or which = argument, like in plot.ts() or plot.lm(), respectively.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
list_methods(
  f = character(),
  class = NULL,
  S3 = TRUE,
  S4 = TRUE,
  mixed = TRUE,
  filter = getOption("svGUI.methods")
)

list_types(method, class = "default", strict = FALSE)

listMethods(
  f = character(),
  class = NULL,
  S3 = TRUE,
  S4 = TRUE,
  mixed = TRUE,
  filter = getOption("svGUI.methods")
)

listTypes(method, class = "default", strict = FALSE)

Arguments

f

The name of the generic function (character string), used only when class = NULL.

class

The name of a class.

S3

If TRUE, list of S3 methods.

S4

If TRUE, list of S4 methods.

mixed

If TRUE, S3 and S4 methods are mixed together in a character vector, otherwise, S3 and S4 methods are reported separately in a list.

filter

A list of methods to consider when listing class methods. Only classes in this list that are defined for the class are returned. Store the list of methods you want in the options "svGUI.methods". The package proposes a reasonable starting point on loading if this option is not defined yet.

method

The method name.

strict

Do we list only types for the class (TRUE), or all possible types, including for inherited objects, and default ones FALSE, by default)?

Value

For list_methods(), if mixed = TRUE, a list with components:

Otherwise, a character vector with the requested methods.

For list_types(), a vector with character strings with methods' type names.

Note

list_types() is only useful for special generic functions with type argument like view, copy or export. These functions offer a mechanism to easily add custom types, and the present function list them. For S3 objects a type is simply a function whose name is : method_type.class. So, adding new types for method is very easy to implement.

See Also

obj_menu()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Generic functions
list_methods("t.test")               # S3
list_methods("show", mixed = FALSE)	# S4
list_methods("ls") # None, not a generic function!

# Classes
# Only the following methods are considered
getOption("gui.methods")
list_methods(class = "data.frame")
list_methods(class = "lm")

# List method types
list_types("view")  # All default view types currently defined
list_types("view", "data.frame")
list_types("view", "data.frame", TRUE) # None, except if you defined custom views!

Example output

Attaching package: 'svMisc'

The following object is masked from 'package:utils':

    ?

[1] "x=\"default\"" "x=\"formula\""
$S3
character(0)

$S4
 [1] "object=\"ANY\""                      
 [2] "object=\"MethodDefinition\""         
 [3] "object=\"MethodDefinitionWithTrace\""
 [4] "object=\"MethodSelectionReport\""    
 [5] "object=\"MethodWithNext\""           
 [6] "object=\"MethodWithNextWithTrace\""  
 [7] "object=\"ObjectsWithPackage\""       
 [8] "object=\"classGeneratorFunction\""   
 [9] "object=\"classRepresentation\""      
[10] "object=\"envRefClass\""              
[11] "object=\"externalRefMethod\""        
[12] "object=\"genericFunction\""          
[13] "object=\"genericFunctionWithTrace\"" 
[14] "object=\"namedList\""                
[15] "object=\"oldClass\""                 
[16] "object=\"refClassRepresentation\""   
[17] "object=\"refMethodDef\""             
[18] "object=\"refObjectGenerator\""       
[19] "object=\"signature\""                
[20] "object=\"sourceEnvironment\""        
[21] "object=\"traceable\""                

character(0)
NULL
[1] "formula" "head"    "plot"    "summary" "tail"   
[1] "anova"     "confint"   "formula"   "logLik"    "plot"      "predict"  
[7] "residuals" "summary"   "vcov"     
character(0)
character(0)
character(0)

svMisc documentation built on Oct. 12, 2021, 1:08 a.m.