similar to: S4-classes: Assignment of values to slots by reference

Displaying 20 results from an estimated 4000 matches similar to: "S4-classes: Assignment of values to slots by reference"

2011 Jun 03
2
S4 Slot assignment within function
Is there a simple way to assign values to S4 slots from within a function? Doing this doesn't work: > assign_slot<-function(x){ assign("OBJECT at slot",x,envir=parent.env(environment()) } >assign_slot(x) All I get from this is a new object with the name OBJECT at slot, the slot assignment of OBJECT doesn't change. I have thought about solutions such as
2013 Oct 28
3
speed of makeCluster (package parallel)
Hi all, I am quite new in the world of parallelization and I wonder if there is a way to increase the speed of creation of a parallel socket cluster. The time spend to include threads increase exponentially with the number of thread considered and I use of computer with two 8 cores CPU and thus showing a total of 32 threads in windows 7. Currently, I use the default parameters (type =
2013 Jan 31
5
Modify objects in function
Dear R community, I do know, that an R function is constructing a copy of any object passed as argument into a function. I program on a larger S4 project for a package, and I arrived at a point where I have to think a little harder on implementation style (especially to spare users complex object handling). I have a function foo(), taking as input arguments two S4 objects of different class
2009 Jun 05
2
S4: When is validObject issued? (or why S4 is killing me:( ..
Dear UseRs, Does anyone know when exactly the validity is checked in S4? Documentation is silent:(. Here is a small example: setClass("test1",representation(a="numeric")) setMethod("initialize","test1", function(.Object,...){ a<-runif(1) ## here slot "a" is initialized ## callNextMethod(.Object,a=a,...)
2006 May 11
2
S4 initialize methods, unexpected recursive callNextMethod
Hi, Given a simple three class hierarchy: A <-- B <-- C I want to define an initialize method for each class such that when I call new("C", x=5), the initialize methods for A and B are used to incrementally build the object. When I do what seems obvious to me using callNextMethod, I get an infinite recursion. An example follows... setClass("A",
2013 Feb 05
1
S4 Classes and Initialize methods
Hello, I am trying to improve my skill on S4 classes. But there's something strange (to me) happening with "initialize" methods. This is probably a normal behaviour... but... something is unclear in my mind I declare two classes, namely "A", and "B", which has a slot of type A. The class "A" has an initialize method. What I do not understand is that
2007 Jul 25
2
initalizing and checking validity of S4 classes
Dear useRs and wizaRds, I am currently developing a set of functions using S4 classes. On the way I encountered the problem exemplified with the code below. For some reason the 'validity' method does not seem to work, i.e. does not check for errors in the specification of the slots of the defined class. Any hints? My understanding of the whole S4 system was that validity checks are made
2005 Aug 05
1
S4 generating function
Can someone explain what the problem is when I use the generating function? And how to get debug() to stop in the Superclass initialize method? ---- source ----- setClass("Superclass", representation(id = "character"), contains = "VIRTUAL") setMethod("initialize", signature(.Object = "Superclass"),
2011 Feb 21
0
[R] S4 classes: referencing slots with other slots
Dear Development Group, In trying to answer the subject question myself, I found this thread initiated by Tony from five years ago: http://tolstoy.newcastle.edu.au/R/help/05/12/18169.html. I recently stumbled upon the following S4 answer to Tony's question: setClass("fooWfcn", representation(dat1="vector", dat2="vector",
2013 Feb 01
2
Armadillo error in R extension
Is there anyway with some experience in using armadillo in R C++ extensions? My problem is the following: I programmed a function in a header looking like #include <armadillo> inline arma::vec foo(input) { ... do something return an arma::vec object } compiling this via R CMD INSTALL packagename (PKG_CXXFLAGS = -I/folder/of/armadillo and armadillo_bits in my package) I get the
2017 Apr 20
2
Problems with S4 methods dispatching on `...` (aka dotsMethods)
Hi all, I recently encountered some unexpected behavior with S4 generics dispatching on `...`, which I described in http://stackoverflow.com/questions/43499203/use-callnextmethod-with-dotsmethods TL;DR: `callNextMethod()` doesn't work in methods dispatching on `...`, and arguments of such methods are resolved differently than the arguments of methods dispatching on formal arguments. Could
2008 Sep 09
1
building a package that contains S4 classes and methods
Hello R users, I am trying to make a my first package and I get an error that I can understand. The package is build out of three files (one for functions, 1 for s4 classes and 1 for s4 methods). Once I source them I run package.skeleton( name="TDC" ) within a R session and I get Creating directories ... Creating DESCRIPTION ... Creating Read-and-delete-me ... Saving functions and
2017 Apr 21
2
Problems with S4 methods dispatching on `...` (aka dotsMethods)
Great, thanks Michael for you quick response! I started off with a question on SO because I was not sure whether this was an actual bug or I was just missing something obvious. I'm looking forward to the patch. Cheers, Andrzej On Thu, Apr 20, 2017 at 10:28 PM, Michael Lawrence < lawrence.michael at gene.com> wrote: > Thanks for pointing out these issues. I have a fix that I will
2017 Apr 25
3
Problems with S4 methods dispatching on `...` (aka dotsMethods)
I attempted to fix it, and that example seems to work for me. It's also a (passing) regression test in R. Are you sure you're using a new enough R-devel? On Tue, Apr 25, 2017 at 2:34 AM, Andrzej Ole? <andrzej.oles at gmail.com> wrote: > Hi Michael, > > thanks again for your patch! I've tested it and I'm happy to confirm that > `callNextMethod()` works with
2006 Dec 12
1
S4 'properties' - creating 'slot' functions?
Dear R users! Several languages like C# or VB allow one to create properties; typically these are under 'get', 'set' tags. My question is this really, what are similar or comparable strategies in R, and what might be preferred? I have a couple of situations where I want a certain computation to belong to a class, but I do not really want to seperate it out to a stand-alone
2007 Dec 23
1
Problem with initialize of S4 classes
Dear all Below is the code for "scriptPreFilter.R" which gives the following result: > source("scriptPreFilter.R") > prefltr <- new("PreFilter", mad=c(0.5,0.01)) [1] "------initialize:PreFilter------" [1] "------initialize:Filter------" > str(prefltr) Formal class 'PreFilter' [package ".GlobalEnv"] with 2 slots
2009 Oct 27
1
How to reduce key strokes when defining S4 classes?
I feel tedious when I define a S4 class and the methods. For each method, I have to call both setMethod and setGeneric (or both setReplaceMethod and setGeneric). I would like a more compact grammar so that I can reduce the key strokes. I'm wondering if there is a better way available. setClass( Class='A', representation=representation( x='numeric' )
2013 Jul 18
1
Looking for knitr example for beginner (NO RStudio)
Hi everyone, I am using package knitr, FIRST TIME. I don't have access to RStudio. Read through Yihui's page, didn't find it helpful. Stuck on terms Rnw, GFM (GitHub Flavored Markdown). Never used Sweave, so the reference is not helping. Is there a simple step-by-step example WITHOUT RStudio? My question: What is the procedure? The documentation explains the functions, but does
2011 Sep 13
4
S4 vs Reference Classes
Hi, I'm looking for some guidance on whether to use S4 or Reference Classes for an analysis application I'm developing. I'm a C++/Python developer, and like to 'think' in OOD. I started my app with S4, thinking that was the best set of OO features in R. However, it appears that one needs Reference Classes to allow object methods to assign values (other than
2011 Apr 06
2
S4 generic functions/methods vs enclosures
Apologies for asking something that is probably very obvious, i just started with S4 classes and i guess i am not finding documentation that lays out the grammar rules and gives enough examples. I understand that main method of writing a member function is to write a generic function and setMethod for this particular class. This, however, presumes that there is "virtuality" for this