RcppAlgos icon indicating copy to clipboard operation
RcppAlgos copied to clipboard

table input

Open ggrothendieck opened this issue 4 years ago • 2 comments

This works:

library(RcppAlgos)
x <- c("a", "b", "b")
tab <- table(x)
permuteGeneral(v = names(tab), freq = tab)

but it would be nice if it directly accepted "table" objects.

permuteGeneral(tab)

ggrothendieck avatar May 20 '21 13:05 ggrothendieck

@ggrothendieck,

Thanks for opening this issue.

I really like the suggestion.

I can think of a few ways of implementing this. For example, we can check to see if the class of v is table. I do have some concerns... mainly, would this be too restrictive. For example, are there other "table" like objects that I would be missing (something like rle). Maybe, it's okay to be restrictive.

Do you have suggestions for a good way of cleanly handling this?

Thanks, Joseph

jwood000 avatar May 22 '21 01:05 jwood000

PermutateGeneral could be turned into an S3 generic with table and default methods (and maybe others in the future?).

ggrothendieck avatar May 22 '21 14:05 ggrothendieck

@ggrothendieck,

It has been a while since you posted this issue.

I have started to work on this about a half a dozen times over the past couple of years and this is what I currently have: 92576896e51f797106119410431e6ddf6fa21822

I'm not really happy with it... It feels messy. I was thinking I could clean up the R code with a clever function factory implementation, but before I go off deep end I'd like to see what you think.

I have seen many post from you on stackoverflow about this topic and meta-programming in general. I've also looked at many packages with S3 methods such as one you are involved with, zoo.

Thanks, Joseph

jwood000 avatar Oct 22 '23 00:10 jwood000

I've further expanded the use of S3 methods throughout the package. I added a link to the branch under the Development section.

jwood000 avatar Nov 16 '23 16:11 jwood000