| change_formals | R Documentation |
This accepts an oClass generator and updates its formal arguments based either on those
passed in ... or the function passed to from_init. The results will be
passed to the appropriate init function each time an instance is generated.
change_formals(x, ..., envir = parent.frame(), from_init = NULL)
x |
oClass generator function |
... |
named or unnamed objects used as the formal arguments of the generator function |
envir |
environment from which to evaluate arguments |
from_init |
function containing the formal arguments to use; typically an |
oClass generator function
clown <- oClass("clown")
clown
# 'init' requires a laugh
init.clown <- function(x, laugh, ...){
x$laugh <- laugh
add_fields(x, ...)
return(x)
}
# change formals of clown
clown <- change_formals(clown, from_init = init.clown)
# alternatively,
clown <- change_formals(clown, laugh, ..dots)
# creation
happy_clown <- clown("HAHA")
sad_clown <- clown("ha")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.