[R] substitute, expression and factors

baptiste auguie baptiste.auguie at googlemail.com
Tue May 18 22:36:47 CEST 2010


Dear list,

I am puzzled by this,

substitute(expression(x), list(x = factor(letters[1:2])))
# expression(1:2)

Why do I get back the factor levels inside the expression and not the
labels? The following work as I expected,

substitute(expression(x), list(x = letters[1:2]))
# expression(c("a", "b"))

substitute(x, list(x = factor(letters[1:2])))
# [1] a b
# Levels: a b

 bquote(.(factor(letters[1:2])))
# [1] a b
# Levels: a b


All the best,

baptiste



More information about the R-help mailing list