Skip to content

Instantly share code, notes, and snippets.

@tsnow
Created July 24, 2013 23:35
Show Gist options
  • Save tsnow/6075620 to your computer and use it in GitHub Desktop.
Save tsnow/6075620 to your computer and use it in GitHub Desktop.
library("optparse")
option_list <- list(
make_option(c("-p", "--no_png"), action="store",default='TRUE')
)
args <- parse_args(OptionParser(option_list = option_list))
no_png <- args$no_png == "TRUE"
f <- file("stdin")
open(f)
print.matrix <- function(m){
write.table(format(m, justify="right"),
row.names=F, col.names=F, quote=F)
}
nums <- as.numeric(readLines(f,warn=FALSE))
close(f)
num_summary <- summary(nums)
summary_names <- gsub(pattern=" Qu.","",names(num_summary))
summary_matrix <- t(matrix(c(summary_names,as.vector(num_summary)),ncol=6,byrow=T))
print(summary_matrix)
if(!no_png){
png(filename="script.png")
#par(mfcol=c(2,1))
hist(nums)
invisible(dev.off())
png(filename="script2.png")
plot(nums)
invisible(dev.off())
system("open script.png script2.png")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment