File: argparse.R

package info (click to toggle)
r-cran-argparse 2.2.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: sh: 13; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 2,898 bytes parent folder | download | duplicates (3)
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
## ----echo=FALSE---------------------------------------------------------------
library("knitr")
rscript_executable <- paste(file.path(R.home(), "bin", "Rscript"), "--vanilla")
opts_knit$set(root.dir = system.file("exec", package = "argparse")) # to access the "Rscript files"
opts_chunk$set(comment = NA, echo = FALSE)
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))