s4

How to properly document S4 methods using roxygen2

孤街醉人 提交于 2019-11-28 03:04:13
I've seen some discussions in SO and other places regarding how this should be or will be done in future versions of Roxygen2. However, I am stuck. How should I go about documenting a S4 generic, as well as its methods, using Roxygen2? A working example for a brand new generic/methods, as well as an example for extending base S4 generic would be incredibly useful. I do not want to have to make separate (mostly) redundant documentation for each S4 method of the same generic. Due dilligence: I have tracked down a useful example for the "extract" method. However, it appears to be outdated and

How to develop a package in R?

末鹿安然 提交于 2019-11-28 02:47:11
I have written some functions in R using S4 classes. Now I want to build an R package out of these functions. How should I proceed? Is there anything that I should do differently because I have used S4 classes? Andrie Consult the following reference material: Chapter 1, Creating R packages , of the Writing R extensions manual. This is the canonical source. It's the ultimate reference point, but not necessarily the best starting point. A short presentation outlining the key ideas in package development and using the devtools package for development Hadley's devtools wiki , particular the

S4 Classes: Multiple types per slot

巧了我就是萌 提交于 2019-11-27 21:11:40
问题 Is it possible to create an S4 class, where one or more of the slots can be of multiple classes? For example. Let's say that you had a situation where data could be either a vector, or a data.frame. exampleClass <- setClass("exampleClass", representation(raw=c("data.frame","numeric","character"), anotherSlot=c("data.frame","numeric")) Or, is this the type of situation where defining a sub-class / super-class becomes necessary? PS: Searching for a useful tutorial on S4 classes produces limited

What does the @ symbol mean in R?

丶灬走出姿态 提交于 2019-11-27 19:20:10
In packages like marray and limma , when complex objects are loaded, they contain "members variables" that are accessed using the @ symbol. What does this mean and how does it differ from the $ symbol? See ?'@' : Description: Extract the contents of a slot in a object with a formal (S4) class structure. Usage: object@name ... The S language has two object systems, known informally as S3 and S4. S3 objects, classes and methods have been available in R from the beginning, they are informal, yet very interactive . S3 was first described in the White Book (Statistical Models in S). S3 is not a

How to properly document S4 class slots using Roxygen2?

老子叫甜甜 提交于 2019-11-27 16:57:21
For documenting classes with roxygen(2), specifying a title and description/details appears to be the same as for functions, methods, data, etc. However, slots and inheritance are their own sort of animal. What is the best practice -- current or planned -- for documenting S4 classes in roxygen2? Due Diligence: I found mention of an @slot tag in early descriptions of roxygen. A 2008 R-forge mailing list post seems to indicate that this is dead, and there is no support for @slot in roxygen: Is this true of roxygen2? The previously-mentioned post suggests a user should instead make their own

Sources on S4 objects, methods and programming in R

强颜欢笑 提交于 2019-11-27 16:45:16
As I'm often confronted with situations where S4 programming is needed to keep an overview, I've collected quite some sources on S4 objects, methods and programming. I've listed them here as a reference. Please add your own sources as well. On the web The methods help files : help files from the package methods, where much of the necessary information can be found S4 classes in 15 pages : Short introduction on the programming with S4 objects. How S4 methods work : more explanation about the underlying mechanisms. Not so short introduction to S4 : with practical examples of how to construct the

Adding S4 dispatch to base R S3 generic

ε祈祈猫儿з 提交于 2019-11-27 15:14:24
问题 I am trying to add a spatial method to merge which needs to be S4 (since it dispatches on the types of two different objects). I have tried using an earlier solution as follows: #' Merge a SpatialPolygonsDataFrame with a data.frame #' @param SPDF A SpatialPolygonsDataFrame #' @param df A data.frame #' @param \dots Parameters to pass to merge.data.frame #' #' @export #' @docType methods #' @rdname merge-methods setGeneric("merge", function(SPDF, df, ...){ cat("generic dispatch\n")

Combining S4 and S3 methods in a single function

回眸只為那壹抹淺笑 提交于 2019-11-27 14:25:24
What is a good way of defining a general purpose function which should have implementations for both S3 and S4 classes? I have been using something like this: setGeneric("myfun", function(x, ...){ standardGeneric("myfun"); }); setMethod("myfun", "ANY", function(x, ...) { if(!isS4(x)) { return(UseMethod("myfun")); } stop("No implementation found for class: ", class(x)); }); This succeeds: myfun.bar <- function(x, ...){ return("Object of class bar successfully dispatched."); } object <- structure(123, class=c("foo", "bar")); myfun(object) Is there a move "native" way to accomplish this? I know

Getting a slot's value of S4 objects?

隐身守侯 提交于 2019-11-27 14:02:46
问题 So I have a spatialpolygons object in R; but I am not sure why I am unable to retrieve the "area" slot from it. Here's my R session: > spatialpolygons An object of class "SpatialPolygons" Slot "polygons": [[1]] An object of class "Polygons" Slot "Polygons": [[1]] An object of class "Polygon" Slot "labpt": [1] 20.50516 57.72918 Slot "area": [1] 36.85484 Slot "hole": [1] FALSE Slot "ringDir": [1] 1 Slot "coords": [,1] [,2] [1,] 16.48438 59.73633 [2,] 22.59277 61.14258 [3,] 24.74609 55.03418 [4,

How to define the subset operators for a S4 class?

女生的网名这么多〃 提交于 2019-11-27 07:07:20
I am having trouble figuring out the proper way to define the [ , $ , and [[ subset operators for an S4 class. Can anyone provide me with a basic example of defining these three for an S4 class? Discover the generic so that we know what we are aiming for > getGeneric("[") standardGeneric for "[" defined from package "base" function (x, i, j, ..., drop = TRUE) standardGeneric("[", .Primitive("[")) <bytecode: 0x32e25c8> <environment: 0x32d7a50> Methods may be defined for arguments: x, i, j, drop Use showMethods("[") for currently available ones. Define a simple class setClass("A", representation