Skip to content

Instantly share code, notes, and snippets.

@vsbuffalo
Created March 18, 2015 03:17
Show Gist options
  • Save vsbuffalo/14f2fbdbb06176fd4f3b to your computer and use it in GitHub Desktop.
Save vsbuffalo/14f2fbdbb06176fd4f3b to your computer and use it in GitHub Desktop.
Yo dawg, I heard you like pipes, so I put a pipe in your pipe, so you can pipe streams while you pipe streams
library(magrittr)
write.table(iris, file="iris.txt", sep="\t", row.names=FALSE, quote=FALSE)
plines <- function(cmd) readLines(pipe(cmd))
ptabs <- function(cmd) read.delim(pipe(cmd))
# just as a trivial example, process some shuffled lines using GNU shuf, sort,
# etc. (we could do this in R, but this is to simulate command line operations)
ptabs("gshuf iris.txt | sort -k5,5 -k1,1n | cut -d '\t' -f 1,2") %>% plot
@noamross
Copy link

So can this be done without writing the file to disk, e.g., ptabs(input, cmd)? Perhaps with fifo()?

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