General S4 Class Extractor Functions

Share:

Description

A collection and description of functions to extract slots from S4 class objects.

The extractor functions are:

getModel Extracts the model slot from a S4 object,
getTitle Extracts the title slot from a S4 object,
getDescription Extracts the description slot from a S4 object,
getSlot Extracts a specified slot from a S4 object,
getArgs Shows the arguments of a S4 function.

Since R version 2.14.0, a generic getCall() is part of R; for earlier versions, we had provided a simple version for S4 objects.

Usage

1
2
3
4
5
6
7
getModel(object)
getTitle(object)
getDescription(object)

getSlot(object, slotName)

getArgs(f, signature)

Arguments

f

a generic function or the character-string name of one.

object

an object of class S4.

signature

the signature of classes to match to the arguments of f

slotName

a character string, the name of the slot to be extracted from the S4 object.

...

Further arguments to be passed to function.

Value

getModel
getTitle
getDescription
getSlot
return the content of the slot.

getArgs returns the names of the arguments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Example S4 Representation:
   # Hyothesis Testing with Control Settings
   setClass("hypTest",
     representation(
       call = "call",
       data = "numeric",
       test = "list",
       description = "character")
   )

## Shapiro Wilk Normaility Test
   swTest = function(x, description = "") {
     ans = shapiro.test(x)
     class(ans) = "list"
     new("hypTest",
       call = match.call(),
       data = x,
       test = ans,
       description = description)
   }
   test = swTest(x = rnorm(500), description = "500 RVs")

## Extractor Functions:
   isS4(test)
   getCall(test)
   getDescription(test)

## get arguments
args(returns)
getArgs(returns)
getArgs("returns")
getArgs(returns, "timeSeries")
getArgs("returns", "timeSeries")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.