File: optparse.R

package info (click to toggle)
r-cran-optparse 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 236 kB
  • sloc: sh: 9; makefile: 1
file content (78 lines) | stat: -rw-r--r-- 3,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

## ----echo=FALSE----------------------------------------------------------
 library("knitr")
 Rscript_executable <- paste(file.path(R.home(), "bin", "Rscript"), "--vanilla")
 opts_knit$set(root.dir = system.file("exec", package="optparse")) # to access the "Rscript files"
 opts_chunk$set(comment=NA, echo=FALSE) 
 # setwd(system.file("exec", package="optparse")) # to access the "Rscript files"
 list_file_command <- "ls"
 chmod_command <- "chmod ug+x display_file.R example.R"
 path_command <- "export PATH=$PATH:`pwd`"
 run_command <- function(string) { suppressWarnings(cat(system(string, intern=TRUE), sep="\n")) }


## ------------------------------------------------------------------------
 run_command(sprintf("%s", list_file_command))
 command <- "display_file.R example.R" # to show file


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))   


## ------------------------------------------------------------------------
 command <- "example.R --help" # same as system("Rscript example.R -h")


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))   
 command <- "example.R" # rely only on defaults


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))   
 command <- "example.R --mean=10 --sd=10 --count=3" 


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "example.R --quiet -c 4 --generator=\"runif\"" #  same as above but "quiet"


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "example.R --silent -m 5" #  same as above but "quiet"


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "example.R -c 100 -c 2 -c 1000 -c 7" #  same as above but "quiet"


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))


## ------------------------------------------------------------------------
 command <- "display_file.R --help" 


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "display_file.R --add_numbers display_file.R" 


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "display_file.R non_existent_file.txt" 


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))
 command <- "display_file.R"


## ------------------------------------------------------------------------
 run_command(sprintf("%s %s 2>&1", Rscript_executable, command))