Last active
August 29, 2015 13:56
Revisions
-
mschubert revised this gist
Feb 26, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,4 @@ # examples: paths %|% "grep -o [^/]+$" # get file names from directories mywords %|% "sed /foo/d" # remove entries containing the word 'foo' c(1:5) %|% sum # use the R sum function -
mschubert revised this gist
Feb 26, 2014 . 1 changed file with 11 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,14 @@ # a unix-like pipe operator in R to perform CLI operations (or call R functions) `%|%` = function(x, command) { if (class(command) == 'function') { command(x) } else { stopifnot(class(x) %in% c('character', 'numeric', 'integer')) system(command, input=as.character(x), intern=TRUE) } } # examples: paths %|% "grep -o [^/]+$" # get file names from directories mywords %|% "sed /foo/d" # remove entries containing the word 'foo' c(1:5) %|% sum # use the R sum function -
mschubert revised this gist
Feb 23, 2014 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,7 @@ # a 'unix' operator in R to perform CLI operations similar to a pipe %unix% = function(x, command) { stopifnot(class(x) == 'character' || class(x) == 'numeric') system(command, input=x, intern=TRUE) } # examples: -
mschubert revised this gist
Feb 20, 2014 . 1 changed file with 12 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,39 +1,16 @@ # a 'unix' operator in R to perform CLI operations similar to a pipe `%unix%` = function(x, command) { stopifnot(class(x) == 'character' || class(x) == 'numeric') tryCatch( system(paste0(command, " <<< '", paste(x, collapse="\n"), "'"), intern=TRUE), error = function(e) NULL, warning = function(w) NULL) } # examples: # get file names from directories paths %unix% "grep -o [^/]+$" # remove entries containing the word 'foo' mywords %unix% "sed /foo/d" -
mschubert created this gist
Feb 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ sed = function(x, pattern) { mynames = names(x) x = sapply(x, function(i) { type = class(i) result = system(paste("echo ", i, " | sed ", pattern, sep=""), intern=TRUE) class(result) = type result }) names(x) = mynames x } '%sed%' = function(x, pattern) { sed(x, pattern) } egrep = function(x, pattern) { stopifnot(class(pattern) == 'character' || class(pattern) == 'numeric') type = class(x) result = list() for (i in as.list(x)) { tryCatch({ result = c(result, system(paste("echo ", i, " | grep ", pattern, sep=""), intern=TRUE)) }, error = function(e) { NULL }, warning = function(w) { NULL }) } class(result) = type result } '%grep%' = function(x, pattern) { egrep(x, pattern) }