2

If I define a function called

log.foo = function(foo){
  log(foo)
}

then R will think it is a S3 method. How can I tell R log.foo() is not the S3 method for the class foo. (In fact, class foo does not exist.)

Or do I just have to rename my function?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 3
    You don't need to do anything if there is no registered class named `foo` and even if there is one, you still may not need to. What errors are you getting? Id you had a class named foo then objects of that class would get returned as log()-ed values when you executed `log(obj)` – IRTFM Apr 30 '14 at 01:06
  • this should not cause any problem. Also amazon-s3 is quite different from R S3 methods. – James King Apr 30 '14 at 01:07
  • Thank you both. The trouble is when I try to build a package including such a function, I got the warning "checking S3 generic/method consistency ... WARNING" – user3587399 Apr 30 '14 at 01:09
  • 3
    Well if you want to avoid the package compiler warning, which is a good thing to avoid, then use `log_foo` as the name. – IRTFM Apr 30 '14 at 01:11
  • I fully agree. Function (and variable) naming rules is a long-standing, ahem, controversy in the `R` community, but since `function.class` is the expected way to define methods, it's really much better in the long run not to name your functions with dots. Personally I like `functionFoo` but as I said, tastes vary :-) – Carl Witthoft Apr 30 '14 at 11:41
  • It seems I should change the function name, then that's what I will do. (I somehow feel that it is possible to tell whether a function is a S3 method, even when there is dot in the function name.) Thanks. – user3587399 Apr 30 '14 at 18:02
  • You might be confusing methods with object classes here. A function can return an S3 or an S4 object. – Carl Witthoft Apr 30 '14 at 18:32

0 Answers0