search for: slotnames

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

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
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 slotnames...
2017 Jun 06
2
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
Hi, It's nice to be able to define S4 classes with slots that correspond to standard attributes: setClass("A1", slots=c(names="character")) setClass("A2", slots=c(dim="integer")) setClass("A3", slots=c(dimnames="list")) By doing this, one gets a few methods for free: a1 <- new("A1", names=letters[1:3])
2008 Jun 07
1
slot(obj, "nosuch") documentation question
...ottom-up quick glance only read last paragraph) to get NULL from invalid slotname. This is in reference to writing method that might be passed an object created by previous version of software, and new slots were added to class in later revisions. For such situations, is the norm then to do "slotNames(obj) %in% <slotname>" prior to accessing any slotname from extended class? TIA R version 2.7.0 Patched (2008-06-04 r45830) ---------------------------------------------------------- SIGSIG -- signature too long (core dumped)
2010 Apr 24
3
S4 Inheritance of environments
...LIST > setClass( 'inheritList', contains='list') [1] "inheritList" > inList <- new( 'inheritList' ) > class( inList ) [1] "inheritList" attr(,"package") [1] ".GlobalEnv" > is.list( inList ) # TRUE [1] TRUE > slotNames(inList) # ".Data" [1] ".Data" > inherits(inList, 'list' ) # TRUE [1] TRUE > > > # ENVIRONMENT > setClass( 'inheritEnv', contains='environment' ) Defining type "environment" as a superclass via class ".environment&qu...
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 \"", slotName...
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 acces...
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&quot...
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&quot...
2017 Jun 06
1
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
I've fixed this and will commit soon. Disregard my dim<-() example; that behaves as expected (the class needs a dim<-() method). Michael On Tue, Jun 6, 2017 at 5:16 AM, Michael Lawrence <michafla at gene.com> wrote: > Thanks for the report. The issue is that one cannot set special attributes > like names, dim, dimnames, etc on S4 objects. I was aready working on this >
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)
Thanks for the report. The issue is that one cannot set special attributes like names, dim, dimnames, etc on S4 objects. I was aready working on this and will have a fix soon. > a2 <- new("A2") > dim(a2) <- c(2, 3) Error in dim(a2) <- c(2, 3) : invalid first argument On Mon, Jun 5, 2017 at 6:08 PM, Herv? Pag?s <hpages at fredhutch.org> wrote: > Hi, > >
2010 Feb 08
1
using setMethod or setGeneric to change S4 accessor symbol from @ to $
I created some S4 objects that are essentially data frame objects. The S4 object definitions were necessary to verify data integrity and force a standardized data format. I am, however, finding myself 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",
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
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 when...
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.mcm...
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.mcm...
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 val...
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 comp...