-
Notifications
You must be signed in to change notification settings - Fork 0
/
individual_assignment_1.Rmd
97 lines (53 loc) · 5.2 KB
/
individual_assignment_1.Rmd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
## Individual assignment 1
rubric={correctness:1}
The purpose of this assignment is to ensure that everyone does some self-learning and obtains practice on using docopt to create command line arguements in scripts, as well as creating releases on GitHub. This assignment will be graded for completion. You must attempt all questions to get the grade.
### Submission instructions
You must also submit a `.html` version of this homework to Canvas.
### Exercise 1
Create a public repository on GitHub.com called `docopt_demo`. Paste the url below:
> <https://github.com/Vikiano/docopt_demo>
### Exercise 2
**Getting documentation from a {docopt} R script**
In [this repo](https://github.ubc.ca/MDS-2021-22/DSCI_522_dsci-workflows_students), in the `src` directory, you will find a script named `demo.R`. Access the documentation for that script from the command line by running the script with the `--help` option (and no other options or arguments). Paste the documentation that was printed out to your terminal below.
> This script prints out docopt args.
> Usage: demo.R <arg1> --arg2=<arg2> [--arg3=<arg3>]
>
> Options:
> <arg1> Takes any value (this is a required positional argument)
> --arg2=<arg2> Takes any value (this is a required option)
> [--arg3=<arg3>] Takes any value (this is an optional option)
### Exercise 3
**What does `docopt` return in R?**
Run the `demo.R` script giving it appropriate arguments to see what the `docopt` function in R returns. Try setting and not setting a value for `arg3`. Describe what you observed below.
For options, you need to include the `--` in the command line call, for example:
Rscript src/my_script something --anoption=something more
> When a value was not set for only `arg3`, the script still runs but ouptut **NULL** for arg3. When a value was set for `arg3`, the script runs and ouptut the value of arg3. When you don't specify a required argument (arg2, or the defualt positional argument), the script does not run but instead throw an error and the usage documentation.
### Exercise 4
**Break this script!**
Run the `demo.R` script and find at least 3 different ways to break it by changing the values or order of the command line arguments at the command line (do not modify the script). Document how you did this below.
> 1. `$ Rscript demo.R 1 --arg3=3`
> 2. `$ Rscript demo.R 1 2 3`
> 3. `$ Rscript demo.R 1 arg2=2 arg3=3`
### Exercise 5
**Add a new optional positional argument**
Copy the `demo.R` script into your `docopt_demo` repo, and then edit it to add a new positional argument that is optional. Also modify the script so that it prints out the value for this new argument in addition to the entire `docopt` object and `docopt` object type. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/Vikiano/docopt_demo/commit/88d1acc7fe43d3bd14de9f3768870fa5239b9f5c>
### Exercise 6
**Add a main function**
Modify the `demo.R` script further so that the three print statements happen inside a main function. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/Vikiano/docopt_demo/commit/642fe26f44a6ad3da5123070d360c9b24d1b7740>
### Exercise 7
**What does `docopt` return in Python?**
In [this repo](https://github.ubc.ca/MDS-2021-22/DSCI_522_dsci-workflows_students), in the `src` directory, you will find a script named `demo.py`. Run the `demo.py` script giving it appropriate arguments to see what the `docopt` function in Python returns. Try setting and not setting a value for `arg3`. How does this differ from what `docopt` returns in R? Describe what you observed below.
> > When a value was not set for only `arg3`, the script still runs but ouptut **None** for arg3. When a value was set for `arg3`, the script runs and ouptut the value of arg3. When you don't specify a required argument (arg2, or the defualt positional argument), the script does not run but instead returns the usage documentation
### Exercise 8
**Add a new optional positional argument**
Copy the `demo.py` script into your `docopt_demo` repo, and then edit it to add a new positional argument that is optional. Also modify the script so that it prints out the value for this new argument in addition to the entire `docopt` object and `docopt` object type. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/Vikiano/docopt_demo/commit/e83e64d754668a623ae0c98237c08218867caabc>
### Exercise 9
Modify the `demo.py` script further so that the three print statements happen inside a main function. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/Vikiano/docopt_demo/commit/6f4851edb9ae6a6a41f1c5b187d0cefdf0cb2043>
### Exercise 10
Create a release in your `docopt_demo` repo called `0.1.0`. Paste the URL to this release below.
\*Hint: See the [creating a release docs](https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/managing-releases-in-a-repository#creating-a-release) to help complete this exercise.
> <https://github.com/Vikiano/docopt_demo/releases/tag/0.1.0>