jwood000 / RcppAlgos

Tool for Solving Problems in Combinatorics and Computational Mathematics
GNU General Public License v2.0
45 stars 5 forks source link

permuteGeneral alters source vector #11

Closed rbmayer closed 4 years ago

rbmayer commented 5 years ago

After passing a source vector from a dataframe to permuteGeneral, the source dataframe is altered.

# compare mydf before and after running permuteGeneral
> name <- c('first', 'second', 'third')
> rank <- c('1st', '2nd', '3rd')
> mydf <- data.frame(name, rank, stringsAsFactors = FALSE)

> mydf
    name rank
1  first  1st
2 second  2nd
3  third  3rd

> permutations <- permuteGeneral(mydf[,"name"], 3)

> mydf
    name rank
1  third  1st
2  first  2nd
3 second  3rd
jwood000 commented 5 years ago

@rbmayer ,

Thanks for reporting this. It is being caused by not making a full copy. We can get around that by calling Rcpp::clone. See more here https://stackoverflow.com/a/21282929.

This will be fixed in the next release. I won't close until then.

Thanks again, Joseph Wood

rbmayer commented 5 years ago

@jwood000 Thanks for the quick response and the link to a temporary workaround.

jwood000 commented 4 years ago

@rbmayer ,

This is fixed in version 2.3.6. It is on CRAN now. The binaries haven't been built for every platform, but they should be there within a couple of days.

Thanks again for reporting