Displaying 20 results from an estimated 261 matches for "myclass".
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
Dear all,
Assume that I have an S4 class "MyClass" with a slot "myname", which
is initialized to: myname="" in method("initialize"):
myclass <- new("MyClass", myname="")
Assume that class "MyClass" has a method "mymethod":
"mymethod.MyClass" <-
fu...
2005 Dec 07
1
Dots argument in apply method
..."problem" when I tried to create an "apply" method for objects
of one of my new classes. I've found a way around the problem but I
wonder if I did not paint myself into the corner. I'd like your opinion
about that.
So I have an object "myObj" of class "myClass". I define a new function
".apply.myClass" which is a "myClass" specific version of "apply". The
trick is that I would like to have an additional formal argument in
.apply.myClass compared to apply. More precisely we have:
apply(X, MARGIN, FUN, ...)
and I wan...
2011 Oct 31
1
Question about copying reference objects using the initialize method
Dears,
I have a question about copying reference objects using the initialize method.
1) If the latter has no arguments, there is no problem to copy an object.
myClass = setRefClass("myClass", fields = list(value = "numeric") )
myClass$methods(initialize = function(...){
? value <<- 1
? callSuper(...)
})
newObject = myClass$new()
newObject$value = 2
copyObject = newObject$copy()
copyObject$value = 3
print(newObject$value)
print(copyO...
2020 May 12
4
S3 method dispatch for methods in local environments
Dear All,
In R 3.6.3 (and earlier), method dispatch used to work for methods stored in local environments that are attached to the search path. For example:
myfun <- function(y) {
out <- list(y=y)
class(out) <- "myclass"
return(out)
}
print.myclass <- function(x, ...) print(formatC(x$y, format="f", digits=5))
myfun(1:4)
# prints: [1] "1.00000" "2.00000" "3.00000" "4.00000"
rm(print.myclass)
myenv <- new.env()
myenv$print.myclass <- local(functi...
2019 Jul 07
3
Possible bug in `class<-` when a class-specific '[[.' method is defined
Hi all !
I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined.
Here below a reproducible example :
#-------------------------------------------------------------------.
counttt <- 0
`[[.MYCLASS` = function(x, ...) {
counttt <<- counttt + 1
# browser()
x = NextMethod()
return(x)
}
df <- as.data.frame(matrix(1:20, nrow=5))
class(df) <- c("MYCLASS","data.frame")
counttt
# The same occurs when using structure(, class=) or attr(,"class")<-...
2008 Dec 22
1
How to add a slot to S4 class of an existing package?
Dear all,
Since my package is based on S4 classes, I would like to know how to add
a slot to an existing S4 class without breaking the code of users of my
package.
Assume the following S4 class:
setClass("MyClass",
representation(name = "character",
type = "character",
data = "data.frame"
),
prototype(name = "",
type = "Default",
data = data.frame(matrix(nr=0,nc=0))
)
)#MyClass
A...
2012 Jul 19
0
[LLVMdev] Supporting Classes using OCaml.
Hello all...
I'm trying to create a simple language that supports classes using the
OCaml API.
When I use the web page demo to produce the intermediate code for the
following C++ example ...
class MyClass {
public:
MyClass();
int c;
};
MyClass::MyClass () {
c=55;
}
...I get something like this ....
%class.MyClass = type { i32 }
@MyClass::MyClass() = alias void (%class.MyClass*)* @MyClass::MyClass()
define void @MyClass::MyClass()(%class.MyClass* %this) unnamed_addr
nounwind uwtable align...
2000 Jun 26
2
nargs() inside "[.myclass"
I am writing a function to work with class I am defining. I have a question
about using nargs() inside of parentheses function. nargs() shows the same
for supplying 1 argument, or no arguments at all. Here is a small example:
> "[.myclass"<-function(x,...) print(nargs()-1)
> x<-c(1,2,3)
> class(x)<-"myclass"
> x[]
[1] 1
> x[1]
[1] 1
> x[1,2]
[1] 2
how can I determine if there was 1 argument supplied, or none?
Thanks.
PS:
> version
_
platform Windows
arch x86
os Win32
sy...
2011 Sep 22
1
R.oo: do work on data member at construction
...I'd like to 'do work' on data members upon construction (i.e. without
implementing it in a get method). Is this the best way to create data member
'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex
I'll run into issues.
setConstructorS3("MyClass", function(x=NA,y=NA,...) {
this <- extend(Object(), "MyClass",
.x=x,
.y=y,
.z=paste(x,y)
)
})
setMethodS3("getX", "MyClass", function(this, ...) {
this$.x;
})
setMethodS3("getY", "MyClass", function(this, ...) {
this$.y...
2009 Jan 02
1
"registering" a generic method for a class
...or and I can't find the text to rid myself of this
(admittedly somewhat trivial) problem. Note that I've done generic
programming with S3 "objects" in the past, but I've never really
dabbled in creating S4 objects until now.
So, I've created a new S4 class, call it "myclass", e.g. :
> setClass("myclass", representation(slot1 = "list"));
And I've also created an implementation of "print" for this class via:
> setMethod("print", "myclass", function(x) { print(paste("a myclass instance with a list o...
2011 Jun 06
1
Seeking help to define method for show() for an S4 object
Dear all, I have created a new S4 class with name "MyClass". Please see
below for it's definition. Now I want to create a
method for the show() function for this class. In defining this method, what
I want is, once user would like see an object of this class
some values will be displayed. Then R will ask for **press Enter**. Once
user presses ente...
2009 Feb 11
1
setClassUnion with numeric; extending class union
...t;))
So I do a workaround as:
setClass("aNumeric", contains="numeric")
setClassUnion("numericOrNULL", c("aNumeric","NULL"))
Then I cannot really extend the above virtual class and can only use it
in a user-defined slot as follows:
setClass("myClass", representation(data="numericOrNULL"))
new("myClass", data=runif(20))
new("myClass", data=NULL)
and this works.
Obviously it would be nicer to have something like the following:
setClass("myClass", contains="numericOrNULL")
new("myClas...
2008 Mar 20
1
setMethod for "["
Hi R-Help,
Please consider the following simple case: I have a class like
setClass("myClass",
representation(x="matrix", y="character"))
and I would like to use the method *"["* for a *myClass* objects (but
changing the default *drop* argument from TRUE to FALSE):
setMethod("[","myClass",
function(x,i,j,...,drop=FALSE...
2005 Jun 02
1
showMethods doubt
Hi,
I'm developing in S4 and I wanted to see the methods for a specific
class using showMethods but I didn't succed. Can someone help ? See the
example below.
setClass("myclass",
representation(
name ="character"
)
)
setGeneric("mymeth", function(obj, ...){
standardGeneric("mymeth")
}
)
setMethod("mymeth", signature("myclass"), function(obj){
print(paste("Hi,", obj at name, "and I don't kno...
2011 Oct 22
1
setMethod "[" - extract by names within Slot
Hi R-helper!
I have problem with setMethods for "[". Here is example :
setClass("myClass", representation(ID.r = "numeric", ID.c = "character", DAT = "matrix"))
to.myClass <- function(ID.r, ID.c, DAT) {
out <- new("myClass", ID.r = ID.r, ID.c = ID.c, DAT = DAT)
return(out)
}
setMethod("[", "myClass&...
2012 Sep 21
2
[LLVMdev] Clang API parsing of the destructor
I am using the clang API (version 3.1 - trunk 153913) to compile some very simple code as follows
class MyClass
{
~MyClass() ;
};
MyClass::~MyClass()
{
}
int main()
{
return 0;
}
My problem is that I get the error message: test.cpp:20:10: error: destructor cannot have a return type MyClass::~MyClass()
If someone can point me to the right direction that would be great. It compiles fine if the destru...
2002 Dec 12
1
improving ts object
Dear all,
Currently, a ts object behaves like an array, and it would be very useful to have a similar object, which would behave like a data.frame, i.e. it could be indexed, named, etc. like a data.frame. What would be the most efficient way to construct such an object? I have tried to make one on my own following the directions of class design from "S Programming" (2000) as a
2005 Jul 08
2
R.oo static field
How can I define a static member of a class? not a static method,
rather a static field that would be accessed by all instances of the
class.
2014 Jan 07
1
Why do methods of "initialize" have no "srcref" attribute as other S4 mehtods?
...comments in its source
### that are used to document it with inlinedocs
(arg ##<< another special comment for the argument
){
2*arg
### a description for the return value
}
>
this also works for operators
> setMethod("$",
+ signature(x = "MyClass"),
+ function
+ (x, ##<< first arg
+ name ##<< second ag
+ ) { }
+ )
[1] "$"
> attr(getMethod("$","MyClass"),"srcref")
function
(x, ##<< first arg
name ##<< second ag
) { }
>
> setClass...
2003 Dec 02
1
setMethod("min", "myclass", ...)
Hello,
I have defined a new class
> setClass("myclass", representation(min = "numeric", max = "numeric"))
and want to write accessor functions, so that for
> foo = new("myclass", min = 0, max = 1)
> min(foo) # prints 0
> max(foo) # prints 1
At first i created a generic function for "min"
> s...