天道酬勤,学无止境

generic-function

Is 'show' a normal S4 generic function?

Question 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

2022-04-04 09:46:08    分类:技术分享    r   show   s4   generic-function

Common Lisp: Generic Function Specializing on Array Length

Question 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 `single-float). Now I am writing a package called vectors which will contain generic functions to

2022-02-10 16:36:49    分类:技术分享    types   common-lisp   generic-function

R: Create custom output from list object

Question 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 a convenient way to do this? Answer1 If you want to use this kind of print regularly i would

2021-06-22 17:02:51    分类:技术分享    r   generic-function