# Simply opens the file in the first argument and draws a histogram as png # as the file.png or the second argument if provided ## Capture command line arguments args <- (commandArgs(TRUE)) ## Read in tab-delimited file as a table ## Use the first line as column headers data <- read.table(args[1], head=FALSE, as.is=TRUE) ## Apply user-defined output filename, if it was specified if (length(args) > 1){ outfile <- args[2] } else { outfile <- paste(args[1], ".png", sep="") } ## Initialize PNG output file and specify dimensions png(file=outfile, w=600, h=500) ## Print a histogram to the PNG file with custom labels hist(data$V2, nclass=50, xlab="Read length", main="Distribution of lengths") ## Close output file dev.off()