s4

How to add class-specific alias without generic alias using Roxygen2?

断了今生、忘了曾经 提交于 2019-12-01 02:45:32
A simple example is that I have created an extension to show , which is a S4 base method. I don't want to cause a disambiguation fork by re-documenting show in my package, and I also want to consolidate the documentation of my extension to show in the documentation for the new class, myPkgSpClass , by adding an alias for show,myPkgSpClass-method . #' @export #' @aliases show,myPkgSpClass-method #' @rdname myPkgSpClass-class setMethod("show", "myPkgSpClass", function(object){ show(NA) }) The problem I'm having, is that this results in an serious warning during documentation-build by roxygen2,

How to add class-specific alias without generic alias using Roxygen2?

六月ゝ 毕业季﹏ 提交于 2019-11-30 22:32:30
问题 A simple example is that I have created an extension to show , which is a S4 base method. I don't want to cause a disambiguation fork by re-documenting show in my package, and I also want to consolidate the documentation of my extension to show in the documentation for the new class, myPkgSpClass , by adding an alias for show,myPkgSpClass-method . #' @export #' @aliases show,myPkgSpClass-method #' @rdname myPkgSpClass-class setMethod("show", "myPkgSpClass", function(object){ show(NA) }) The

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

筅森魡賤 提交于 2019-11-30 14:18:55
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 unfortunately this gives the error: plot.new has not yet been called I have also no idea, how I can manipulate e

Reference Classes, tab completion and forced method definition

青春壹個敷衍的年華 提交于 2019-11-30 13:55:58
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"), methods = list( addone = function(){ a <<- a+1 }, initialize = function(){ a <<- 1 } ) ) example <- test

Rd file name conflict when extending a S4 method of some other package

杀马特。学长 韩版系。学妹 提交于 2019-11-30 10:40:51
Actual question How do I avoid Rd file name conflicts when a S4 generic and its method(s) are not necessarily all defined in the same package (package containing (some of) the custom method(s) depends on the package containing the generic) and using roxygenize() from package roxygen2 to generate the actual Rd files? I'm not sure if this is a roxygen2 problem or a common problem when the generic and its method(s) are scattered across packages (which IMHO in general definitely is a realistic use-case scenario if you follow a modular programming style). What's the recommended way to handle these

sum of S4 objects in R

筅森魡賤 提交于 2019-11-30 08:48:25
I have a S4 class and I would like to define the linear combination of these objects. Is it possible to dispatch * and + functions on this specific class? here is an example: setClass("yyy", representation(v="numeric")) setMethod("+", signature(e1 = "yyy", e2 = "yyy"), function (e1, e2) e1@v + e2@v) setMethod("+", signature(e1 = "yyy", e2 = "numeric"), function (e1, e2) e1@v + e2) then, > y1 <- new("yyy", v = 1) > y2 <- new("yyy", v = 2) > > y1 + y2 [1] 3 > y1 + 3 [1] 4 The + operator is part of the Arith group generic (see ?GroupGenericFunctions ) so one can implement all functions in the

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

亡梦爱人 提交于 2019-11-30 06:03:57
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 methods that are dispatched to based on the signature of the function call -- here the class of its first

Example of Using an S3 Class in a S4 Object

元气小坏坏 提交于 2019-11-30 05:18:49
问题 I want to include an RODBC connection as part of S4 object. It looks like RODBC is S3. For example: setClass( Class="Node", representation=representation( nodeName = "character", connection = "RODBC" ) ) Throws undefined slot classes . It looks like I want to use setOldClass , but I am having trouble figuring out how to use it. Assuming I do want setOldClass , How would I use setOldClass so that I can include my RODBC connection as slot to my Node class? 回答1: Although the documentation is

Is S4 method dispatch slow?

廉价感情. 提交于 2019-11-30 05:12:12
My S4 class has a method that is called many times. I noticed that the execution time is much slower than it would be if a similar function was called independently. So I added a slot with type "function" to my class and used that function instead of the method. The example below shows two ways of doing this, and both of them run much faster than the corresponding method. Also, the example suggests that the lower speed of the method is not due to method having to retrieve data from the class, since the functions are faster even when they also do that. Of course, this way of doing things is not

What's the difference between setMethod(“$<-”) and set setReplaceMethod(“$”)?

主宰稳场 提交于 2019-11-30 03:34:48
问题 Question When programming in r with the s4 OOP system, when one have to use setReplaceMethod ? I don't see what's the difference with the setMethod when adding <- to the name of the function. Does setMethod("$<-") and setReplaceMethod("$") are equal? Documentation I didn't find anything in the documentation with ?setReplaceMethod or ??setReplaceMethod . There is nothing except the usage. In StackOverflow, there is several questions about setReplaceMethod but none helping. I started to search