getS4SlotGSetterGenericAndMethods {DesignPatterns}R Documentation

AUTOMATIC WRAPPED GETTER AND SETTER GENERICS AND METHODS FOR S4 CLASSES

Description

Automatic wrapping getter and setter (GSetter) generics and methods for S4 classes, like the functionality implemented in many IDEs for other programming languagues like Java or C#.

Usage

getS4SlotGSetterGenericAndMethods(class, slot)
getS4AllSlotsGSetterGenericAndMethods(class)

writeS4SlotGSetterGenericAndMethods(class, slot, con=stdout(), ...)
writeS4AllSlotsGSetterGenericAndMethods(class, con=stdout(),...)

getOwnSlotNames(class)
getS4AllOwnSlotsGSetterGenericAndMethods(class)
writeS4AllOwnSlotsGSetterGenericAndMethods(class, con=stdout(),...)

Arguments

class Name of a S4 class
slot Slot name of a S4 class, must be of length one
con Connection to write the output to, for example stardard output of R (stdout()) or a file name.
... Other parameters passed to writeLines.

Details

We use the abbreviation GSetter to refer to the getter (aka accessor) and the setter (aka mutator) of S4 class slots. The former gets the value of the slot, while the later specify the value of the slot.

getS4SlotGSetterGenericAndMethods returns a string containing both generics and methods to get and set the value of the given slot in the specified class. It only receives one slot at a time. The results can be written into plain text file with the wrapper writeS4SlotGSetterGenericAndMethods. The user could comment out some of the generics or methods in the output file in case they do not need them.

getS4AllSlotsGSetterGenericAndMethods returns the generics and methods of getters and setters of all slots in the specified class in the form of a vector of character strings. User could use writeS4AllSlotsGSetterGenericAndMethods to write them into plain text files, which can be moved later to the R package.

getS4AllOwnSlotsGSetterGenericANdMethods returns the generic and methods of getters and setter of all own slots in the specified class, that is, excluding the ones defined by its known superclass. Its use is similar to getS4AllSlotsGSetterGenericANdMethods. It also has the ‘write’ wrapper for easy output. It calls getOwnSlotNames to determine the slots owned merely by the extended class.

Value

One or a vector of character strings containing the text form of the generics and methods.

Examples

setClass("track", representation(xx="numeric", yy="numeric"))
## the trailing "\n" is just for the beauty of output
cat(getS4SlotGSetterGenericAndMethods("track", "xx"), "\n")
## it equals to
writeS4SlotGSetterGenericAndMethods("track", "xx", con=stdout())


cat(getS4AllSlotsGSetterGenericAndMethods("track"), "\n")
tmp <- tempfile()
writeS4AllSlotsGSetterGenericAndMethods("track", con=tmp)
source(tmp)

## show subclass
setClass("carTrack", representation(carName="character"), contains="track")
cat(getS4AllOwnSlotsGSetterGenericAndMethods("carTrack"), "\n")
## alternatively
writeS4AllOwnSlotsGSetterGenericAndMethods("carTrack", con=stdout())

[Package DesignPatterns version 0.1.2 Index]