Busca de métodos para genéricos primitivos

Programação Orientada a Objetos com S3 e R6 em R

Richie Cotton

Data Evangelist at DataCamp

 

  • Escrever código
  • Depurar código
  • Manter código

 

  • Executar código
Programação Orientada a Objetos com S3 e R6 em R

R vs. C

  • Código em C costuma ser mais rápido
  • Código em R geralmente é mais fácil de escrever
  • ... e mais fácil de depurar
Programação Orientada a Objetos com S3 e R6 em R

ch2_3-method-lookup-for-primitive-generics.012.png

Programação Orientada a Objetos com S3 e R6 em R

ch2_3-method-lookup-for-primitive-generics.013.png

Programação Orientada a Objetos com S3 e R6 em R
exp
function (x)  .Primitive("exp")
+
function (e1, e2)  .Primitive("+")
if
.Primitive("if")
sin
function (x)  .Primitive("sin")
-
function (e1, e2)  .Primitive("-")
for
.Primitive("for")
Programação Orientada a Objetos com S3 e R6 em R
.S3PrimitiveGenerics
"anyNA"          "as.character"   "as.complex"
"as.double"      "as.environment" "as.integer"     
"as.logical"     "as.call"        "as.numeric"
"as.raw"         "c"              "dim"           
"dim<-"          "dimnames"       "dimnames<-"     
"is.array"       "is.finite"      "is.infinite"    
"is.matrix"      "is.na"          "is.nan"
"is.numeric"     "length"         "length<-"      
"levels<-"       "names"          "names<-"
"rep"            "seq.int"        "xtfrm" 
Programação Orientada a Objetos com S3 e R6 em R
all_of_time <- c("1970-01-01", "2012-12-21")
as.Date(all_of_time)
"1970-01-01" "2012-12-21"
class(all_of_time) <- "date_strings"
as.Date(all_of_time)
Error in as.Date.default(all_of_time) : 
  do not know how to convert 'all_of_time' to class"Date"
length(all_of_time)
2
Programação Orientada a Objetos com S3 e R6 em R

Resumo

  • Algumas funções de R são escritas em C
  • A interface primitiva oferece melhor desempenho
  • .S3PrimitiveGenerics lista genéricos S3 primitivos
  • Genéricos primitivos não geram erro quando nenhum método é encontrado
Programação Orientada a Objetos com S3 e R6 em R

Vamos praticar!

Programação Orientada a Objetos com S3 e R6 em R

Preparing Video For Download...