Can as_factor from forcats return an ordered factor? It seems like a missing feature if not although I haven't seen it reported as an issue on the GitHub page.
I have tried:
y <- forcats::as_factor(c("a", "z", "g"), ordered = TRUE)
is.ordered(y)
# FALSE
If I can't then is there any potential danger in doing:
y <- ordered(forcats::as_factor(c("a", "z", "g")))
Or would it be better to do:
y <- factor(c("a", "z", "g"), levels = unique(c("a", "z", "g")), ordered = TRUE))
It appears this indeed is an unexpected behavior.
forcats::as_factoris forcing it to be ordered as they appear, but somehow does not set the flag. But combining it withbase::factor, it's not required to explicitly specify the ordering, just setting the flag seems to work fine.