callWithStringsAsFactors | R Documentation |
Set the option "stringsAsFactors", run a function and reset the option.
callWithStringsAsFactors(stringsAsFactors, FUN, ...)
stringsAsFactors |
TRUE or FALSE. Before calling |
FUN |
function to be called |
... |
arguments passed to |
This function returns what FUN
returns when called with the
arguments given in ...
option.bak <- getOption("stringsAsFactors")
d1 <- callWithStringsAsFactors(
TRUE,
rbind,
data.frame(id = 1, name = "Peter"),
data.frame(id = 2, name = "Paul"),
data.frame(id = 3, name = "Mary")
)
d2 <- callWithStringsAsFactors(
FALSE,
rbind,
data.frame(id = 1, name = "Peter"),
data.frame(id = 2, name = "Paul"),
data.frame(id = 3, name = "Mary")
)
str(d1)
str(d2)
# The option "stringsAsFactors" has not changed!
stopifnot(option.bak == getOption("stringsAsFactors"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.