vector to digest function #2

Closed
jangorecki opened this Issue Nov 1, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@jangorecki

Is there any more efficient way to turn vector of characters into vector of its hashes then presented below?

col <- c("asd1","asd2","asd3","asd2","asd1")
masking <- function(col) vapply(col, function(object) digest(object, algo="md5"), FUN.VALUE = "", USE.NAMES = FALSE)
masking(col)
col

and not only for md5

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Nov 2, 2014

Owner

Not currently. But if you have large vectors, and do this frequently, it would take probably less than 10 lines with Rcpp to make a really fast variant that loops on the compiled side. And with the extra hand-holding maybe 25 lines in plain C. If you want to contribute that ...

I think digest() does what it is designed for, so I think I'd like to close this here.

Owner

eddelbuettel commented Nov 2, 2014

Not currently. But if you have large vectors, and do this frequently, it would take probably less than 10 lines with Rcpp to make a really fast variant that loops on the compiled side. And with the extra hand-holding maybe 25 lines in plain C. If you want to contribute that ...

I think digest() does what it is designed for, so I think I'd like to close this here.

@jangorecki

This comment has been minimized.

Show comment
Hide comment
@jangorecki

jangorecki Nov 2, 2014

Ok, thanks for the information. Just for future readers I'm leaving the non-Rcpp solution, faster then the one from the first post

masking <- function(x, algo="crc32"){
  unq_hashes <- vapply(unique(x), function(object) digest(object, algo=algo), FUN.VALUE="", USE.NAMES=TRUE)
  unname(unq_hashes[x])
}

Ok, thanks for the information. Just for future readers I'm leaving the non-Rcpp solution, faster then the one from the first post

masking <- function(x, algo="crc32"){
  unq_hashes <- vapply(unique(x), function(object) digest(object, algo=algo), FUN.VALUE="", USE.NAMES=TRUE)
  unname(unq_hashes[x])
}

@jangorecki jangorecki closed this Nov 2, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment