coerceListToS4 | R Documentation |
This is a utility function that allows us to convert a named collection of values in the form of a list (or vector) to an S4 object. This is used to simplify calls to SOAP methods that expect a structured object of an S4 class by allowing us to group the slots in a list.
coerceListToS4(.x = list(...), .obj, ..., .partialMatch = TRUE, .coerce = TRUE)
.x |
the R list containing the named elements that map to the slots in the S4 object |
.obj |
an instance of the S4 object or the name of an S4 class. |
... |
named elements which act as slots. This allows the caller to avoid collecting these elements into a list. |
.partialMatch |
a logical value that controls whether we match the names of the elements in the list to slot names in the class using partial matching or exact matching. |
.coerce |
a logical value that controls whether we coerce each slot to its defined type. |
The obj
object with any slots filled in from the
the list x
.
Duncan Temple Lang
setClass("Bar", representation(x = "logical", y = "data.frame"))
setClass("Foo", representation(a = "numeric", b = "integer", c = "character",
d = "Bar"))
coerceListToS4(list(a = 1, b = 4:9), new("Foo"))
coerceListToS4(list(a = 1, b = 4:9, d = coerceListToS4(list(y = mtcars), new("Bar"))), new("Foo"))
# here we drop the new() and the list() but note that we have to
# indicate that the class name should match the second parameter
# with an extra ,
coerceListToS4(a = 1, b = 4:9, d = coerceListToS4(y = mtcars, , "Bar"), , "Foo")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.