R/main.R
callWithStringsAsFactors.Rd
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)#> 'data.frame': 3 obs. of 2 variables: #> $ id : num 1 2 3 #> $ name: Factor w/ 3 levels "Peter","Paul",..: 1 2 3str(d2)#> 'data.frame': 3 obs. of 2 variables: #> $ id : num 1 2 3 #> $ name: chr "Peter" "Paul" "Mary"# The option "stringsAsFactors" has not changed! stopifnot(option.bak == getOption("stringsAsFactors"))