# NOT RUN {
d <- data.frame(Sepal_Length=c(5.8,5.7),
Sepal_Width=c(4.0,4.4),
Species='setosa',
rank=c(1,2))
RANKCOLUMN <- NULL # optional, make sure macro target does not look like unbound variable.
GROUPCOLUMN <- NULL # optional, make sure macro target does not look like unbound variable.
mapping = c(RANKCOLUMN= 'rank', GROUPCOLUMN= 'Species')
let(alias = mapping,
expr = {
# Notice code here can be written in terms of known or concrete
# names "RANKCOLUMN" and "GROUPCOLUMN", but executes as if we
# had written mapping specified columns "rank" and "Species".
# restart ranks at zero.
dres <- d
dres$RANKCOLUMN <- dres$RANKCOLUMN - 1 # notice, using $ not [[]]
# confirm set of groups.
groups <- unique(d$GROUPCOLUMN)
},
debugPrint = TRUE
)
print(groups)
print(length(groups))
print(dres)
# }
Run the code above in your browser using DataLab