1

I am looking for the real object type of some functions in R, for example, I can not find out the object type of mean function.

> library(pryr)
> otype(mean)
[1] "base"
> ftype(mean)
[1] "s3"      "generic"

Sometimes the mean function is S3 and sometimes it is base!

M--
  • 25,431
  • 8
  • 61
  • 93
Shahab Einabadi
  • 307
  • 4
  • 15

1 Answers1

2

What does ftype tell us?

This function figures out whether the input function is a regular/primitive/internal function, a internal/S3/S4 generic, or a S3/S4/RC method. This is function is slightly simplified as it’s possible for a method from one class to be a generic for another class, but that seems like such a bad idea that hopefully no one has done it.

What does otype give us?

Figure out which object system an object belongs to:

• base: no class attribute

• S3: class attribute, but not S4

• S4: isS4, but not RC

• RC: inherits from "refClass"

For reference:

  1. pryr package documentation

  2. R language objects

Community
  • 1
  • 1
M--
  • 25,431
  • 8
  • 61
  • 93