jwood000/RcppAlgos

permuteGeneral alters source vector

Closed this issue · 3 comments

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

@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

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

@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