Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Created December 15, 2020 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdwab/24e3b933940cc0425c1b65d2f7e931af to your computer and use it in GitHub Desktop.
Save mrdwab/24e3b933940cc0425c1b65d2f7e931af to your computer and use it in GitHub Desktop.
# Using `fread` and `fwrite` to paste together columns like `do.call(paste, ...)`
fpaste <- function(dt, sep = ",") {
x <- tempfile()
if (sep == "") {
data.table(V1 = do.call(stringi::stri_join, c(dt, sep = "")))
} else {
fwrite(dt, file = x, sep = sep, col.names = FALSE)
fread(x, sep = "\n", header = FALSE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment