search for: slotnam

Displaying 20 results from an estimated 52 matches for "slotnam".

Did you mean: slotnum
2005 Nov 18
3
Method for $
Dear R experts, I have defined a class "myclass" and would like the slots to be extractable not only by "@" but also by "$". I now try to write a method for "$" that simply executes the request object at slotname, whenever someone calls object$slotname for any object of class "myclass". I don't manage to find out how I can provide this function with "slotname", so that one and the same function works for any arbitrary slotname a user might choose. I have tried setMethod("$...
2008 Nov 20
1
How to convert S4 class slots into data.frame or how to assign variables of type 'Date'
...eed a method to convert this class forth and back into a single row data.frame, where every slots represents a column. This method looks at the moment like this: > setMethod("as.data.frame", "Transaction", function(x, row.names = NULL, optional = FALSE, ...){ slotnames <- slotNames(x) slotlist <- data.frame(rbind(1:length(slotnames))) names(slotlist) <- slotnames for(i in slotnames) { slotlist[1, i] <- slot(x, i) } return(slotlist) } ) This method doesn't require predetermined slotname...
2017 Jun 06
2
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
...oblems. I can extend A1: setClass("B1", contains="A1") but trying to extend A2 or A3 produces an error (with a non-informative message in the 1st case and a somewhat obscure one in the 2nd): setClass("B2", contains="A2") # Error in attr(prototype, slotName) <- attr(pri, slotName) : # invalid first argument setClass("B3", contains="A3") # Error in attr(prototype, slotName) <- attr(pri, slotName) : # 'dimnames' applied to non-array So it seems that the presence of a "dim" or "dimnames&...
2008 Jun 07
1
slot(obj, "nosuch") documentation question
Using slot() on object (or "@") and using a nonexistent slotname returns an error (see example code). R> setClass("foobar", representation=list(a="numeric")) [1] "foobar" R> foobar <- new("foobar", a=5) R> foobar at a [1] 5 R> foobar at b Error: no slot of name "b" for this object of class "...
2010 Apr 24
3
S4 Inheritance of environments
...ling lists and could not find an answer to this. My apologies if it has already been answered. If it has, a pointer to the relevant discussion would be greatly appreciated. Creating S4 classes containing environments exhibits unexpected behavior/features.? These have a different in two ways: 1) slotName for the data: ".xData" instead of ".Data" and do not respond to the 2) Response to the is.* function seems to indicate that the object does not know of its inheritance. ( Notably, the inherits function works as expected. ) Here is a working illustration: > # LIST > se...
2009 Jun 18
1
validObject throws non-caught error when slot doesn't exist
...rollable by 'test' argument) when retrieving a non-existent slot. The offending line of code is shown below: > validObject function (object, test = FALSE, complete = FALSE) { ... for (i in seq_along(slotTypes)) { classi <- slotTypes[[i]] sloti <- slot(object, slotNames[[i]]) # offending line of code One potential patch is to substitute the offending line with sloti <- try(slot(object, slotNames[[i]]), silent = TRUE) if (class(sloti) == "try-error") { errors <- c(errors, paste("missing slot \"", slotNa...
2004 Dec 09
2
wishlist -- names gives slotnames (PR#7410)
...ersion: 1.9.1 OS: Windows XP Submission from: (NULL) (171.64.102.199) It would be nice if names(obj) would give slot names as well. Since for many people slots are new, the first thing that happens is you try to access what's in them and can't find how to do it. If you don't know that slotNames() exists, it can be very frustrating. Moreover, if you don't even know that the objects has slots (or that such things exist), it's extremely confusing. It just looks like nothing is there (you get NULL). If needed, you could have a message that says that these are slots and should be acc...
2013 Feb 06
0
slotName defined in object, present in instance, but inaccessible [SCL:4]
...ains="DataFrame", ## representation(states="StatesORNULL")) ## R> foo <- occupancy(pooledMethSegs) R> plotOccupancy(foo) Error in slot(object, "states") : no slot of name "states" for this object of class "Occupancy" R> slotNames(foo) [1] "states" "rownames" "nrows" "listData" [5] "elementType" "elementMetadata" "metadata" R> foo@states Error: no slot of name "states" for this object of class "Occupancy&qu...
2013 Feb 06
0
slotName defined in object, present in instance, but inaccessible [SCL:4]
...ains="DataFrame", ## representation(states="StatesORNULL")) ## R> foo <- occupancy(pooledMethSegs) R> plotOccupancy(foo) Error in slot(object, "states") : no slot of name "states" for this object of class "Occupancy" R> slotNames(foo) [1] "states" "rownames" "nrows" "listData" [5] "elementType" "elementMetadata" "metadata" R> foo@states Error: no slot of name "states" for this object of class "Occupancy&qu...
2017 Jun 06
1
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
...t;, contains="A1") >> >> but trying to extend A2 or A3 produces an error (with a non-informative >> message in the 1st case and a somewhat obscure one in the 2nd): >> >> setClass("B2", contains="A2") >> # Error in attr(prototype, slotName) <- attr(pri, slotName) : >> # invalid first argument >> >> setClass("B3", contains="A3") >> # Error in attr(prototype, slotName) <- attr(pri, slotName) : >> # 'dimnames' applied to non-array >> >> So it seems...
2005 Jan 18
1
"Attach" for S4 objects?
When passing a list as an argument to a function, I find it convenient to attach it in the first line of th function code, then refer to the components as A, B, etc. rather than as list$A, list$B, etc. If I pass a S4 class object, is there a way to "attach" it, or do I have to refer to the slots as object at A, objetc at B, etc.? I could always make copies, A <- object at A
2017 Jun 06
0
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
...setClass("B1", contains="A1") > > but trying to extend A2 or A3 produces an error (with a non-informative > message in the 1st case and a somewhat obscure one in the 2nd): > > setClass("B2", contains="A2") > # Error in attr(prototype, slotName) <- attr(pri, slotName) : > # invalid first argument > > setClass("B3", contains="A3") > # Error in attr(prototype, slotName) <- attr(pri, slotName) : > # 'dimnames' applied to non-array > > So it seems that the presence of a &quot...
2010 Feb 08
1
using setMethod or setGeneric to change S4 accessor symbol from @ to $
...self redefining all the typical generic functions so that I can still manipulate my S4 objects as if they were data frames ... I have used setMethod to set methods for "subset", "head", and "tail". I would like to use setMethod or setGeneric to enable me to use object$slotname to access object@slotname for my S4 objects. Any advice is appreciated. Thanks. --Markus [[alternative HTML version deleted]]
2013 Feb 15
1
Iterating through slots of an S4 object
I want to loop through slots of an S4 object and am unsure how to do so since the only way I can find to access them is individually in the form 'object@slotName'. I have guessed at a few possibilities which did not work and I have read some S4 object tutorials and things but still unsuccessful. I presume it is possible though? Any help would be much appreciated, Scott [[alternative HTML version deleted]]
2011 Jun 04
1
S4 class, passing argument names to function, modify original
...original object (not returning the modified copy of it an overwrite the original by assignment)? Thanks, S?ren setClass("Foo", representation( N = "numeric" ), prototype( N = 10000 ) ) .foo.update <- function(object, ...) { args <- list(...) for (i in slotNames("Foo")[pmatch(names(args), slotNames("Foo"), nomatch=0)]) { slot(object, i) <- args[[i]] # indeed more to do here return(object) } } setReplaceMethod("$", "Foo", function(x, name, value) { x <- .foo.update(x, name=value) x }...
2009 Aug 30
1
Trying to rename spatial pts data frame slot that isn't a slot()
...e manipulated in qGIS mymcp<-readOGR(dsn=mcp.dir,layer="All mantas MCP land differenc") My spatial points data frame has a number of "Slot"s, including one that contained the original names called Slot "ID". However, I can not access this slot using slot() or slotNames(). > slotNames(mymcp) [1] "data" "polygons" "plotOrder" "bbox" "proj4string" What am I missing here? Is Slot "ID" not a slot? Can I export the ID's with the shapefiles to qGIS? Can I rename the ID's whe...
2004 Nov 26
1
Testing for S4 objects
Dear r-help list members, Is there a way to test whether an object is an S4 object? The best that I've been able to come up with is isS4object <- function(object) !(is.null(slotNames(object))) which assumes that an S4 object has at least one slot. I think this is safe, but perhaps I'm missing something. Thanks, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.m...
2004 Nov 26
1
Testing for S4 objects
Dear r-help list members, Is there a way to test whether an object is an S4 object? The best that I've been able to come up with is isS4object <- function(object) !(is.null(slotNames(object))) which assumes that an S4 object has at least one slot. I think this is safe, but perhaps I'm missing something. Thanks, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.m...
2009 Aug 17
2
S4: inheritance of validity methods?
...orm some checks on children slots. Say, I want to check if number of slots in a class is equal to "n": setClass("A", representation(a="numeric", n="integer"), prototype=list(a=12, n=1L), validity=function(object){ if(length(slotNames(object))!=object at n+1) paste("Number of slots must be ", object at n) else TRUE }) setClass("B", representation(b="numeric"), contains="A", prototype=list(a=12, b=14, n=2L)) new("B", a=11, b=33) Error in v...
2011 Aug 09
2
S4 classes, some help with the basics
...ject. How can I call parts of that object without using the specific names of the object in the call? example code: library(pcaMethods) myMatrix <- matrix(runif(1e4), ncol=100) ## silly, but sufficient for example myPCA <- pca(myMatrix) ## creates a "pcaRes" S4 class for (i in slotNames(myPCA) ) { summary(myPCA@i) ### I know this doesn't work, but this is the question... what grammar could I use? } ################ I would like to be able to print out the summary for each of the components of the class "pcaRes" without knowing a priori the names of those co...