Mercurial > repos > mingchen0919 > one_command_liners
comparison tool_template_render.R @ 11:670e1591cc65 draft
update
| author | mingchen0919 |
|---|---|
| date | Sat, 24 Feb 2018 10:44:30 -0500 |
| parents | a9f93a4742b1 |
| children | 9cf29b2374a6 |
comparison
equal
deleted
inserted
replaced
| 10:49cabfe55b61 | 11:670e1591cc65 |
|---|---|
| 1 zz = file("warnings_and_errors.txt") | 1 zz = file("warnings_and_errors.txt") |
| 2 sink(zz) | 2 sink(zz) |
| 3 sink(zz, type = "message") | 3 sink(zz, type = "message") |
| 4 | |
| 4 | 5 |
| 5 # bring user inputs and command line arguments to R | 6 # bring user inputs and command line arguments to R |
| 6 spec_matrix = as.matrix( | 7 spec_matrix = as.matrix( |
| 7 data.frame(stringsAsFactors=FALSE, | 8 data.frame(stringsAsFactors=FALSE, |
| 8 long_flags = c("X_e", "X_A", "X_B", "X_O", "X_r", "X_d", "X_s", | 9 long_flags = c("X_e", "X_A", "X_B", "X_O", "X_r", "X_d", "X_s", |
| 15 ) | 16 ) |
| 16 ) | 17 ) |
| 17 opt = getopt::getopt(spec_matrix) | 18 opt = getopt::getopt(spec_matrix) |
| 18 opt | 19 opt |
| 19 | 20 |
| 20 rmarkdown::render(input = opt$X_t, output_file = opt$X_O) | 21 # build command: awk '{print $1,$2}' > output.txt and run |
| 22 X_A = paste0(paste0('$', trimws(strsplit(opt$X_A, ',')[[1]])), collapse = ',') | |
| 23 extract_field_command = paste0("awk '{print ", X_A, " }' ", opt$X_B, " > ", opt$X_O) | |
| 24 system(command = extract_field_command) | |
| 25 | |
| 21 | 26 |
| 22 sink() | 27 sink() |
