원시 제네릭의 메서드 조회

R에서 S3와 R6로 배우는 Object-Oriented Programming

Richie Cotton

Data Evangelist at DataCamp

 

  • 코드 작성
  • 코드 디버깅
  • 코드 유지보수

 

  • 코드 실행
R에서 S3와 R6로 배우는 Object-Oriented Programming

R vs. C

  • C 코드는 종종 더 빠릅니다
  • R 코드는 보통 작성이 더 쉽습니다
  • 그리고 디버깅도 더 쉽습니다
R에서 S3와 R6로 배우는 Object-Oriented Programming

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

R에서 S3와 R6로 배우는 Object-Oriented Programming

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

R에서 S3와 R6로 배우는 Object-Oriented Programming
exp
function (x)  .Primitive("exp")
+
function (e1, e2)  .Primitive("+")
if
.Primitive("if")
sin
function (x)  .Primitive("sin")
-
function (e1, e2)  .Primitive("-")
for
.Primitive("for")
R에서 S3와 R6로 배우는 Object-Oriented Programming
.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" 
R에서 S3와 R6로 배우는 Object-Oriented Programming
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
R에서 S3와 R6로 배우는 Object-Oriented Programming

요약

  • 일부 R 함수는 실제로 C로 작성되어 있습니다
  • 원시(primitive) 인터페이스는 최고 성능을 제공합니다
  • .S3PrimitiveGenerics원시 S3 제네릭을 나열합니다
  • 원시 제네릭은 메서드를 못 찾을 때 에러를 발생시키지 않습니다
R에서 S3와 R6로 배우는 Object-Oriented Programming

연습해 봅시다!

R에서 S3와 R6로 배우는 Object-Oriented Programming

Preparing Video For Download...