I cannot figure out how to use select.treedata() inside another function.
tree<-pbtree(n=100, scale=1)
Q<-matrix(c(-1,1,1,-1),2,2)
rownames(Q)<-colnames(Q)<-1:2
x<-sim.history(tree,Q)$states
y<-setNames(as.numeric(x),names(x))
ydf <- as.data.frame(y)
ytd<-make.treedata(tree, ydf)
#either of these work
select(ytd, 2)
select(ytd, y)
# now try in a function
foo<-function(ytd, columnSelect) {
ynew<-select(ytd, columnSelect)
return(ynew)
}
# now these don't work, and return what was (to me) a strange error
foo(ytd, 2)
foo(ytd, y)
# I think I get what's happening - the second argument is passed through to dplyr 'select'
# as 'columnSelect' and the variable within the function is being ignored.
# I am not sure how to fix this.
# there are hacks online but this might be a real issue:
# http://stackoverflow.com/questions/22919448/passing-function-argument-to-dplyr-select
I cannot figure out how to use select.treedata() inside another function.