Title: | RBioinf |
---|---|
Description: | Functions and datasets and examples to accompany the monograph R For Bioinformatics. |
Authors: | Robert Gentleman |
Maintainer: | Robert Gentleman <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.67.0 |
Built: | 2024-12-19 03:36:33 UTC |
Source: | https://github.com/bioc/RBioinf |
These functions are used to demonstrate some of the debugging facilities in R.
asSimpleVector(x, mode = "logical") convertMode(from, to) setVNames(x, nm) subsetAsCharacter(x, i, j)
asSimpleVector(x, mode = "logical") convertMode(from, to) setVNames(x, nm) subsetAsCharacter(x, i, j)
x |
input |
mode |
the mode of |
from |
a parameter |
to |
another parameter |
nm |
names for |
i |
an index |
j |
another index |
A set of functions that can be used to demonstrate debugging principles and practices.
asSimpleVector
converts the argument x
to a simple R
vector of the given mode preserving names, dimension and dimnames.
subsetAsCharacter
calculates either a vector or a matrix subset of the
argument x
and returns the subset after converting it to be of
mode character. It uses asSimpleVector
to do the conversion to
character and thus also preserves any names, dimension or dimnames in the
subset.
setVNames
sets the names of the given vector x
to
the argument nm
and then converts x
to numeric
using asSimpleVector
.
convertMode
converts its first argument to
the mode of the second argument.
Various values are returned.
S. DebRoy
asSimpleVector(list(a = 1, b = 2), "character")
asSimpleVector(list(a = 1, b = 2), "character")
Given either a list of classes, or a single class, these functions produce a graph, with the classes as nodes and edges representing subclass/superclass relationships.
classList2Graph(class, fullNames=TRUE) class2Graph(class, fullNames=TRUE)
classList2Graph(class, fullNames=TRUE) class2Graph(class, fullNames=TRUE)
class |
Either the name of a single class, |
fullNames |
Indicates whether to use fully qualified (by package) names for the class. |
Edges are directed, and go from superclasses to subclasses (more specialized to less specialized).
A graph, typically an instance of the graphNEL
class.
R. Gentleman
graphClasses = getClasses("package:graph") classList2Graph(graphClasses)
graphClasses = getClasses("package:graph") classList2Graph(graphClasses)
There are a number of different methods for computing the class linearization.
The methods described here are discussed in more detail in the vignette
for this package. LPO
and computeClassLinearization
are
aliases, the former being easier to type, the latter more descriptive.
computeClassLinearization(inClass, C3 = FALSE) LPO(inClass, C3 = FALSE)
computeClassLinearization(inClass, C3 = FALSE) LPO(inClass, C3 = FALSE)
inClass |
The class for which a linearization of its is wanted. |
C3 |
Whether or not to use the C3 method in computing the linearization. |
For many different computations, especially method dispatch, an algorithm for specifying a linear order of the class inheritance tree is needed. All object oriented programming languages support the computation of a linearization. Local precedence order (LPO) uses the order of the direct superclasses, given in the class definition, in computing the linearization, with earlier superclasses considered more specific than later ones. If there are no duplicate class labels in the hierarchy then this is then simply a bread-first search of the superclass definitions. But when one or more classes are inherited from different superclasses this definition becomes more complicated, and can in fact not be satisfied.
A vector with the class linearization, the.
R. Gentleman
Monotonic Superclass Linearization for Dylan, K. Barrett and others, 1996, OOPSLA
setClass("object") setClass("grid-layout", contains="object") setClass("horizontal-grid", contains="grid-layout") setClass("vertical-grid", contains="grid-layout") setClass("hv-grid", contains=c("horizontal-grid", "vertical-grid")) LPO("hv-grid")
setClass("object") setClass("grid-layout", contains="object") setClass("horizontal-grid", contains="grid-layout") setClass("vertical-grid", contains="grid-layout") setClass("hv-grid", contains=c("horizontal-grid", "vertical-grid")) LPO("hv-grid")
A function to print a function together with relevant line
numbers. These can be used to decide where to set trace
functions etc.
printWithNumbers(f)
printWithNumbers(f)
f |
Any R function. |
The function is printed, all lines that correspond to potential break points in the code are numbered.
The function is invoked primarily for its side effect; the printing of the function with line numbers. However, the character vector is returned and could be used as input for other tools.
R. Gentleman
printWithNumbers(convertMode)
printWithNumbers(convertMode)
This function generates random DNA sequences, nucleotides are sampled with frequency 0.25 each.
randDNA(n)
randDNA(n)
n |
The length of the sequence desired. |
This function generates random sequences of A, C, T and G. Real DNA is quite different, so one should not use these sequences for much other than pedagogical purposes.
A length one character vector, with n
characters randomly
chosen from A, C, T and G.
R. Gentleman
randDNA(100)
randDNA(100)
A function that prints the requested monthly calendar. The function
relies on pipe
and the Unix routine cal
.
Rcal(month, year)
Rcal(month, year)
month |
An optional argument, if supplied a number between 1 and 12. |
year |
An optional argument, if supplied a year. |
By default this prints the calendar for the current month and year. Otherwise if a month and year are given and then the calendar for that month and year is printed.
No value is returned.
R. Gentleman
if (.Platform$OS.type != "windows") { Rcal() Rcal(6, 1970) }
if (.Platform$OS.type != "windows") { Rcal() Rcal(6, 1970) }
This function takes the name of either a class or a generic function and finds a set of related manual pages. The user then selects which manual page they want.
S4Help(name, signature)
S4Help(name, signature)
name |
The name of the S4 class or generic function. |
signature |
Currently not used. |
For S4 classes, the class and any superclasses are found and the user can select which manual page they want. If the supplied name corresponds to a generic function, then that function, or any of its methods can be selected.
NULL
is returned, invisibly. The function is called purely for side
effect.
R. Gentleman
## Not run: S4Help("classRepresentation") S4Help("coerce") ## End(Not run)
## Not run: S4Help("classRepresentation") S4Help("coerce") ## End(Not run)
This function takes as input any vector, matrix or array of numeric values and passes that array out to C, where it is printed, in order from the first value stored to the last, regardless of the dimensioning information. And information about the location is printed as well.
simplePVect(iV)
simplePVect(iV)
iV |
The input vector. |
As above.
NULL
is returned. The function is called only for its side effects.
R. Gentleman
simplePVect(1:3)
simplePVect(1:3)
A simple interface function to R's C level rng code. Primarily a pedagogical tool to accompany the monograph R for Bioinformatics.
simpleRand(x, y = "notused")
simpleRand(x, y = "notused")
x |
The number of random numbers to generate. |
y |
Not used in the base implementation, but various exercises involve making use of this. |
An interface, via .Call
to R's underlying RNG cod.
The random numbers generated, plus information about the RNG used.
R. Gentleman
simpleRand(4)
simpleRand(4)
The function demonstrates how to access R's internal sorting routines
via the .Call
interface.
simpleSort(x)
simpleSort(x)
x |
The vector to be sorted. |
A simple interface to sorting routines in R. It is intended to be modified following exercises in the accompanying monograph.
The sorted vector.
R. Gentleman
simpleSort(c(4,2,6))
simpleSort(c(4,2,6))
Given the name of a S4 class, or a S4 classRepresentation object, these functions return either the names of the direct subclasses or of the direct superclasses.
subClassNames(x) superClassNames(x)
subClassNames(x) superClassNames(x)
x |
Either the name of a class, or an instance of classRepresentation. |
If a name is given then getClass
is used to get the
class representation object.
A character vector, listing either the direct subclasses or the direct superclasses, depending on which function was called.
R. Gentleman
subClassNames("matrix") superClassNames("matrix")
subClassNames("matrix") superClassNames("matrix")
This function computes and returns a list of all super classes
given a classRepresentation
.
superClasses(x)
superClasses(x)
x |
A |
This function needs to be rationalized with superClassNames
.
A list of the super classes.
R. Gentleman
superClassNames(getClass("graphNEL"))
superClassNames(getClass("graphNEL"))
This function can turn on tracing for all methods (or a subset of the methods) of a generic function. It is useful when debugging, as it can help see how the methods are being traversed.
traceMethods(generic, traceStrings, tracer) untraceMethods(generic, methodSigs)
traceMethods(generic, traceStrings, tracer) untraceMethods(generic, methodSigs)
generic |
The name of the generic function, quoted or not. |
traceStrings |
A string to print when each method is entered. |
tracer |
A function to insert as the tracer, if missing a function that prints the methods signature is used. |
methodSigs |
A set of method signatures, as a character vector, that tracing will be turned off for. |
traceMethods
uses showMethods
to figure out what methods
exist, and what the signatures are. It then uses trace
to set a trace on
all methods.
untraceMethods
uses the returned value of traceMethods
,
or any other similar construct to untrace methods for a generic.
A vector of method signatures is returned. This could be then used to untrace the methods (something else to automate).
R. Gentleman
## Not run: traceMethods{slice} untraceMethods{slice} ## End(Not run)
## Not run: traceMethods{slice} untraceMethods{slice} ## End(Not run)