Last active
December 10, 2015 15:38
-
-
Save aL3xa/4455572 to your computer and use it in GitHub Desktop.
Simple and pointless demonstration of R system call output manipulation
This file contains 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 characters
#!/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