generic-function

Is 'show' a normal S4 generic function?

允我心安 提交于 2019-12-22 08:29:46
问题 I'm trying to create a method for my class, which inherits from data.frame. I was originally hoping just to inherit the 'show' method from data.frame as well, but I'm also fine with writing my own. I defined my class and 'show' method as follows: setClass("SCvec", representation(auth = "character", dev = "character", sensor = "character", channel = "character", starttime = "character", endtime = "character"), contains="data.frame") setMethod("show", signature(x="SCvec"), function(x) print(x))

R: Create custom output from list object

人盡茶涼 提交于 2019-12-20 03:44:11
问题 I have a list that stores different data types and objects: header <- "This is a header." a <- 10 b <- 20 c <- 30 w <- 1:10 x <- 21:30 y <- 51:60 z <- 0:9 mylist <- list(header = header, const = list(a = a, b = b, c = c), data = data.frame(w,x,y,z)) Now I want R to display this list in the following format: This is a header. Values: a: 10 b: 20 c: 30 Data: w x y z 1 1 21 51 0 2 2 22 52 1 3 3 23 53 2 4 4 24 54 3 5 5 25 55 4 6 6 26 56 5 7 7 27 57 6 8 8 28 58 7 9 9 29 59 8 10 10 30 60 9 Is there

Replacing an ordinary function with a generic function

杀马特。学长 韩版系。学妹 提交于 2019-12-12 12:13:39
问题 I'd like to use names such as elt, nth and mapcar with a new data structure that I am prototyping, but these names designate ordinary functions and so, I think, would need to be redefined as generic functions. Presumably it's bad form to redefine these names? Is there a way to tell defgeneric not to generate a program error and to go ahead and replace the function binding? Is there a good reason for these not being generic functions or is just historic? What's the considered wisdom and best

Common Lisp: Generic Function Specializing on Array Length

蓝咒 提交于 2019-12-11 09:39:09
问题 I am just getting started with generic functions and am wondering if this is possible (I really hope so!). I have made 3 packages for handling vectors of different lengths: vector2, vector3 and vector4 . Each package has functions that handle vectors of that length: vector2:normalize - for normalizing *vector2s* vector3:normalize - for normalizing *vector3s* etc. My vectors are typed arrays (for speed and memory use as this is for writing games) so a vector3 is: (make-array 3 :element-type

Is 'show' a normal S4 generic function?

不羁的心 提交于 2019-12-05 14:05:39
I'm trying to create a method for my class, which inherits from data.frame. I was originally hoping just to inherit the 'show' method from data.frame as well, but I'm also fine with writing my own. I defined my class and 'show' method as follows: setClass("SCvec", representation(auth = "character", dev = "character", sensor = "character", channel = "character", starttime = "character", endtime = "character"), contains="data.frame") setMethod("show", signature(x="SCvec"), function(x) print(x)) when I type show in the R console, it prints out: standardGeneric for "show" defined from package