-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindividual_assignment_1.Rmd
98 lines (54 loc) · 4.9 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
98
## 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 should commit and push your changes to the public GitHub.com repository you created in exercise 1.
- You should submit a `.html` version of this assignment to Canvas.
### Exercise 1
Create a public repository on GitHub.com called `docopt_demo`. Paste the url below:
> <https://github.com/austin-shih/docopt_demo>
### Exercise 2
**Getting documentation from a {docopt} R script**
In [this repo](https://github.ubc.ca/MDS-2022-23/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:
> <arg> 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
> **answer**: The script prints out the assigned values to the `arg`s. If `arg3` is not set, the terminal will print `arg3` as `NULL`
### 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. Not providing a value for `arg1`, or the first positional argument is not given.
> 2. Not providing a value for `arg2.`
> 3. Providing `arg4`, the script can not take in an argument that's not a defined option.
### 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. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/austin-shih/docopt_demo/commit/fb88abe901dc2f6948b95c4f165bc7939033a845>
### Exercise 6
**Add a main function**
Modify the `demo.R` script further so that the 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/austin-shih/docopt_demo/commit/7ae3a4152d0974e7909d9412f5b7dc2770793aa0>
### Exercise 7
**What does `docopt` return in Python?**
In [this repo](https://github.ubc.ca/MDS-2022-23/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.
> **answer**: The script takes in any value for positional argument `arg1` and any value for argument `arg2` and optional for `arg3`. The script then print the output as a dictionary as with `arg2` first, then `arg3`, then `<arg1>`. If `arg3` is not given then the value will be `None`.
### 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. Commit this change and push it to your `docopt_demo` repository. Paste the URL to this commit below:
> <https://github.com/austin-shih/docopt_demo/commit/8c0fc01ad8e00f12b4eb84d0a9f177dbdc636fe7>
### Exercise 9
Modify the `demo.py` script further so that the 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/austin-shih/docopt_demo/commit/75f302e3c6f451e7c6f3b498e688de51c9695492>
### 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/austin-shih/docopt_demo/releases/tag/0.1.0>