The function in question is really unique.data.table
, an S3 method defined in the data.table
package. That method is not really intended to be called directly, so it isn't exported. This is typically the case with S3 methods. Instead, the package registers the method as an S3 method, which then allows the S3 generic, base::unique
in this case, to dispatch on it. So the right way to call the function is:
library(data.table)
irisDT <- data.table(iris)
unique(irisDT)
We use base::unique
, which is exported, and it dispatches data.table:::unique.data.table
, which is not exported. The function data.table:::unique
does not actually exist (or does it need to).
As eddi points out, base::unique
dispatches based on the class of the object called. So base::unique
will call data.table:::unique.data.table
only if the object is a data.table
. You can force a call to that method directly with something like data.table:::unique.data.table(iris)
, but internally that will mostly likely result in the next method getting called unless your object is actually a data.table
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…