s4 - Override setClass and setMethod in a package R 3.0.1 -


i having problem override setclass , setmethod in package

requirement: r 3.0.1, rtools

please find below steps recreate problem:

1. create class , method

setclass(class="aaa",            representation(            name="character",            val="numeric"          ) )  setmethod("*",        signature(e1 = "numeric", e2 = "aaa"),        definition=function (e1, e2) {           e2@val = e2@val * e1       e2            } ) 

2/ save file in

c:\aaa.r

3/ build package

>  setwd("c:") >  package.skeleton(name="aaa",code_files="c:\\aaa.r") >  system("r cmd build aaa") >  system("r cmd install --build aaa") 

4/ testing

> library(aaa) > x = new("aaa") > x@val = 100 > -1 * x object of class "aaa" slot "name": character(0)  slot "val": [1] -100  slot "type": character(0) 

5/ override class , method

setclass(class="aaa",            representation(            name="character",            val="numeric",            type="character",            desc="character"          ) )  setmethod("*",       signature(e1 = "numeric", e2 = "aaa"),                    definition=function (e1, e2) {                     if (e2@type == "double"){                         e2@val = e2@val * (2 * e1)                            } else {                         e2@val = e2@val * e1                      }                                  e2                   }         ) 

6/ testing

> y = new("aaa") > y@val=25 > y@type="double" > -1 * y error in -1 * y : invalid object (non-function) used method 

please advise


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -