Skip to contents

Duck typing is a way to emulate type checking by virtue of an object's characteristics as opposed to strong typing.

Usage

argument %isa% type
argument %hasa% property
argument %hasall% property

Arguments

argument

An object to inspect

type

A type name

property

A property of an object

Details

These operators provide a convenient method for testing for specific properties of an object.

%isa% checks if an object is of the given type.

%hasa% checks if an object has a given property. This can be any named element of a list or data.frame.

Value

Boolean value indicating whether the specific test is true or not.

Author

Brian Lee Yung Rowe

See also

Examples

5 %isa% numeric
#> [1] TRUE

Point(r,theta, 'polar') %as% {
  o <- list(r=r,theta=theta)
  o@system <- 'polar'
  o
}

p <- Point(5, pi/2, 'polar')
p 
#> $r
#> [1] 5
#> 
#> $theta
#> [1] 1.570796
#> 
#> attr(,"system")
#> [1] "polar"
#> attr(,"class")
#> [1] "Point" "list"