R’s default behaviour in regard to creating data.frames is to convert any charcter vectors to type factor - some like it, some not …
data.frame(a=letters[1:2])$a
## [1] a b
## Levels: a b
Now the hellno package was written to overcome that feature in case one does not at all like the default and prefers to be explicit about string conversion and one stil wants to use data.frames. Loading the package will result in putting the alternative implementations of data.frame()
and as.data.frame()
before those from package base. R gives a message to inform us about that and hence the no string conversion takes place anymore:
library(hellno)
##
## Attaching package: 'hellno'
##
## Die folgenden Objekte sind maskiert von 'package:base':
##
## as.data.frame, data.frame
data.frame(a=letters[1:2])$a
## [1] "a" "b"
Unloading hellno again to show programming behaviour:
unloadNamespace("hellno")
Another approach is to use hellno as import in other packages to get the behaviour consistently inside a package.
Loading the package (that uses hellno internally) does not change the default R behaviour.
library(hellnotests)
data.frame(a=letters[1:2])$a
## [1] a b
## Levels: a b
While all functions within the package use hellno’s alternative implementations:
hellno_df
## function() {
## data.frame(a=letters[1:3])$a
## }
## <environment: namespace:hellnotests>
… and hence for them string conversion is no matter anymore:
hellno_df()
## [1] "a" "b" "c"