Skip to content

Instantly share code, notes, and snippets.

@aL3xa
Last active December 10, 2015 15:38
Show Gist options
  • Save aL3xa/4455572 to your computer and use it in GitHub Desktop.
Save aL3xa/4455572 to your computer and use it in GitHub Desktop.
Simple and pointless demonstration of R system call output manipulation
#!/usr/bin/Rscript --vanilla
## grab arguments from command line
args <- commandArgs(TRUE)
## replace all argument values with "moo"
s <- sapply(nchar(args) - 1, function(times) paste0("m", paste0(rep("o", times), collapse = "")))
## execute a system cmd (cowsay)
cs <- system2("cowsay", s, stdout = TRUE)
## cat altered output
cat(cs, sep = "\n")
## call from the shell
## ➜ ~ ./mooifier.R ovo nema nikakvog smisla ali ipak radi
## ________________________________________
## < moo mooo mooooooo mooooo moo mooo mooo >
## ----------------------------------------
## \ ^__^
## \ (oo)\_______
## (__)\ )\/\
## ||----w |
## || ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment