Description Usage Value Author(s) See Also Examples
CqlsObj class as a combination of usual S3 class and Ruby-like Binding.
1 2 | CqlsObj(...)
.ExternalInEnvir(name,...,envir,PACKAGE)
|
CqlsObj()
returns at least a Binding
R object. Unnamed arguments are implicitly converted in character and considered as the classes of the returned object (completed with the class Binding
). Named arguments are used as initial values of fields of the newly created object.
R. Drouilhet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | b <- CqlsObj(Spy,Man) #or CqlsObj("Spy","Man")
class(b) # => c("Spy","Man","Binding")
b$first <- "James" # regular R variable (not a ptR)
b$.last <- "Bond" # last.ptR is created in binding b with value "toto"
b$.last # "*" stands for a ptR and equivalent to b$last.ptR
b$last # equivalent to b$.last$value or b$last.ptR$value
print(b)
print.Spy <- function(obj) cat("My name is",obj$first,obj$last,"!\n")
print(b)
b2 <- CqlsObj(Man,Spy,first=b$first,.last=b$.last) #instance variables can be initialized
# equivalent to:
# b2 <- CqlsObj(Man,Spy)
# b2$first <- b$first # just a value not a ptR
# b2$.last <- b$.last # but not b2$.last <- b$last (only the value of b$last in b2$.last)
print(b2)
b2$first <- "JAMES"
b2$.last <- "BOND" # or b2$last <- "BOND" but maybe it is confusing!
print(b)
print.Man <- function(obj) cat("I am",obj$first,obj$last,"!\n")
print(b2)
# example of update in a dynamic way
update.Man <- function(obj,first,last) {obj$first <- first;obj$.last <- last}
update(b2,"Jamie","Bondie") # here it is!
print(b2) # b2$first and b2$.last updated
print(b) # b$.last updated but not b$first
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.