s4

How to specify in which order to load S4 methods when using roxygen2

荒凉一梦 提交于 2019-12-21 09:13:07
问题 I ran into following problem already multiple times. Say you have two classes, classA and classB described in the following files classA.R : #' the class classA #' #' This is a class A blabla #' \section{Slots}{\describe{\item{\code{A}}{a Character}}} #' @ name classA #' @rdname classA #' @exportClass classA setClass("classA",representation(A="character")) And classB.R #' the class classB #' #' This is a class B blabla #' \section{Slots}{\describe{\item{\code{B}}{an object of class A}}} #' @

k-fold cross validation for GLMM S4 class model object

狂风中的少年 提交于 2019-12-21 02:59:06
问题 I have a GLMM object fit using the glmer function in R and want to perform k-fold cross validation. For simple GLMs I have used the CVbinary function from the DAAG pkg as seen below. > SimpleGLM <- glm(Res ~ Var1 + Var2, data = Data, family=binomial) > CVbinary(SimpleGLM, nfolds=10, print.details=TRUE) Fold: 3 2 4 1 7 10 6 9 5 8 Internal estimate of accuracy = 0.828 Cross-validation estimate of accuracy = 0.827 However, when a random term for IndID is added to the model an error (below)

Reference Class with custom field classes in R?

核能气质少年 提交于 2019-12-20 14:41:49
问题 I would like to use a custom reference class inside another reference class, but this code fails: nameClass <- setRefClass("nameClass", fields = list(first = "character", last = "character"), methods = list( initialize = function(char){ chunks <- strsplit(char,"\\.") first <<- chunks[[1]][1] last <<- chunks[[1]][2] }, show = function(){ cat("Special Name Class \n:") cat("First Name:") methods::show(first) cat("Last Name:") methods::show(last) } )) # this works fine nameClass$new("tyler.durden

Problems passing arguments with callNextMethod() in R

故事扮演 提交于 2019-12-19 06:19:58
问题 My question: Why is callNextMethod() not passing arguments as expected to the next method? Situation: Say I have two hierarchical classes foo and bar ( bar is subclass of foo ) for which I have a method foobar that can dispatch for both classes (i.e., has methods for both classes). Furthermore, the method for the (sub)class bar calls the method for foo after some calculations with callNextMethod() . Both methods have the same additional argument (with default) that should be passed to the

Formatting and manipulating a plot from the R package “hexbin”

雨燕双飞 提交于 2019-12-18 16:50:28
问题 I generate a plot using the package hexbin : # install.packages("hexbin", dependencies=T) library(hexbin) set.seed(1234) x <- rnorm(1e6) y <- rnorm(1e6) hbin <- hexbin( x = x , y = y , xbin = 50 , xlab = expression(alpha) , ylab = expression(beta) ) ## Using plot method for hexbin objects: plot(hbin, style = "nested.lattice") abline(h=0) This seems to generate an S4 object ( hbin ), which I then plot using plot . Now I'd like to add a horizontal line to that plot using abline , but

Reference Classes, tab completion and forced method definition

混江龙づ霸主 提交于 2019-12-18 16:16:29
问题 I am currently writing a package using reference classes. I have come across an issue which from reading various sources: Method initialisation in R reference classes Can't reliably use RefClass methods in Snowfall I gather is caused because reference methods are not all copied to every object in the class rather they are copied when first accessed. https://stat.ethz.ch/pipermail/r-devel/2011-June/061261.html As an example define: test <- setRefClass("TEST", fields = list( a = "numeric"),

Why, for an integer vector x, does as(x, “numeric”) trigger loading of an additional S4 method for coerce?

若如初见. 提交于 2019-12-18 12:03:51
问题 While my question is related to this recent one, I suspect its answer(s) will have to do with the detailed workings of R's S4 object system. What I would expect: ( TLDR; -- All indications are that as(4L, "numeric") should dispatch to a function whose body uses as.numeric(4L) to convert it to a "numeric" vector.) Whenever one uses as(object, Class) to convert an object to the desired Class , one is really triggering a behind-the-scenes call to coerce() . coerce() , in turn, has a bunch of

class in R: S3 vs S4

折月煮酒 提交于 2019-12-18 09:59:17
问题 I want to create a class in R, should I use S3 or S4 class? I read a lot of different things about them, is there one superior to the other one? 回答1: S3 can only dispatch on it's first argument, whereas S4 can dispatch on multiple arguments. If you want to be able to write methods for function foo that should do different things if given an object of class "bar" or given objects of class "bar" and "foobar" , or given objects of class "barfoo" and "foobar" , then S4 provides a far better way

dputting an S4 object

若如初见. 提交于 2019-12-18 05:55:07
问题 How would a person dput() an S4 object? I tried this require(sp) require(splancs) plot(0, 0, xlim = c(-100, 100), ylim = c(-100, 100)) poly.d <- getpoly() #draw a pretty polygon - PRETTY! poly.d <- rbind(poly.d, poly.d[1,]) # close the polygon because of Polygons() and its kin poly.d <- SpatialPolygons(list(Polygons(list(Polygon(poly.d)), ID = 1))) poly.d dput(poly.d) Notice that if I dput() an S4 object, I cannot reconstruct it again. Your thoughts? 回答1: As it currently stands, you cannot

S4 object with a pointer to a C struct

狂风中的少年 提交于 2019-12-18 05:16:06
问题 I have a third-party C library I am using to write an R extension. I am required to create a few structs defined in the library (and initialize them) I need to maintain them as part of an S4 object (think of these structs as defining to state of a computation, to destroy them would be to destroy all remaining computation and the results of all that has been already computed). I am thinking of creating a S4 object to hold pointers these structs as void* pointers but it is not at all clear how