Learn R Programming

ProTrackR (version 0.4.4)

PTPattern-method: Coerce to or replace PTPattern

Description

This method will coerce a set of objects to a PTPattern object. It can also be used to select specific patterns from PTModule objects and replace the selected PTPattern.

Usage

# S4 method for raw,missing
PTPattern(x)

# S4 method for matrix,missing PTPattern(x)

# S4 method for PTModule,numeric PTPattern(x, pattern)

# S4 method for PTModule,numeric,PTPattern PTPattern(x, pattern) <- value

Value

When PTPattern is used, a PTPattern object based on x is returned.

When PTPattern<- is used, object x is returned in which the selected PTPattern is replaced with value.

Arguments

x

Object (any of raw data, a 64 by 16 matrix of raw data, a 64 by 4 matrix of character strings, or a PTModule) to coerce to a PTPattern. See details below for the required format of x.

pattern

When x is a PTModule, provide an index of the pattern that needs to be coerced to a PTPattern. Note that ProTracker uses indices for patterns that start at zero, whereas R uses indices that start at one. Hence add one to an index obtained from a PTModule object (e.g., x$pattern.order).

value

An object of PTPattern with which the PTPattern object at the specified index in object x needs to be replaced.

Author

Pepijn de Vries

Details

Method to coerce x to class PTPattern.

When x is a 64 by 16 matrix of raw data, each row implicitly represents the PTCell objects of each of the four tracks. Each PTCell consists of four raw values. The values in each row are formatted accordingly, where the values of the cells of each track are concatenated. See PTCell documentation for more details on the raw format of a PTCell object.

When x is a 64 by 16 matrix of character representations of PTCell objects, the character representation must be conform the specifications as documented at the PTCell.

When x is of class PTModule, the PTPattern at the specified index (pattern) is returned, or can be replaced.

See Also

Other pattern.operations: MODPlugToPTPattern(), PTPattern-class, PTPatternToMODPlug(), appendPattern(), deletePattern(), pasteBlock(), patternLength(), patternOrderLength(), patternOrder()

Examples

Run this code
## This will create an 'empty' PTPattern with
## all 0x00 values, which is equivalent to
## new("PTPattern"):
PTPattern(as.raw(0x00))

## Create a PTPattern based on repeated
## PTCell character representations:
pat <- PTPattern(matrix("F#2 1A 20A", 64, 4))

data("mod.intro")

## Replace the first pattern in the patternOrder
## table in mod.intro with 'pat' (don't forget to
## add one (+1) to the index):
PTPattern(mod.intro,
          patternOrder(mod.intro)[1] + 1) <- pat

Run the code above in your browser using DataLab