<- function(id, things, operation, test){
new_monkey structure(id, things, operation, test)
}
Day 11
Data
Monkeys 🐒 are having fun with my stuff!!!
Functions and objects
I will need to create classes, I think.
🐒 Monkey
🎁 Thing
A class with attributes worry_level
and monkey
(which monkey holds it).
<- function(id, worry_level, monkey){
new_thing stopifnot(is.numeric(worry_level))
structure(id, worry_level, monkey = monkey, class = "thing")
}<- function(x, ...){
print.thing cat("This thing (", id, ") is associated with current worry level of ",
$worry_level, " and is being hold by a monkey no.", x$monkey, "\n")
x
}
change_worry_level(thing, operation){
<- thing$worry_level
old <- NA
new eval(parse_expr(operation))
$worry_level <- new
thingreturn(thing)
}change_monkey_holding(thing, old_monkey, new_monkey){
remove_thing(old_monkey, thing$id)
add_thing(new_monkey, thing$id)
$monkey <- new_monkey$id
thingreturn(thing)
}