ann <- Person$new("Ann", "black")
In the example above (which is from this Introduction), how would I get "ann"?
For instance, I would need a method ann$getName that would return "ann".
ann <- Person$new("Ann", "black")
In the example above (which is from this Introduction), how would I get "ann"?
For instance, I would need a method ann$getName that would return "ann".
I'm trying to do the same thing, so perhaps I can clarify the question. The goal (for me) is to give the user of the class some feedback. Something like that:
Person <- R6Class("Person",
public = list(
name = NULL,
hair = NULL,
initialize = function(name = NA, hair = NA) {
self$name <- name
self$hair <- hair
},
do_something_very_long=function(){
whoami <- self$getInstanceName() ## $getInstanceName() is the method I need to write !
message(paste("Please wait, processing object",whoami))
# Do a very long calculation...
}
)
)
Which I'd then run in a script that would do something like
#File batch_processing.R
first_in_line<-Person$new("Alice","Black")
next_customer<-Person$new("Bob","Red")
VIP<-Person$new("Charlie","Brown")
# etc ...
first_in_line$do_something_very_long()
next_customer$do_something_very_long()
VIP$do_something_very_long()
# etc ...
So, my (notional) user will start batch_processing.R, perhaps with
$ R ~/batch_processing.R
or
R> source("batch_processing.R")
and watch not much happening while the script works. I would like, therefore, some feedback so that when the user comes back after his coffee, he can look at the screen and see that the computer is busy processing VIP or next_customer.
Obviously - one way is to explicitly give unique identifiers to each object ($name in this case). In my real application case, however, this would not be very meaningful, or would duplicate the object name ("model 1", "model 2"...) which is a bit wasteful !