Skip to content

Instantly share code, notes, and snippets.

@PirateGrunt
Created July 23, 2013 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PirateGrunt/6059617 to your computer and use it in GitHub Desktop.
Save PirateGrunt/6059617 to your computer and use it in GitHub Desktop.
kids1 = as.array(c("Bob", "Joe"))
kids2 = as.array(c("Steve", "Beth", "Kim"))
setClass("person", representation(name="character", age="numeric", children = "list"))
setMethod(
f = "[",
signature="person",
definition=function(x,i,j,...,drop=TRUE){
initialize(x, name=x@name[i], age = x@age[i], children = list(x@children[i]))
}
)
people = new("person", name=c("John", "Fred"), age=c(40, 20), children = list(kids1, kids2))
people[1]@name
people[1]@age
people[1]@children
people[2]@name
people[2]@age
people[2]@children
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment