├── worksheet_viz
├── cleanup.R
└── data
│ └── world_vaccination.csv
├── CNAME
├── worksheet_intro
├── cleanup.R
├── images
│ ├── disk.png
│ ├── ws1_assign.png
│ ├── ws1_filter.png
│ ├── ws1_ggplot.png
│ ├── ws1_mutate.png
│ ├── ws1_select.png
│ ├── numberline_0.png
│ ├── numberline_1.png
│ ├── ws1_filter_NA.png
│ ├── ws1_read_csv.png
│ ├── magnifying_glass.png
│ ├── ws1_error_image.png
│ ├── ws1_filter_gen.png
│ ├── ws1_ggplot_male.png
│ ├── ws1_mutate_gen.png
│ ├── ws1_read_csv_gen.png
│ ├── ws1_select_gen.png
│ ├── ws1_ggplot_female.png
│ ├── ws1_mutate_female.png
│ ├── ws1_select_female.png
│ ├── ws1_read_csv_correct.png
│ └── Screen Shot 2018-07-06 at 4.37.16 PM.png
├── output_121_2.png
├── output_126_2.png
└── tests.R
├── worksheet_wrangling
├── cleanup.R
└── data
│ └── departure_bay_temperature.csv
├── _includes
├── footer.html
└── google-analytics.html
├── worksheet_clustering
├── cleanup.R
└── tests.R
├── worksheet_inference1
├── cleanup.R
└── tests.R
├── worksheet_inference2
├── cleanup.R
└── tests.R
├── worksheet_classification1
└── cleanup.R
├── worksheet_regression2
├── cleanup.R
└── tests.R
├── worksheet_classification2
├── cleanup.R
├── data
│ └── fruit_data.csv
└── tests.R
├── worksheet_regression1
├── cleanup.R
├── img
│ ├── k-nn.jpeg
│ └── k-nn_RMSE.jpeg
└── tests.R
├── worksheet_version_control
├── cleanup.R
├── img
│ ├── logo.png
│ ├── rename.png
│ ├── commits_link.png
│ ├── new-notebook.png
│ ├── to-get-to-root.png
│ ├── commits_history_link.png
│ └── to-get-to-project-root.png
└── tests.R
├── worksheet_reading
├── cleanup.R
└── data
│ ├── flights_filtered.db
│ ├── happiness_report.xlsx
│ ├── happiness_report_no_header.csv
│ ├── happiness_report.tsv
│ ├── happiness_report.csv
│ ├── happiness_report_semicolon.csv
│ └── happiness_report_metadata.csv
├── _config.yml
├── Dockerfile
├── .github
└── workflows
│ └── update_environment.yml
├── LICENSE.md
└── README.md
/worksheet_viz/cleanup.R:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CNAME:
--------------------------------------------------------------------------------
1 | worksheets.datasciencebook.ca
--------------------------------------------------------------------------------
/worksheet_intro/cleanup.R:
--------------------------------------------------------------------------------
1 | # Clean up datafiles that students output
--------------------------------------------------------------------------------
/worksheet_wrangling/cleanup.R:
--------------------------------------------------------------------------------
1 | # cleanup datafiles students output
--------------------------------------------------------------------------------
/_includes/footer.html:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/worksheet_clustering/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_inference1/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_inference2/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_classification1/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_regression2/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_classification2/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
--------------------------------------------------------------------------------
/worksheet_regression1/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
3 |
--------------------------------------------------------------------------------
/worksheet_version_control/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
3 |
4 |
--------------------------------------------------------------------------------
/worksheet_reading/cleanup.R:
--------------------------------------------------------------------------------
1 | # clean up data files that students output
2 |
3 | unlink('data/delay_data.csv')
4 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | title: "Data Science: A First Introduction Worksheets"
2 | theme: minima
3 | google_analytics: G-B5Q4J8ZFKZ
4 |
--------------------------------------------------------------------------------
/worksheet_intro/images/disk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/disk.png
--------------------------------------------------------------------------------
/worksheet_intro/output_121_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/output_121_2.png
--------------------------------------------------------------------------------
/worksheet_intro/output_126_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/output_126_2.png
--------------------------------------------------------------------------------
/worksheet_regression1/img/k-nn.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_regression1/img/k-nn.jpeg
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_assign.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_assign.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_filter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_filter.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_ggplot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_ggplot.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_mutate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_mutate.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_select.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_select.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/logo.png
--------------------------------------------------------------------------------
/worksheet_intro/images/numberline_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/numberline_0.png
--------------------------------------------------------------------------------
/worksheet_intro/images/numberline_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/numberline_1.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_filter_NA.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_filter_NA.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_read_csv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_read_csv.png
--------------------------------------------------------------------------------
/worksheet_regression1/img/k-nn_RMSE.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_regression1/img/k-nn_RMSE.jpeg
--------------------------------------------------------------------------------
/worksheet_version_control/img/rename.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/rename.png
--------------------------------------------------------------------------------
/worksheet_intro/images/magnifying_glass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/magnifying_glass.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_error_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_error_image.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_filter_gen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_filter_gen.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_ggplot_male.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_ggplot_male.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_mutate_gen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_mutate_gen.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_read_csv_gen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_read_csv_gen.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_select_gen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_select_gen.png
--------------------------------------------------------------------------------
/worksheet_reading/data/flights_filtered.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_reading/data/flights_filtered.db
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_ggplot_female.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_ggplot_female.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_mutate_female.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_mutate_female.png
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_select_female.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_select_female.png
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_reading/data/happiness_report.xlsx
--------------------------------------------------------------------------------
/worksheet_intro/images/ws1_read_csv_correct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/ws1_read_csv_correct.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/commits_link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/commits_link.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/new-notebook.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/new-notebook.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/to-get-to-root.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/to-get-to-root.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/commits_history_link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/commits_history_link.png
--------------------------------------------------------------------------------
/worksheet_version_control/img/to-get-to-project-root.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_version_control/img/to-get-to-project-root.png
--------------------------------------------------------------------------------
/worksheet_intro/images/Screen Shot 2018-07-06 at 4.37.16 PM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD/worksheet_intro/images/Screen Shot 2018-07-06 at 4.37.16 PM.png
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Copyright (c) UBC-DSCI Development Team.
2 | FROM ubcdsci/r-dsci-100:202308310221101cdf31
3 |
4 | # Switch the working directory back to the homedir
5 | WORKDIR ${HOME}
6 |
7 | # Make sure the contents of our repo are in ${HOME} for binder
8 | COPY . ${HOME}
9 | USER root
10 | RUN chown -R ${NB_UID} ${HOME}
11 | USER ${NB_USER}
12 |
--------------------------------------------------------------------------------
/_includes/google-analytics.html:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/.github/workflows/update_environment.yml:
--------------------------------------------------------------------------------
1 | name: Update the environment file
2 | on:
3 | push:
4 | branches:
5 | - main
6 | paths:
7 | - Dockerfile
8 | jobs:
9 | rebuild-docker:
10 | runs-on: ubuntu-latest
11 | permissions:
12 | contents: write
13 | steps:
14 | - name: Checkout main
15 | uses: actions/checkout@v3
16 | with:
17 | fetch-depth: '0'
18 | ref: 'main'
19 | - name: Build the docker image
20 | run: docker build -t local .
21 | - name: Generate the environment file
22 | run: docker run --rm -v $(pwd):/home/jovyan/work local mamba env export > environment.yml
23 | - name: Commit the updated env
24 | run: |
25 | git config --local user.email "action@github.com"
26 | git config --local user.name "GitHub Action"
27 | git add environment.yml
28 | git commit -m "Update environment.yml based on new Docker image"
29 | - name: Push changes to build scripts
30 | uses: ad-m/github-push-action@master
31 | with:
32 | github_token: ${{ secrets.GITHUB_TOKEN }}
33 | branch: 'main'
34 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | These worksheets are made available under the **Attribution-NonCommercial-ShareAlike 4.0 International** ([CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)).
4 |
5 | This is a human-readable summary of (and not a substitute for) the [license](https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
6 |
7 | ## You are free to:
8 |
9 | - **Share** — copy and redistribute the material in any medium or format
10 | - **Adapt** — remix, transform, and build upon the material
11 |
12 | The licensor cannot revoke these freedoms as long as you follow the license terms.
13 |
14 | ## Under the following terms:
15 |
16 | - **Attribution** — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
17 | - **NonCommercial** — You may not use the material for commercial purposes.
18 | - **ShareAlike** — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
19 |
20 | **No additional restrictions** — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
21 |
22 | ## Notices:
23 |
24 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
25 |
26 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
27 |
--------------------------------------------------------------------------------
/worksheet_classification2/data/fruit_data.csv:
--------------------------------------------------------------------------------
1 | fruit_label,fruit_name,fruit_subtype,mass,width,height,color_score
2 | 1,apple,granny_smith,192,8.4,7.3,0.55
3 | 1,apple,granny_smith,180,8,6.8,0.59
4 | 1,apple,granny_smith,176,7.4,7.2,0.6
5 | 2,mandarin,mandarin,86,6.2,4.7,0.8
6 | 2,mandarin,mandarin,84,6,4.6,0.79
7 | 2,mandarin,mandarin,80,5.8,4.3,0.77
8 | 2,mandarin,mandarin,80,5.9,4.3,0.81
9 | 2,mandarin,mandarin,76,5.8,4,0.81
10 | 1,apple,braeburn,178,7.1,7.8,0.92
11 | 1,apple,braeburn,172,7.4,7,0.89
12 | 1,apple,braeburn,166,6.9,7.3,0.93
13 | 1,apple,braeburn,172,7.1,7.6,0.92
14 | 1,apple,braeburn,154,7,7.1,0.88
15 | 1,apple,golden_delicious,164,7.3,7.7,0.7
16 | 1,apple,golden_delicious,152,7.6,7.3,0.69
17 | 1,apple,golden_delicious,156,7.7,7.1,0.69
18 | 1,apple,golden_delicious,156,7.6,7.5,0.67
19 | 1,apple,golden_delicious,168,7.5,7.6,0.73
20 | 1,apple,cripps_pink,162,7.5,7.1,0.83
21 | 1,apple,cripps_pink,162,7.4,7.2,0.85
22 | 1,apple,cripps_pink,160,7.5,7.5,0.86
23 | 1,apple,cripps_pink,156,7.4,7.4,0.84
24 | 1,apple,cripps_pink,140,7.3,7.1,0.87
25 | 1,apple,cripps_pink,170,7.6,7.9,0.88
26 | 3,orange,spanish_jumbo,342,9,9.4,0.75
27 | 3,orange,spanish_jumbo,356,9.2,9.2,0.75
28 | 3,orange,spanish_jumbo,362,9.6,9.2,0.74
29 | 3,orange,selected_seconds,204,7.5,9.2,0.77
30 | 3,orange,selected_seconds,140,6.7,7.1,0.72
31 | 3,orange,selected_seconds,160,7,7.4,0.81
32 | 3,orange,selected_seconds,158,7.1,7.5,0.79
33 | 3,orange,selected_seconds,210,7.8,8,0.82
34 | 3,orange,selected_seconds,164,7.2,7,0.8
35 | 3,orange,turkey_navel,190,7.5,8.1,0.74
36 | 3,orange,turkey_navel,142,7.6,7.8,0.75
37 | 3,orange,turkey_navel,150,7.1,7.9,0.75
38 | 3,orange,turkey_navel,160,7.1,7.6,0.76
39 | 3,orange,turkey_navel,154,7.3,7.3,0.79
40 | 3,orange,turkey_navel,158,7.2,7.8,0.77
41 | 3,orange,turkey_navel,144,6.8,7.4,0.75
42 | 3,orange,turkey_navel,154,7.1,7.5,0.78
43 | 3,orange,turkey_navel,180,7.6,8.2,0.79
44 | 3,orange,turkey_navel,154,7.2,7.2,0.82
45 | 4,lemon,spanish_belsan,194,7.2,10.3,0.7
46 | 4,lemon,spanish_belsan,200,7.3,10.5,0.72
47 | 4,lemon,spanish_belsan,186,7.2,9.2,0.72
48 | 4,lemon,spanish_belsan,216,7.3,10.2,0.71
49 | 4,lemon,spanish_belsan,196,7.3,9.7,0.72
50 | 4,lemon,spanish_belsan,174,7.3,10.1,0.72
51 | 4,lemon,unknown,132,5.8,8.7,0.73
52 | 4,lemon,unknown,130,6,8.2,0.71
53 | 4,lemon,unknown,116,6,7.5,0.72
54 | 4,lemon,unknown,118,5.9,8,0.72
55 | 4,lemon,unknown,120,6,8.4,0.74
56 | 4,lemon,unknown,116,6.1,8.5,0.71
57 | 4,lemon,unknown,116,6.3,7.7,0.72
58 | 4,lemon,unknown,116,5.9,8.1,0.73
59 | 4,lemon,unknown,152,6.5,8.5,0.72
60 | 4,lemon,unknown,118,6.1,8.1,0.7
--------------------------------------------------------------------------------
/worksheet_version_control/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 |
4 | # Round double to precise integer
5 | #
6 | # `int_round` works to create an integer corresponding to a number that is
7 | # tested up to a particular decimal point of precision. This is useful when
8 | # there is a need to compare a numeric value using hashes.
9 | #
10 | # @param x Double vector of length one.
11 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
12 | #
13 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
14 | #
15 | # @examples
16 | # # to get an integer up to two decimals of precision from 234.56789
17 | # int_round(234.56789, 2)
18 | #
19 | # to get an integer rounded to the hundred digit from 234.56789
20 | # int_round(234.56789, -2)
21 | int_round <- function(x, digits){
22 | x = x * 10^digits
23 | xint = as.integer(x)
24 | xint1 = xint + 1L
25 | if (abs(xint - x) < abs(xint1 - x)){
26 | return(xint)
27 | }
28 | else {
29 | return(xint1)
30 | }
31 | }
32 |
33 | test_1.1 <- function(){
34 | test_that('Solution is incorrect.', {
35 | expect_equal(digest(answer1.1), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test
36 | })
37 | print("Success!")
38 | }
39 |
40 | test_1.2 <- function(){
41 | test_that('Solution is incorrect. Git is a tool for version control that is used locally on your computer.', {
42 | expect_equal(digest(answer1.2), 'd2a90307aac5ae8d0ef58e2fe730d38b') # we hid the answer to the test here so you can't see it, but we can still run the test
43 | })
44 | print("Success! Git is a tool for version control that is used locally on your computer, whereas GitHub is an example of a remote/cloud repository hosting service where you can backup and share your files with collaborators.")
45 | }
46 |
47 | test_2.1 <- function(){
48 | test_that('Solution is incorrect.', {
49 | expect_equal(digest(answer2.1), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test
50 | })
51 | print("Success!")
52 | }
53 |
54 | test_3.1 <- function(){
55 | test_that('Solution is incorrect. Technically, you can write any kind of message you want, but they are only useful if they describe what the change to the file(s) was about!', {
56 | expect_equal(digest(answer3.1), 'd2a90307aac5ae8d0ef58e2fe730d38b') # we hid the answer to the test here so you can't see it, but we can still run the test
57 | })
58 | print("Success! Yes commit messages are required, and yes what is in the message is important! The most useful messages describe what the change to the file(s) was about so that you can easily and effectively review the project's history!")
59 | }
60 |
61 | test_4.1 <- function(){
62 | test_that('Solution is incorrect.', {
63 | expect_equal(digest(answer4.1), '05ca18b596514af73f6880309a21b5dd') # we hid the answer to the test here so you can't see it, but we can still run the test
64 | })
65 | print("Success!")
66 | }
67 |
68 | test_6.1 <- function(){
69 | test_that('Solution is incorrect.', {
70 | expect_equal(digest(answer6.1), '01a75cb73d67b0f895ff0e61449c7bf8') # we hid the answer to the test here so you can't see it, but we can still run the test
71 | })
72 | print("Success!")
73 | }
74 |
75 | test_7.1 <- function(){
76 | test_that('Solution is incorrect. Committing your changes only puts them in the Git history on the local computer you are working on (i.e., your workspace on the JupyterHub or your laptop). To get the changes on GitHub you need to do an additional step of pushing the changes to the remote repository on GitHub.', {
77 | expect_equal(digest(answer7.1), 'd2a90307aac5ae8d0ef58e2fe730d38b') # we hid the answer to the test here so you can't see it, but we can still run the test
78 | })
79 | print("Success! You're right! The changes (and all the associated information) are not yet on GitHub, they are only in the Git history on the local computer you are working on (i.e., your workspace on the JupyterHub or your laptop).")
80 | }
81 |
82 | test_8.1 <- function(){
83 | test_that('Solution is incorrect.', {
84 | expect_equal(digest(answer8.1), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test
85 | })
86 | print("Success!")
87 | }
88 |
89 | test_9.1 <- function(){
90 | test_that('Solution is incorrect. Public repositories are viewable by anyone, but not editable by everyone.', {
91 | expect_equal(digest(answer9.1), '05ca18b596514af73f6880309a21b5dd') # we hid the answer to the test here so you can't see it, but we can still run the test
92 | })
93 | print("Success! Nice work! You can share your work publicly on GitHub while still retaining control over who can edit the shared work.")
94 | }
95 |
96 | test_10.1 <- function(){
97 | test_that('Solution is incorrect.', {
98 | expect_equal(digest(answer10.1), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test
99 | })
100 | print("Success!")
101 | }
102 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Jupyter notebook worksheets to accompany [*Data Science: A First Introduction*](https://datasciencebook.ca) by
2 | Tiffany Timbers, Trevor Campbell and Melissa Lee. To use these worksheets, you can either:
3 |
4 | 1. Click on a "launch binder" button to open an interactive, but non-persistent, version of the notebook.
5 |
6 | 2. Download this repository by clicking [here](https://github.com/UBC-DSCI/data-science-a-first-intro-worksheets/archive/refs/heads/main.zip) and follow our computer setup instructions [here](https://datasciencebook.ca/setup.html). The setup instructions should be followed to guarantee that your software environment is compatible with the worksheets.
7 |
8 | Regardless of the method you choose to access them, we also recommend reading our [Combining code and text with Jupyter chapter](https://datasciencebook.ca/jupyter.html) before starting out.
9 |
10 | | Book chapter | View worksheet on GitHub | Launch worksheet on myBinder.org |
11 | |--------------|-----------|----|
12 | | [R and the tidyverse](https://datasciencebook.ca/intro.html) | [view worksheet](worksheet_intro/worksheet_intro.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_intro%2Fworksheet_intro.ipynb) |
13 | | [Reading in data locally and from the web](https://datasciencebook.ca/reading.html) | [view worksheet](worksheet_reading/worksheet_reading.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_reading%2Fworksheet_reading.ipynb) |
14 | | [Cleaning and wrangling data](https://datasciencebook.ca/wrangling.html) | [view worksheet](worksheet_wrangling/worksheet_wrangling.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_wrangling%2Fworksheet_wrangling.ipynb) |
15 | | [Effective data visualization](https://datasciencebook.ca/viz.html) | [view worksheet](worksheet_viz/worksheet_viz.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_viz%2Fworksheet_viz.ipynb) |
16 | | [Classification I: training & predicting](https://datasciencebook.ca/classification1.html) | [view worksheet](worksheet_classification1/worksheet_classification1.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_classification1%2Fworksheet_classification1.ipynb)|
17 | | [Classification II: evaluation & tuning](https://datasciencebook.ca/classification2.html) | [view worksheet](worksheet_classification2/worksheet_classification2.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_classification2%2Fworksheet_classification2.ipynb) |
18 | | [Regression I: K-nearest neighbors](https://datasciencebook.ca/regression1.html) | [view worksheet](worksheet_regression1/worksheet_regression1.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_regression1%2Fworksheet_regression1.ipynb) |
19 | | [Regression II: linear regression](https://datasciencebook.ca/regression2.html) | [view worksheet](worksheet_regression2/worksheet_regression2.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_regression2%2Fworksheet_regression2.ipynb) |
20 | | [Clustering](https://datasciencebook.ca/clustering.html) | [view worksheet](worksheet_clustering/worksheet_clustering.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_clustering%2Fworksheet_clustering.ipynb) |
21 | | [Statistical inference (sampling)](https://datasciencebook.ca/inference.html) | [view worksheet](worksheet_inference1/worksheet_inference1.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_inference1%2Fworksheet_inference1.ipynb) |
22 | | [Statistical inference (bootstrapping)](https://datasciencebook.ca/inference.html) | [view worksheet](worksheet_inference2/worksheet_inference2.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_inference2%2Fworksheet_inference2.ipynb) |
23 | | [Collaboration with version control](https://datasciencebook.ca/version-control.html) | [view worksheet](worksheet_version_control/worksheet_version_control.ipynb) | [](https://mybinder.org/v2/gh/UBC-DSCI/data-science-a-first-intro-worksheets/HEAD?labpath=worksheet_version_control%2Fworksheet_version_control.ipynb) |
24 |
25 | ### Licence
26 | [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
27 |
28 | ### Acknowledgments
29 | We would like to thank the [BinderHub Federation](https://mybinder.readthedocs.io/en/latest/about/federation.html#the-binderhub-federation) for their kind and generous support of [mybinder.org](https://mybinder.org/). The interactive versions of these notebooks would not be possible without their efforts.
30 |
31 | ### References
32 | Jupyter et al., "Binder 2.0 - Reproducible, Interactive, Sharable
33 | Environments for Science at Scale." Proceedings of the 17th Python
34 | in Science Conference. 2018. doi://10.25080/Majora-4af1f417-011
35 |
--------------------------------------------------------------------------------
/worksheet_wrangling/data/departure_bay_temperature.csv:
--------------------------------------------------------------------------------
1 | Sea Surface Temperatures,,,,,,,,,,,,
2 | Departure Bay 49.2064 123.9624,,,,,,,,,,,,
3 | Year,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
4 | 1914,7.2,NA,NA,NA,NA,NA,NA,NA,11.1,10,7.3,6.3
5 | 1915,5.6,6.6,7.5,9,9.9,12.5,14.7,15.8,14,8.2,4.4,4.1
6 | 1916,1.2,0.1,3.5,6.5,8,12,13.1,14,11.4,7.6,5.4,3.5
7 | 1917,3.8,2.8,4.4,5.4,8.3,11,13.7,12.2,10,8.6,7,4.9
8 | 1918,3.7,3.9,4.6,6,9.3,11.2,13.1,14.5,13.8,9.1,6.7,5
9 | 1919,4.4,2.5,5,7.2,10,12.2,15.3,14.5,12.1,9.2,6.1,4.1
10 | 1920,3.9,3.8,6.1,6.9,10.2,11.9,14.7,14.5,11.3,8,7.5,5.4
11 | 1921,3.8,1.1,6,7.8,9.4,12.4,14,13.2,10.2,8,4.4,0.4
12 | 1922,4.1,3.8,5.8,6.5,7.5,13.3,14.9,12,10.3,7.7,6.2,5
13 | 1923,0.1,2.7,4.1,7.8,10.5,12.5,15.8,16.8,13.1,10,7.8,5
14 | 1924,0.4,6,7,8,9.4,14.5,14,14,12.5,7,6,4.1
15 | 1925,2,4.1,6.3,7.5,11,14,16.1,11.4,13.1,9.4,7,7.5
16 | 1926,6,7.5,8,8.9,9.8,13.2,14,14.2,12.2,9.7,8.6,4.4
17 | 1927,4.1,5,6,6.8,8.4,13.5,14.5,14.5,12,9.4,5.9,3.8
18 | 1928,4.3,5,5.9,7.9,9.1,14,16.1,16.4,9.8,10,8,6.5
19 | 1929,4.9,5.8,6.2,7,NA,11,15,13.1,13.1,10,8,7
20 | 1930,4.1,4.1,5,8,10.5,12,14.2,15,11.4,8.5,5,5
21 | 1931,5.4,5.4,6.5,8.6,12.7,14,14.7,16.6,11,7.8,6.3,5.4
22 | 1932,2.2,4.4,4.8,7.4,10.3,13.8,14,16.4,NA,NA,NA,NA
23 | 1933,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
24 | 1934,NA,NA,NA,NA,NA,15.5,14.5,14.3,11.3,9.4,8.6,5.4
25 | 1935,4.7,5.1,6.2,8.1,9.4,14,14.6,16.6,11.2,8.6,7.2,6.7
26 | 1936,6.2,4.2,6.1,6.4,9.8,12.3,14.1,16.1,13.5,10.5,8.2,5.4
27 | 1937,4.4,5.4,6.2,7.2,8,12.7,17,13.6,12.8,10.6,5.7,5.3
28 | 1938,4.9,5.5,7.2,8.3,10,12.3,14.9,13.9,12.9,9.7,7.2,5.9
29 | 1939,6.7,3.3,5.6,7.8,11,12.9,13.9,13.3,13.3,8,4.9,6.4
30 | 1940,5.4,6.1,7.2,9.4,11,13.6,15.5,14.8,13.8,10.6,6.9,6.7
31 | 1941,5.8,6.8,7.5,9.1,10.8,13.6,15.1,14.8,13.2,10.6,8.5,6.2
32 | 1942,5.7,6.6,7.5,9.4,10.5,12.5,15.8,16.1,13,10.4,6.9,5.8
33 | 1943,4.9,4.9,6.4,7.9,9.7,12,14.2,14,11.4,9.7,8.9,6.7
34 | 1944,6.2,6.5,6.9,7.9,10.5,13.5,14,15.7,8.4,10.7,8,6.6
35 | 1945,6.4,6.1,6.5,7.5,10,14.4,15.5,15.9,12.6,9.4,7,6
36 | 1946,5.6,5.9,6.6,7.8,10.2,13.1,13.7,12.4,12.1,9,7,5.1
37 | 1947,4.4,4.6,6,7.5,9.4,13.6,14.2,14,10.4,9.6,7.1,6.3
38 | 1948,5.5,5,6.4,6.5,9.3,14.7,13.9,14.3,9.9,9.7,6.9,4.7
39 | 1949,3.7,4.8,6.3,7.3,8.5,11.7,13.6,12.4,11.7,9.5,8.6,4.2
40 | 1950,-0.6,-0.1,5.3,6.6,8.4,11.1,16.4,12.3,10.3,8.2,6.2,5.9
41 | 1951,3.1,3.3,3.4,7.7,10.1,13.4,12.7,14.3,11.6,9.2,6.7,5
42 | 1952,3.4,4.2,5.7,6.6,7.8,11.1,13.5,12.7,10.2,9.8,7.2,5.3
43 | 1953,4.8,6.1,5.8,7.3,9.6,10,13.4,11.7,10.6,10.3,7.9,5.9
44 | 1954,4.2,4.2,6,5.7,8.8,10.9,13.3,13.5,12.9,9.8,7.8,5.7
45 | 1955,5.6,5.2,5.5,7.1,9.7,12.2,14,15.2,10.8,8.6,4.8,3
46 | 1956,4.3,3.7,4.8,7.1,10.8,9.9,15,14.8,9.8,7.3,6.1,5.4
47 | 1957,3.7,4.2,5.9,7.4,10.9,12.4,11.9,14.9,13.7,10,7.2,6.1
48 | 1958,6.2,6.5,6.9,7.4,11,15.7,17.6,12.9,10.9,10.1,6.8,5.9
49 | 1959,2.8,4.9,6.5,8,9.3,11.9,13.2,14.2,10.4,10.1,7.4,6.1
50 | 1960,5.3,4.9,5.3,7.5,10.1,12.1,14.4,12.4,10.7,9.3,6.8,6.1
51 | 1961,5.5,5.7,4.8,7.8,9.1,12.8,14.4,13,11.2,8.5,7.3,4.2
52 | 1962,4.2,5.4,4.4,7.6,8.6,12.1,13.6,13.3,11.1,9.9,6.6,6.1
53 | 1963,4.2,4.4,6.8,7.6,9.5,13.1,13.5,14,12,9.1,6.9,6.1
54 | 1964,5.2,5.8,5.6,7.4,8.8,11.4,13.1,13.6,11.5,10.3,6.9,3.9
55 | 1965,4.4,4.3,6.1,7.1,8.6,13.3,15.1,15.2,13.4,10,7.6,4.7
56 | 1966,4.9,5.6,5.4,NA,NA,11.8,13.2,12.9,11.2,9.5,7.7,5.8
57 | 1967,5.4,5.4,6.6,7.6,9.8,14.5,16.5,17,11.7,10,8.1,5.5
58 | 1968,5.3,4.4,6.9,7.6,9.9,10.4,13.3,12.8,11.3,8.9,7.5,1.9
59 | 1969,3.3,4.1,4.9,5.9,9.4,14.6,14.7,11.2,11.1,9.8,6.8,6.9
60 | 1970,5.6,6.6,7.2,8,9.4,12.2,13.3,14.7,11.2,7.6,4.6,1.9
61 | 1971,0.9,1.1,0,7.2,8.6,11.1,11.7,13.4,12.2,5.8,7.2,4.4
62 | 1972,4.4,4.7,4.4,6.1,8.4,13.1,11.4,16.4,9.7,8.8,7.2,5.3
63 | 1973,4.7,2.2,6.1,7,8.9,11.7,13.6,14.4,11.4,9.2,5.8,4.4
64 | 1974,3.3,5,5.3,6.7,10,11.1,12.8,11.8,13.9,10,6.1,5.6
65 | 1975,2.9,2.9,5.6,6.8,9.4,10.7,16.1,13.1,14,8,6,4
66 | 1976,5,3,4.2,7,8.6,9.3,14,13.7,13,10,7,6
67 | 1977,5.5,7,6,8,9.5,12,14.5,12.5,12,9,6.5,4.1
68 | 1978,3,4.9,7,8.7,10.1,12.4,14.8,13.4,11.3,10.2,7.8,6
69 | 1979,5.9,4.8,5.9,8.2,11,14,12,14.5,12,9.2,7.2,6.5
70 | 1980,4,5,6.7,8,10.6,12.6,13.2,14,12.4,10,7.5,5.6
71 | 1981,6.1,5,8.5,9,NA,12,15,13.4,11.2,10.5,8,6.1
72 | 1982,4.6,5.3,6.7,7,9,12.6,14.9,14.6,12,9.5,7.3,6.5
73 | 1983,6.7,6.5,7.7,NA,NA,NA,NA,NA,NA,NA,NA,NA
74 | 1984,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
75 | 1985,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
76 | 1986,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA
77 | 1987,5.3,6,5.5,8.6,9.4,10.5,13.5,15.5,11.8,10.4,7.6,6.3
78 | 1988,6.3,6,7,7,8.7,10.7,13.6,11.5,11.4,10.5,7.4,5.6
79 | 1989,5.2,0.7,5.5,7.7,11,12.7,13.5,15.4,14.2,9.5,8.2,6.7
80 | 1990,6,4.3,6.5,9.2,11.2,12.3,15.6,14.8,14.2,9.3,7.3,2.6
81 | 1991,3,6.2,6.1,7.7,9.8,11.3,13.4,11.5,13.2,9.9,7.3,6.4
82 | 1992,5.2,6.2,8.2,8.8,11.2,14.3,13.6,13.7,11.8,10.3,7.4,4.6
83 | 1993,5.7,6.3,6.9,8.4,9.5,12.5,12.5,13.2,14.7,10.6,7.8,6.6
84 | 1994,6.2,5.5,7.3,8.2,10.9,11.9,15.3,14.6,12.2,10,7.2,4.7
85 | 1995,4.5,5.2,6.3,8,10.7,11,15.3,13.1,11.3,9.5,7.3,4.2
86 | 1996,0.5,2.5,5.9,7.5,9.6,12.5,14.9,14.5,11.5,8.2,6,2
87 | 1997,4.2,4.9,6.1,7.7,9.3,11.8,12.9,12.4,11.7,10.4,7.1,6
88 | 1998,4.3,6.4,6.8,8.3,10.4,13.5,12.8,16.9,14.8,10.1,7.8,2
89 | 1999,4.9,5.5,5.7,6.5,9.2,12.2,13,14.9,11.5,9.3,7.3,5.8
90 | 2000,5.4,5.7,6.3,8.7,9.4,11.5,13.2,11.4,12.1,9.1,7.2,5.7
91 | 2001,5.5,4.9,6.4,8,9.4,12.4,15.4,11.7,11.7,9,7.8,5.2
92 | 2002,4.8,5.3,5.1,7.2,9.4,11.4,14.5,14.8,13.7,10.2,8.1,6.1
93 | 2003,5.7,6.7,6.4,7.7,10.6,11.7,12.3,16.4,13.1,10.2,6.6,6.3
94 | 2004,4.5,6.1,7.1,9.1,12,13.4,15.8,13.7,13.1,10.2,8,6.5
95 | 2005,5.2,6,6.9,7.8,10.5,14,13.1,13.9,10.9,9.7,7.8,6.2
96 | 2006,7,5.8,6.7,8.2,9.4,12.4,13.5,15.2,13.9,9.9,6.2,5.9
97 | 2007,6,6.2,7.3,7.3,10,13.4,13.1,15.3,12.6,9.8,7.6,6.5
98 | 2008,5.1,5.8,6.7,6.3,9.7,NA,12.9,12.5,12.1,9.9,8.1,5.9
99 | 2009,4.5,5.1,5.2,6.7,9.3,13.3,13,12.8,11.4,9.2,7.9,5.3
100 | 2010,5.5,6.8,7.1,7.3,9.7,9.9,14.3,15.9,12.2,9.3,6.7,4.5
101 | 2011,4.5,4.8,5.2,7.1,8.5,13.1,13.9,15.4,10.1,9.1,6.7,5.8
102 | 2012,4.5,4.8,5.2,6.5,9.6,11.1,14.2,13.8,12.5,8.8,5.9,6
103 | 2013,4.7,6.2,6.2,8.1,10.3,12.8,17,14,11,9.5,7.6,5.5
104 | 2014,4.4,3.1,3.7,7.7,10.1,12,15.9,16.8,11.7,10.6,7.1,7.1
105 | 2015,6.3,8,8,8.9,11,15.5,13.8,13.4,11.6,11.3,8.1,6.8
106 | 2016,6,7.1,8.4,9.8,13,14.2,14.6,14.6,12.6,10.8,8.2,5.5
107 | 2017,5.6,4.8,7.1,7.9,10.5,12.4,15.3,15.3,13.1,10.2,8.8,6.9
108 | 2018,6.2,6,7.1,8.2,NA,NA,NA,NA,NA,NA,NA,NA
--------------------------------------------------------------------------------
/worksheet_intro/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 |
4 | # Round double to precise integer
5 | #
6 | # `int_round` works to create an integer corresponding to a number that is
7 | # tested up to a particular decimal point of precision. This is useful when
8 | # there is a need to compare a numeric value using hashes.
9 | #
10 | # @param x Double vector of length one.
11 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
12 | #
13 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
14 | #
15 | # @examples
16 | # # to get an integer up to two decimals of precision from 234.56789
17 | # int_round(234.56789, 2)
18 | #
19 | # to get an integer rounded to the hundred digit from 234.56789
20 | # int_round(234.56789, -2)
21 | int_round <- function(x, digits){
22 | x = x * 10^digits
23 | xint = as.integer(x)
24 | xint1 = xint + 1L
25 | if (abs(xint - x) < abs(xint1 - x)){
26 | return(xint)
27 | }
28 | else {
29 | return(xint1)
30 | }
31 | }
32 |
33 | test_that('int_round gives expected types', {
34 | expect_equal(typeof(int_round(234.56789, 2)), "integer")
35 | expect_equal(typeof(int_round(234.56789, -2)), "integer")
36 | expect_equal(typeof(int_round(234L, 2)), "integer")
37 | })
38 |
39 | test_that('int_round gives expected values', {
40 | expect_equal(int_round(234.56789, 2), 23457)
41 | expect_equal(int_round(234.56789, -2), 2)
42 | expect_equal(int_round(234L, 2), 23400)
43 | })
44 | # -
45 |
46 | test_3.2 <- function(){
47 | test_that('seconds_in_a_minute should exist and have the value of how many seconds are in a minute.', {
48 | expect_equal(digest(int_round(seconds_in_a_minute, 2)), 'fd54bb9b93cc9d4df5d0e1b0ef6d2588') # we hid the answer to the test here so you can't see it, but we can still run the test
49 | })
50 | test_that('seconds_in_a_hour should exist and have the value of how many seconds are in a hour.', {
51 | expect_equal(digest(int_round(seconds_in_an_hour, 2)), '20dbbc2a608b1e18079e3a446a9cfb38') # we hid the answer to the test here so you can't see it, but we can still run the test
52 | })
53 | print("Success!")
54 | }
55 |
56 | test_4.0 <- function(){
57 | test_that('Solution is incorrect', {
58 | expect_equal(digest(title), 'c76933115bc8095b2140c11556800725') # we hid the answer to the test here so you can't see it, but we can still run the test
59 | })
60 | print("Success!")
61 | }
62 |
63 | test_4.1 <- function(){
64 | test_that('Solution is incorrect', {
65 | expect_equal(digest(smallest), 'db8e490a925a60e62212cefc7674ca02') # we hid the answer to the test here so you can't see it, but we can still run the test
66 | })
67 | print("Success!")
68 | }
69 |
70 | test_5.1 <- function(){
71 | test_that('Solution is incorrect, the rvest package needs to be loaded', {
72 | expect_true("package:rvest" %in% search())
73 | })
74 | print("Success!")
75 | }
76 |
77 | test_6.1 <- function(){
78 | test_that('Solution is incorrect', {
79 | expect_equal(digest(answer6.1), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test
80 | })
81 | print("Success!")
82 | }
83 |
84 | test_7.0.1 <- function(){
85 | test_that('Solution is incorrect', {
86 | expect_equal(digest(answer7.0.1), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test
87 | })
88 | print("Success!")
89 | }
90 |
91 | test_7.0.2 <- function(){
92 | test_that('Solution is incorrect', {
93 | expect_equal(digest(answer7.0.2), '05ca18b596514af73f6880309a21b5dd') # we hid the answer to the test here so you can't see it, but we can still run the test
94 | })
95 | print("Success!")
96 | }
97 |
98 | test_7.0.3 <- function(){
99 | test_that('Solution is incorrect', {
100 | expect_equal(digest(answer7.0.3), '475bf9280aab63a82af60791302736f6') # we hid the answer to the test here so you can't see it, but we can still run the test
101 | })
102 | print("Success!")
103 | }
104 |
105 | test_7.1.1 <- function(){
106 | test_that('Did not create an object named marathon_small', {
107 | expect_true(exists("marathon_small"))
108 | })
109 | test_that('marathon_small should be a data frame', {
110 | expect_true('data.frame' %in% class(marathon_small))
111 | })
112 | test_that('marathon_small does not contain the correct data', {
113 | expect_equal(dim(marathon_small), c(1833, 5))
114 | expect_equal(digest(int_round(sum(marathon_small$age), 2)), 'b0c43657ea54a87600e9a39a810e7d79')
115 | expect_equal(colnames(marathon_small), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))
116 | })
117 | print("Success!")
118 | }
119 |
120 | test_7.1.2 <- function(){
121 | test_that('Solution is incorrect', {
122 | expect_equal(digest(answer7.1.2), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test
123 | })
124 | print("Success!")
125 | }
126 |
127 | test_7.2.1 <- function(){
128 | test_that('Solution is incorrect.', {
129 | expect_equal(digest(number_rows), '58fac55045cec17cd9f4006f4b5ab349') # we hid the answer to the test here so you can't see it, but we can still run the test
130 | })
131 | print("Success!")
132 | }
133 |
134 | test_7.3.1 <- function(){
135 | test_that('marathon_filtered has the incorrect number of rows', {
136 | expect_equal(digest(int_round(nrow(marathon_filtered), 0)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
137 | })
138 | test_that('marathon_filtered has the incorrect number of column', {
139 | expect_equal(digest(int_round(ncol(marathon_filtered), 0)), 'dd4ad37ee474732a009111e3456e7ed7') # we hid the answer to the test here so you can't see it, but we can still run the test
140 | })
141 | test_that('marathon_filtered bmi column contains the incorrect values', {
142 | expect_equal(colnames(marathon_filtered), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))
143 | expect_equal(digest(int_round(sum(marathon_filtered$bmi), 2)), '875f8815cddc21b22a1b1eb1d5ed6ab6') # we hid the answer to the test here so you can't see it, but we can still run the test
144 | })
145 | print("Success!")
146 | }
147 |
148 | test_7.4.1 <- function(){
149 | test_that('marathon_male has the incorrect number of rows', {
150 | expect_equal(digest(int_round(nrow(marathon_male), 0)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
151 | })
152 | test_that('marathon_male has the incorrect number of columns', {
153 | expect_equal(digest(int_round(ncol(marathon_male), 0)), 'c01f179e4b57ab8bd9de309e6d576c48') # we hid the answer to the test here so you can't see it, but we can still run the test
154 | })
155 | test_that('marathon_male bmi and/or km10_time_seconds column(s) contains the incorrect values', {
156 | expect_equal(digest(int_round(sum(marathon_male$bmi), 2)), '875f8815cddc21b22a1b1eb1d5ed6ab6') # we hid the answer to the test here so you can't see it, but we can still run the test
157 | expect_equal(digest(int_round(sum(marathon_male$km10_time_seconds, na.rm = TRUE), 2)), 'c35b7f74b3421852308c5f7722b30667') # we hid the answer to the test here so you can't see it, but we can still run the test
158 | })
159 | print("Success!")
160 | }
161 |
162 | test_7.4.2 <- function(){
163 | test_that('Solution is incorrect', {
164 | expect_match(digest(answer7.4.2), "a9cf135185e7fe4ae642c8dcb228cd2d")
165 | })
166 | print("Success!")
167 | }
168 |
169 | test_7.4.3 <- function(){
170 | test_that('Solution is incorrect', {
171 | expect_match(digest(answer7.4.3), "edf7faf67d063030eba4ec85c6f7cc55")
172 | })
173 | print("Success!")
174 | }
175 |
176 | test_7.5.1 <- function(){
177 | test_that('marathon_minutes has the incorrect number of rows', {
178 | expect_equal(digest(int_round(nrow(marathon_minutes), 0)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
179 | })
180 | test_that('marathon_minutes has the incorrect number of columns', {
181 | expect_equal(digest(int_round(ncol(marathon_minutes), 0)), '11946e7a3ed5e1776e81c0f0ecd383d0') # we hid the answer to the test here so you can't see it, but we can still run the test
182 | })
183 | test_that('km10_time_minutes column does not exist contains incorrect values', {
184 | expect_equal(digest(int_round(sum(marathon_minutes$km10_time_minutes, na.rm = TRUE), 2)), 'df88470bb77695f5d6bccdc54dd5c6bb') # we hid the answer to the test here so you can't see it, but we can still run the test
185 | })
186 | print("Success!")
187 | }
188 |
189 | test_7.6.1 <- function(){
190 | test_that('Solution is incorrect', {
191 | expect_match(digest(answer7.6.1), '3a5505c06543876fe45598b5e5e5195d')
192 | })
193 | print("Success!")
194 | }
195 |
--------------------------------------------------------------------------------
/worksheet_inference2/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 |
4 | # Round double to precise integer
5 | #
6 | # `int_round` works to create an integer corresponding to a number that is
7 | # tested up to a particular decimal point of precision. This is useful when
8 | # there is a need to compare a numeric value using hashes.
9 | #
10 | # @param x Double vector of length one.
11 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
12 | #
13 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
14 | #
15 | # @examples
16 | # # to get an integer up to two decimals of precision from 234.56789
17 | # int_round(234.56789, 2)
18 | #
19 | # to get an integer rounded to the hundred digit from 234.56789
20 | # int_round(234.56789, -2)
21 | int_round <- function(x, digits){
22 | x = x * 10^digits
23 | xint = as.integer(x)
24 | xint1 = xint + 1L
25 | if (abs(xint - x) < abs(xint1 - x)){
26 | return(xint)
27 | }
28 | else {
29 | return(xint1)
30 | }
31 | }
32 |
33 | test_1.1 <- function(){
34 | test_that("Answer is incorrect", {
35 | expect_equal(digest(answer1.1), 'd2a90307aac5ae8d0ef58e2fe730d38b')
36 | })
37 | print("Success!")
38 | }
39 |
40 | test_1.2 <- function(){
41 | test_that("Answer is incorrect", {
42 | expect_equal(digest(paste(answer1.2, collapse="")), 'd04127a9755e9ea38971707b06bd7127')
43 | })
44 | print("Success!")
45 | }
46 |
47 | test_1.3 <- function(){
48 | test_that("Answer is incorrect", {
49 | expect_equal(digest(answer1.3), '475bf9280aab63a82af60791302736f6')
50 | })
51 | print("Success!")
52 | }
53 |
54 | test_1.4 <- function(){
55 | test_that("Answer is incorrect", {
56 | expect_equal(digest(answer1.4), 'c1f86f7430df7ddb256980ea6a3b57a4')
57 | })
58 | print("Success!")
59 | }
60 |
61 | test_1.5 <- function(){
62 | test_that('one_sample_estimates should have one column named mean, and one row.', {
63 | expect_equal(int_round(nrow(one_sample_estimates), 0), 1)
64 | expect_equal(int_round(ncol(one_sample_estimates), 0), 1)
65 | expect_equal(digest(paste(sort(colnames(one_sample_estimates)), collapse = "")), '01e0708f75fc4f568f278b875b2e0740')
66 | expect_equal(digest(int_round(one_sample_estimates$mean[1], 2)), 'c054e6da6a916431a27931c4e3a1efe5')
67 | })
68 | print("Success!")
69 | }
70 |
71 | test_1.6 <- function(){
72 | test_that("boot1 should have 2 columns, named replicate and age", {
73 | expect_equal(digest(paste(sort(colnames(boot1)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
74 | })
75 | test_that("boot1 have 40 rows (the same number of observations as one_sample)", {
76 | expect_equal(int_round(nrow(boot1), 0), 40)
77 | })
78 | test_that("boot1 does not have the correct values in the age column", {
79 | expect_equal(digest(int_round(sum(boot1$age), 2)), '112ddeb87a12f6976a1d15f6612eda87')
80 | })
81 | test_that("size and reps do not contain the correct values", {
82 | expect_equal(digest(int_round(sum(as.integer(unlist(attr(boot1, "groups")))), 2)), '67a199c96b75217a12f8fa73c51e93fc')
83 | })
84 | print("Success!")
85 | }
86 |
87 | test_1.7 <- function() {
88 | test_that("Answer is incorrect", {
89 | expect_equal(digest(answer1.7), 'c1f86f7430df7ddb256980ea6a3b57a4')
90 | })
91 | print("Success!")
92 | }
93 |
94 | test_1.8 <- function() {
95 | properties <- c(boot1_dist$layers[[1]]$mapping, boot1_dist$mapping)
96 | labels <- boot1_dist$labels
97 | test_that('age should be on the x-axis.', {
98 | expect_true("age" == rlang::get_expr(properties$x))
99 | })
100 | test_that('boot1_dist should be a histogram.', {
101 | expect_true("GeomBar" %in% class(boot1_dist$layers[[1]]$geom))
102 | })
103 | test_that('boot1 data should be used to create the histogram', {
104 | expect_equal(int_round(nrow(boot1_dist$data), 0), 40)
105 | expect_equal(digest(int_round(sum(boot1_dist$data), 2)), 'd3e914baed4511182de1e98d25219ac8')
106 | })
107 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
108 | expect_false((labels$x) == 'age')
109 | expect_false(is.null(labels$title))
110 | })
111 | print("Success!")
112 | }
113 |
114 | test_1.9 <- function(){
115 | test_that("boot6 should have 2 columns, named replicate and age", {
116 | expect_equal(digest(paste(sort(colnames(boot6)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
117 | })
118 | test_that("boot6 have 240 rows (six times the number of observations in one_sample)", {
119 | expect_equal(int_round(nrow(boot6), 0), 240)
120 | })
121 | test_that("boot6 does not have the correct values in the age column", {
122 | expect_equal(digest(int_round(sum(boot6$age), 2)), 'f3f7f979ba3e6a29874aac628c26ef4f')
123 | })
124 | test_that("size and reps do not contain the correct values", {
125 | expect_equal(digest(int_round(sum(as.integer(unlist(attr(boot6, "groups")))), 2)), 'c553d74ed95c022e74dce82e82d6e6dd')
126 | })
127 | print("Success!")
128 | }
129 |
130 | test_2.0 <- function(){
131 | properties <- c(boot6_dist$layers[[1]]$mapping, boot6_dist$mapping)
132 | labels <- boot6_dist$labels
133 | test_that('age should be on the x-axis.', {
134 | expect_true("age" == rlang::get_expr(properties$x))
135 | })
136 | test_that('boot6_dist should be a histogram.', {
137 | expect_true("GeomBar" %in% class(boot6_dist$layers[[1]]$geom))
138 | })
139 | test_that('boot6 data should be used to create the histogram', {
140 | expect_equal(int_round(nrow(boot6_dist$data), 0), 240)
141 | })
142 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
143 | expect_false((labels$x) == 'age')
144 | expect_false(is.null(labels$title))
145 | })
146 | test_that('boot6_dist should use facet_wrap.', {
147 | expect_true("FacetWrap" %in% class(boot6_dist$facet))
148 | })
149 | print("Success!")
150 | }
151 |
152 | test_2.1 <- function(){
153 | test_that('boot6_means should have 2 columns (named replicate & mean), and six rows.', {
154 | expect_equal(int_round(nrow(boot6_means), 0), 6)
155 | expect_equal(int_round(ncol(boot6_means), 0), 2)
156 | expect_equal(digest(paste(sort(colnames(boot6_means)), collapse = "")), '35d687b4f0369a9d4e0a6ef74556908e')
157 | expect_equal(digest(int_round(boot6_means$mean[1], 2)), '1940ea892300bba15c54ed5bdbda7cb9')
158 | })
159 | print("Success!")
160 | }
161 |
162 | test_2.2 <- function(){
163 | test_that("boot1000 should have 2 columns, named replicate and age", {
164 | expect_equal(digest(paste(sort(colnames(boot1000)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
165 | })
166 | test_that("boot1000 have 40000 rows (1000 times the number of observations in one_sample)", {
167 | expect_equal(int_round(nrow(boot1000), 0), 40000)
168 | })
169 | test_that("boot1000 does not have the correct values in the age column", {
170 | expect_equal(digest(int_round(sum(boot1000$age), 2)), '81452ed8488b320217742924137c2e99')
171 | })
172 | test_that("size and reps do not contain the correct values", {
173 | expect_equal(digest(int_round(sum(as.integer(unlist(attr(boot1000, "groups")))), 0)), 'c611e93a1a0b0bdeb5e0c5acf678ee5b')
174 | })
175 | print("Success!")
176 | }
177 |
178 | test_2.3 <- function(){
179 | test_that('boot1000_means should have 2 columns (named replicate & mean), and 1000 rows.', {
180 | expect_equal(int_round(nrow(boot1000_means), 0), 1000)
181 | expect_equal(int_round(ncol(boot1000_means), 0), 2)
182 | expect_equal(digest(paste(sort(colnames(boot1000_means)), collapse = "")), '35d687b4f0369a9d4e0a6ef74556908e')
183 | expect_equal(digest(int_round(boot1000_means$mean[1], 2)), '1940ea892300bba15c54ed5bdbda7cb9')
184 | })
185 | print("Success!")
186 | }
187 |
188 | test_2.4 <- function(){
189 | properties <- c(boot_est_dist$layers[[1]]$mapping, boot_est_dist$mapping)
190 | labels <- boot_est_dist$labels
191 | test_that('mean should be on the x-axis.', {
192 | expect_true("mean" == rlang::get_expr(properties$x))
193 | })
194 | test_that('boot_est_dist should be a histogram.', {
195 | expect_true("GeomBar" %in% class(boot_est_dist$layers[[1]]$geom))
196 | })
197 | test_that('boot1000_means data should be used to create the histogram', {
198 | expect_equal(int_round(nrow(boot_est_dist$data), 0), 1000)
199 | expect_equal(digest(int_round(sum(boot_est_dist$data), 2)), 'f84934414055b43f674c20306aaf69d9')
200 | })
201 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
202 | expect_false((labels$x) == 'age')
203 | expect_false(is.null(labels$title))
204 | })
205 | print("Success!")
206 | }
207 |
208 | test_2.5 <- function(){
209 | test_that("Answer is incorrect", {
210 | expect_equal(digest(answer2.5), 'd2a90307aac5ae8d0ef58e2fe730d38b')
211 | })
212 | print("Success!")
213 | }
214 |
215 | test_2.6 <- function(){
216 | test_that("Answer is incorrect", {
217 | expect_equal(digest(answer2.6), '05ca18b596514af73f6880309a21b5dd')
218 | })
219 | print("Success!")
220 | }
221 |
222 | test_2.7 <- function(){
223 | test_that("Answer is incorrect", {
224 | expect_equal(digest(answer2.7), 'd2a90307aac5ae8d0ef58e2fe730d38b')
225 | })
226 | print("Success!")
227 | }
228 |
229 | test_2.8 <- function(){
230 | test_that("Answer is incorrect", {
231 | expect_equal(digest(answer2.8), '05ca18b596514af73f6880309a21b5dd')
232 | })
233 | print("Success!")
234 | }
235 |
236 | test_2.9 <- function(){
237 | test_that("Answer is incorrect", {
238 | expect_equal(digest(answer2.9), 'd2a90307aac5ae8d0ef58e2fe730d38b')
239 | })
240 | print("Success!")
241 | }
242 |
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report_no_header.csv:
--------------------------------------------------------------------------------
1 | Norway,7.53700017929077,1.61646318435669,0.796666502952576,0.635422587394714
2 | Denmark,7.52199983596802,1.48238301277161,0.792565524578094,0.626006722450256
3 | Iceland,7.50400018692017,1.480633020401,0.833552122116089,0.627162635326385
4 | Switzerland,7.49399995803833,1.56497955322266,0.858131289482117,0.620070576667786
5 | Finland,7.4689998626709,1.44357192516327,0.80915766954422,0.617950856685638
6 | Netherlands,7.3769998550415,1.50394463539124,0.810696125030518,0.585384488105774
7 | Canada,7.31599998474121,1.47920441627502,0.83455765247345,0.611100912094116
8 | New Zealand,7.31400012969971,1.40570604801178,0.816759705543518,0.614062130451202
9 | Sweden,7.28399991989136,1.49438726902008,0.830875158309937,0.612924098968506
10 | Australia,7.28399991989136,1.484414935112,0.84388679265976,0.601607382297516
11 | Israel,7.21299982070923,1.37538242340088,0.83840399980545,0.405988603830338
12 | Costa Rica,7.0789999961853,1.10970628261566,0.759509265422821,0.580131649971008
13 | Austria,7.00600004196167,1.48709726333618,0.81532841920852706,0.567766189575195
14 | United States,6.99300003051758,1.54625928401947,0.77428662776947,0.505740523338318
15 | Ireland,6.97700023651123,1.53570663928986,0.80978262424469,0.573110342025757
16 | Germany,6.95100021362305,1.48792338371277,0.798950731754303,0.562511384487152
17 | Belgium,6.89099979400635,1.46378076076508,0.818091869354248,0.539770722389221
18 | Luxembourg,6.86299991607666,1.74194359779358,0.845089495182037,0.59662789106369
19 | United Kingdom,6.71400022506714,1.44163393974304,0.805335938930511,0.508190035820007
20 | Chile,6.65199995040894,1.25278460979462,0.819479703903198,0.376895278692245
21 | United Arab Emirates,6.64799976348877,1.62634336948395,0.726798236370087,0.60834527015686
22 | Brazil,6.63500022888184,1.10735321044922,0.616552352905273,0.437453746795654
23 | Czech Republic,6.60900020599365,1.35268235206604,0.754444003105164,0.490946173667908
24 | Argentina,6.59899997711182,1.18529546260834,0.695137083530426,0.494519203901291
25 | Mexico,6.57800006866455,1.15318381786346,0.709978997707367,0.412730008363724
26 | Singapore,6.57200002670288,1.69227766990662,0.949492394924164,0.549840569496155
27 | Malta,6.52699995040894,1.34327983856201,0.821944236755371,0.588767051696777
28 | Uruguay,6.4539999961853,1.21755969524384,0.719216823577881,0.57939225435257
29 | Guatemala,6.4539999961853,0.872001945972443,0.540239989757538,0.531310617923737
30 | Panama,6.4520001411438,1.23374843597412,0.706156134605408,0.550026834011078
31 | France,6.44199991226196,1.43092346191406,0.844465851783752,0.470222115516663
32 | Thailand,6.42399978637695,1.12786877155304,0.647239029407501,0.580200731754303
33 | Taiwan Province of China,6.42199993133545,1.43362653255463,0.793984234333038,0.361466586589813
34 | Spain,6.40299987792969,1.38439786434174,0.888960599899292,0.408781230449677
35 | Qatar,6.375,1.87076568603516,0.710098087787628,0.604130983352661
36 | Colombia,6.35699987411499,1.07062232494354,0.595027923583984,0.477487415075302
37 | Saudi Arabia,6.3439998626709,1.53062355518341,0.590148329734802,0.449750572443008
38 | Trinidad and Tobago,6.16800022125244,1.36135590076447,0.519983291625977,0.518630743026733
39 | Kuwait,6.10500001907349,1.63295245170593,0.632105708122253,0.496337592601776
40 | Slovakia,6.09800004959106,1.32539355754852,0.712732911109924,0.295817464590073
41 | Bahrain,6.08699989318848,1.48841226100922,0.653133034706116,0.536746919155121
42 | Malaysia,6.08400011062622,1.29121541976929,0.618784427642822,0.402264982461929
43 | Nicaragua,6.07100009918213,0.737299203872681,0.653095960617065,0.447551846504211
44 | Ecuador,6.00799989700317,1.00082039833069,0.685636222362518,0.4551981985569
45 | El Salvador,6.00299978256226,0.909784495830536,0.596018552780151,0.432452529668808
46 | Poland,5.97300004959106,1.29178786277771,0.699475347995758,0.520342111587524
47 | Uzbekistan,5.97100019454956,0.786441087722778,0.498272627592087,0.658248662948608
48 | Italy,5.96400022506714,1.39506661891937,0.853144347667694,0.256450712680817
49 | Russia,5.96299982070923,1.28177809715271,0.547349333763123,0.373783111572266
50 | Belize,5.95599985122681,0.907975316047668,0.450191766023636,0.547509372234344
51 | Japan,5.92000007629395,1.41691517829895,0.913475871086121,0.505625545978546
52 | Lithuania,5.90199995040894,1.31458234786987,0.62894994020462,0.234231784939766
53 | Algeria,5.87200021743774,1.09186446666718,0.617584645748138,0.233335807919502
54 | Latvia,5.84999990463257,1.26074862480164,0.638566970825195,0.325707912445068
55 | South Korea,5.83799982070923,1.40167844295502,0.900214076042175,0.257921665906906
56 | Moldova,5.83799982070923,0.728870630264282,0.589465200901031,0.240729048848152
57 | Romania,5.82499980926514,1.21768391132355,0.685158312320709,0.457003742456436
58 | Bolivia,5.82299995422363,0.833756566047668,0.473630249500275,0.558732926845551
59 | Turkmenistan,5.82200002670288,1.13077676296234,0.437726080417633,0.41827192902565
60 | Kazakhstan,5.81899976730347,1.28455626964569,0.606041550636292,0.437454283237457
61 | North Cyprus,5.80999994277954,1.3469113111496,0.834647238254547,0.471203625202179
62 | Slovenia,5.75799989700317,1.3412059545517,0.790828227996826,0.572575807571411
63 | Peru,5.71500015258789,1.03522527217865,0.630166113376617,0.450002878904343
64 | Mauritius,5.62900018692017,1.18939554691315,0.638007462024689,0.491247326135635
65 | Cyprus,5.62099981307983,1.35593807697296,0.84471470117569,0.355111539363861
66 | Estonia,5.61100006103516,1.32087934017181,0.695168316364288,0.479131430387497
67 | Belarus,5.56899976730347,1.15655755996704,0.637714266777039,0.295400261878967
68 | Libya,5.52500009536743,1.10180306434631,0.520169019699097,0.465733230113983
69 | Turkey,5.5,1.19827437400818,0.637605607509613,0.300740599632263
70 | Paraguay,5.49300003051758,0.932537317276001,0.579250693321228,0.473507791757584
71 | "Hong Kong S.A.R., China",5.47200012207031,1.55167484283447,0.943062424659729,0.490968644618988
72 | Philippines,5.42999982833862,0.85769921541214,0.468009054660797,0.585214674472809
73 | Serbia,5.39499998092651,1.06931757926941,0.65078467130661,0.208715528249741
74 | Jordan,5.33599996566772,0.991012394428253,0.604590058326721,0.418421149253845
75 | Hungary,5.32399988174438,1.2860119342804,0.687763452529907,0.175863519310951
76 | Jamaica,5.31099987030029,0.925579309463501,0.641022384166718,0.474307239055634
77 | Croatia,5.29300022125244,1.22255623340607,0.701288521289825,0.255772292613983
78 | Kosovo,5.27899980545044,0.951484382152557,0.541452050209045,0.260287940502167
79 | China,5.27299976348877,1.08116579055786,0.741415500640869,0.472787708044052
80 | Pakistan,5.26900005340576,0.72688353061676,0.402047783136368,0.23521526157856
81 | Indonesia,5.26200008392334,0.995538592338562,0.492345720529556,0.443323463201523
82 | Venezuela,5.25,1.12843120098114,0.617144227027893,0.153997123241425
83 | Montenegro,5.23699998855591,1.12112903594971,0.667464673519135,0.194989055395126
84 | Morocco,5.2350001335144,0.878114581108093,0.59771066904068,0.408158332109451
85 | Azerbaijan,5.23400020599365,1.15360176563263,0.540775775909424,0.398155838251114
86 | Dominican Republic,5.23000001907349,1.07937383651733,0.574873745441437,0.55258983373642
87 | Greece,5.22700023651123,1.28948748111725,0.810198903083801,0.0957312509417534
88 | Lebanon,5.22499990463257,1.07498753070831,0.73508107662200906,0.288515985012054
89 | Portugal,5.19500017166138,1.3151752948761,0.795843541622162,0.498465299606323
90 | Bosnia and Herzegovina,5.18200016021729,0.982409417629242,0.705186307430267,0.204403176903725
91 | Honduras,5.18100023269653,0.730573117733002,0.582569479942322,0.348079860210419
92 | Macedonia,5.17500019073486,1.06457793712616,0.644948184490204,0.325905978679657
93 | Somalia,5.15100002288818,0.0226431842893362,0.113989137113094,0.602126955986023
94 | Vietnam,5.07399988174438,0.788547575473785,0.652168989181519,0.571055591106415
95 | Nigeria,5.07399988174438,0.783756256103516,0.0569157302379608,0.394952565431595
96 | Tajikistan,5.04099988937378,0.524713635444641,0.529235124588013,0.471566706895828
97 | Bhutan,5.01100015640259,0.885416388511658,0.495879292488098,0.501537680625916
98 | Kyrgyzstan,5.00400018692017,0.596220076084137,0.553457796573639,0.454943388700485
99 | Nepal,4.96199989318848,0.479820191860199,0.504130780696869,0.440305948257446
100 | Mongolia,4.95499992370605,1.02723586559296,0.557783484458923,0.394143968820572
101 | South Africa,4.8289999961853,1.05469870567322,0.187080070376396,0.479246735572815
102 | Tunisia,4.80499982833862,1.00726580619812,0.613212049007416,0.289680689573288
103 | Palestinian Territories,4.77500009536743,0.716249227523804,0.565666973590851,0.25471106171608
104 | Egypt,4.7350001335144,0.989701807498932,0.520187258720398,0.282110154628754
105 | Bulgaria,4.71400022506714,1.1614590883255,0.708217680454254,0.289231717586517
106 | Sierra Leone,4.70900011062622,0.36842092871666,0.00556475389748812,0.318697690963745
107 | Cameroon,4.69500017166138,0.564305365085602,0.132892116904259,0.430388748645782
108 | Iran,4.69199991226196,1.15687310695648,0.639333188533783,0.249322608113289
109 | Albania,4.64400005340576,0.996192753314972,0.731159746646881,0.381498634815216
110 | Bangladesh,4.60799980163574,0.586682975292206,0.533241033554077,0.478356659412384
111 | Namibia,4.57399988174438,0.964434325695038,0.33861181139946,0.520303547382355
112 | Kenya,4.55299997329712,0.560479462146759,0.309988349676132,0.452763766050339
113 | Mozambique,4.55000019073486,0.234305649995804,0.106654435396194,0.480791091918945
114 | Myanmar,4.54500007629395,0.367110550403595,0.397522568702698,0.514492034912109
115 | Senegal,4.53499984741211,0.479309022426605,0.409362852573395,0.377922266721725
116 | Zambia,4.51399993896484,0.636406779289246,0.257835894823074,0.461603492498398
117 | Iraq,4.49700021743774,1.10271048545837,0.50118046998977706,0.288555532693863
118 | Gabon,4.46500015258789,1.1982102394104,0.356578588485718,0.312328577041626
119 | Ethiopia,4.46000003814697,0.339233845472336,0.353409707546234,0.408842742443085
120 | Sri Lanka,4.44000005722046,1.00985014438629,0.625130832195282,0.561213254928589
121 | Armenia,4.37599992752075,0.900596737861633,0.637524425983429,0.198303267359734
122 | India,4.31500005722046,0.792221248149872,0.455427616834641,0.469987004995346
123 | Mauritania,4.29199981689453,0.648457288742065,0.285349279642105,0.0960980430245399
124 | Congo (Brazzaville),4.29099988937378,0.808964252471924,0.28995743393898,0.435025870800018
125 | Georgia,4.28599977493286,0.950612664222717,0.649546980857849,0.309410035610199
126 | Congo (Kinshasa),4.28000020980835,0.0921023488044739,0.191407024860382,0.235961347818375
127 | Mali,4.19000005722046,0.476180493831635,0.169365674257278,0.306613743305206
128 | Ivory Coast,4.17999982833862,0.603048920631409,0.0486421696841717,0.447706192731857
129 | Cambodia,4.16800022125244,0.601765096187592,0.429783403873444,0.633375823497772
130 | Sudan,4.13899993896484,0.65951669216156,0.290920823812485,0.0149958552792668
131 | Ghana,4.11999988555908,0.667224824428558,0.295637726783752,0.423026293516159
132 | Ukraine,4.09600019454956,0.89465194940567,0.575903952121735,0.122974775731564
133 | Uganda,4.08099985122681,0.381430715322495,0.217632606625557,0.443185955286026
134 | Burkina Faso,4.03200006484985,0.3502277135849,0.215844258666039,0.324367851018906
135 | Niger,4.02799987792969,0.161925330758095,0.26850500702858,0.36365869641304
136 | Malawi,3.97000002861023,0.233442038297653,0.315089583396912,0.466914653778076
137 | Chad,3.93600010871887,0.438012987375259,0.0411347150802612,0.16234202682972
138 | Zimbabwe,3.875,0.375846534967422,0.196763753890991,0.336384207010269
139 | Lesotho,3.80800008773804,0.521021246910095,0.0,0.390661299228668
140 | Angola,3.79500007629395,0.858428180217743,0.0498686656355858,0.0
141 | Afghanistan,3.79399991035461,0.401477217674255,0.180746778845787,0.106179520487785
142 | Botswana,3.76600003242493,1.12209415435791,0.341755509376526,0.505196332931519
143 | Benin,3.65700006484985,0.431085407733917,0.209930211305618,0.425962775945663
144 | Madagascar,3.64400005340576,0.305808693170547,0.375223308801651,0.189196765422821
145 | Haiti,3.6029999256134,0.368610262870789,0.277321130037308,0.0303698573261499
146 | Yemen,3.59299993515015,0.591683447360992,0.310080915689468,0.249463722109795
147 | South Sudan,3.59100008010864,0.39724862575531,0.163486003875732,0.147062435746193
148 | Liberia,3.53299999237061,0.119041793048382,0.229918196797371,0.332881182432175
149 | Guinea,3.50699996948242,0.244549930095673,0.194129139184952,0.348587512969971
150 | Togo,3.49499988555908,0.305444717407227,0.247105568647385,0.38042613863945
151 | Rwanda,3.47099995613098,0.368745893239975,0.326424807310104,0.581843852996826
152 | Syria,3.46199989318848,0.777153134346008,0.50053334236145,0.0815394446253777
153 | Tanzania,3.34899997711182,0.511135876178741,0.364509284496307,0.390017777681351
154 | Burundi,2.90499997138977,0.091622568666935,0.151610791683197,0.0599007532000542
155 | Central African Republic,2.69300007820129,0.0,0.0187726859003305,0.270842045545578
156 |
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report.tsv:
--------------------------------------------------------------------------------
1 | country happiness_score GDP_per_capita life_expectancy freedom
2 | Norway 7.53700017929077 1.61646318435669 0.796666502952576 0.635422587394714
3 | Denmark 7.52199983596802 1.48238301277161 0.792565524578094 0.626006722450256
4 | Iceland 7.50400018692017 1.480633020401 0.833552122116089 0.627162635326385
5 | Switzerland 7.49399995803833 1.56497955322266 0.858131289482117 0.620070576667786
6 | Finland 7.4689998626709 1.44357192516327 0.80915766954422 0.617950856685638
7 | Netherlands 7.3769998550415 1.50394463539124 0.810696125030518 0.585384488105774
8 | Canada 7.31599998474121 1.47920441627502 0.83455765247345 0.611100912094116
9 | New Zealand 7.31400012969971 1.40570604801178 0.816759705543518 0.614062130451202
10 | Sweden 7.28399991989136 1.49438726902008 0.830875158309937 0.612924098968506
11 | Australia 7.28399991989136 1.484414935112 0.84388679265976 0.601607382297516
12 | Israel 7.21299982070923 1.37538242340088 0.83840399980545 0.405988603830338
13 | Costa Rica 7.0789999961853 1.10970628261566 0.759509265422821 0.580131649971008
14 | Austria 7.00600004196167 1.48709726333618 0.81532841920852706 0.567766189575195
15 | United States 6.99300003051758 1.54625928401947 0.77428662776947 0.505740523338318
16 | Ireland 6.97700023651123 1.53570663928986 0.80978262424469 0.573110342025757
17 | Germany 6.95100021362305 1.48792338371277 0.798950731754303 0.562511384487152
18 | Belgium 6.89099979400635 1.46378076076508 0.818091869354248 0.539770722389221
19 | Luxembourg 6.86299991607666 1.74194359779358 0.845089495182037 0.59662789106369
20 | United Kingdom 6.71400022506714 1.44163393974304 0.805335938930511 0.508190035820007
21 | Chile 6.65199995040894 1.25278460979462 0.819479703903198 0.376895278692245
22 | United Arab Emirates 6.64799976348877 1.62634336948395 0.726798236370087 0.60834527015686
23 | Brazil 6.63500022888184 1.10735321044922 0.616552352905273 0.437453746795654
24 | Czech Republic 6.60900020599365 1.35268235206604 0.754444003105164 0.490946173667908
25 | Argentina 6.59899997711182 1.18529546260834 0.695137083530426 0.494519203901291
26 | Mexico 6.57800006866455 1.15318381786346 0.709978997707367 0.412730008363724
27 | Singapore 6.57200002670288 1.69227766990662 0.949492394924164 0.549840569496155
28 | Malta 6.52699995040894 1.34327983856201 0.821944236755371 0.588767051696777
29 | Uruguay 6.4539999961853 1.21755969524384 0.719216823577881 0.57939225435257
30 | Guatemala 6.4539999961853 0.872001945972443 0.540239989757538 0.531310617923737
31 | Panama 6.4520001411438 1.23374843597412 0.706156134605408 0.550026834011078
32 | France 6.44199991226196 1.43092346191406 0.844465851783752 0.470222115516663
33 | Thailand 6.42399978637695 1.12786877155304 0.647239029407501 0.580200731754303
34 | Taiwan Province of China 6.42199993133545 1.43362653255463 0.793984234333038 0.361466586589813
35 | Spain 6.40299987792969 1.38439786434174 0.888960599899292 0.408781230449677
36 | Qatar 6.375 1.87076568603516 0.710098087787628 0.604130983352661
37 | Colombia 6.35699987411499 1.07062232494354 0.595027923583984 0.477487415075302
38 | Saudi Arabia 6.3439998626709 1.53062355518341 0.590148329734802 0.449750572443008
39 | Trinidad and Tobago 6.16800022125244 1.36135590076447 0.519983291625977 0.518630743026733
40 | Kuwait 6.10500001907349 1.63295245170593 0.632105708122253 0.496337592601776
41 | Slovakia 6.09800004959106 1.32539355754852 0.712732911109924 0.295817464590073
42 | Bahrain 6.08699989318848 1.48841226100922 0.653133034706116 0.536746919155121
43 | Malaysia 6.08400011062622 1.29121541976929 0.618784427642822 0.402264982461929
44 | Nicaragua 6.07100009918213 0.737299203872681 0.653095960617065 0.447551846504211
45 | Ecuador 6.00799989700317 1.00082039833069 0.685636222362518 0.4551981985569
46 | El Salvador 6.00299978256226 0.909784495830536 0.596018552780151 0.432452529668808
47 | Poland 5.97300004959106 1.29178786277771 0.699475347995758 0.520342111587524
48 | Uzbekistan 5.97100019454956 0.786441087722778 0.498272627592087 0.658248662948608
49 | Italy 5.96400022506714 1.39506661891937 0.853144347667694 0.256450712680817
50 | Russia 5.96299982070923 1.28177809715271 0.547349333763123 0.373783111572266
51 | Belize 5.95599985122681 0.907975316047668 0.450191766023636 0.547509372234344
52 | Japan 5.92000007629395 1.41691517829895 0.913475871086121 0.505625545978546
53 | Lithuania 5.90199995040894 1.31458234786987 0.62894994020462 0.234231784939766
54 | Algeria 5.87200021743774 1.09186446666718 0.617584645748138 0.233335807919502
55 | Latvia 5.84999990463257 1.26074862480164 0.638566970825195 0.325707912445068
56 | South Korea 5.83799982070923 1.40167844295502 0.900214076042175 0.257921665906906
57 | Moldova 5.83799982070923 0.728870630264282 0.589465200901031 0.240729048848152
58 | Romania 5.82499980926514 1.21768391132355 0.685158312320709 0.457003742456436
59 | Bolivia 5.82299995422363 0.833756566047668 0.473630249500275 0.558732926845551
60 | Turkmenistan 5.82200002670288 1.13077676296234 0.437726080417633 0.41827192902565
61 | Kazakhstan 5.81899976730347 1.28455626964569 0.606041550636292 0.437454283237457
62 | North Cyprus 5.80999994277954 1.3469113111496 0.834647238254547 0.471203625202179
63 | Slovenia 5.75799989700317 1.3412059545517 0.790828227996826 0.572575807571411
64 | Peru 5.71500015258789 1.03522527217865 0.630166113376617 0.450002878904343
65 | Mauritius 5.62900018692017 1.18939554691315 0.638007462024689 0.491247326135635
66 | Cyprus 5.62099981307983 1.35593807697296 0.84471470117569 0.355111539363861
67 | Estonia 5.61100006103516 1.32087934017181 0.695168316364288 0.479131430387497
68 | Belarus 5.56899976730347 1.15655755996704 0.637714266777039 0.295400261878967
69 | Libya 5.52500009536743 1.10180306434631 0.520169019699097 0.465733230113983
70 | Turkey 5.5 1.19827437400818 0.637605607509613 0.300740599632263
71 | Paraguay 5.49300003051758 0.932537317276001 0.579250693321228 0.473507791757584
72 | Hong Kong S.A.R., China 5.47200012207031 1.55167484283447 0.943062424659729 0.490968644618988
73 | Philippines 5.42999982833862 0.85769921541214 0.468009054660797 0.585214674472809
74 | Serbia 5.39499998092651 1.06931757926941 0.65078467130661 0.208715528249741
75 | Jordan 5.33599996566772 0.991012394428253 0.604590058326721 0.418421149253845
76 | Hungary 5.32399988174438 1.2860119342804 0.687763452529907 0.175863519310951
77 | Jamaica 5.31099987030029 0.925579309463501 0.641022384166718 0.474307239055634
78 | Croatia 5.29300022125244 1.22255623340607 0.701288521289825 0.255772292613983
79 | Kosovo 5.27899980545044 0.951484382152557 0.541452050209045 0.260287940502167
80 | China 5.27299976348877 1.08116579055786 0.741415500640869 0.472787708044052
81 | Pakistan 5.26900005340576 0.72688353061676 0.402047783136368 0.23521526157856
82 | Indonesia 5.26200008392334 0.995538592338562 0.492345720529556 0.443323463201523
83 | Venezuela 5.25 1.12843120098114 0.617144227027893 0.153997123241425
84 | Montenegro 5.23699998855591 1.12112903594971 0.667464673519135 0.194989055395126
85 | Morocco 5.2350001335144 0.878114581108093 0.59771066904068 0.408158332109451
86 | Azerbaijan 5.23400020599365 1.15360176563263 0.540775775909424 0.398155838251114
87 | Dominican Republic 5.23000001907349 1.07937383651733 0.574873745441437 0.55258983373642
88 | Greece 5.22700023651123 1.28948748111725 0.810198903083801 0.0957312509417534
89 | Lebanon 5.22499990463257 1.07498753070831 0.73508107662200906 0.288515985012054
90 | Portugal 5.19500017166138 1.3151752948761 0.795843541622162 0.498465299606323
91 | Bosnia and Herzegovina 5.18200016021729 0.982409417629242 0.705186307430267 0.204403176903725
92 | Honduras 5.18100023269653 0.730573117733002 0.582569479942322 0.348079860210419
93 | Macedonia 5.17500019073486 1.06457793712616 0.644948184490204 0.325905978679657
94 | Somalia 5.15100002288818 0.0226431842893362 0.113989137113094 0.602126955986023
95 | Vietnam 5.07399988174438 0.788547575473785 0.652168989181519 0.571055591106415
96 | Nigeria 5.07399988174438 0.783756256103516 0.0569157302379608 0.394952565431595
97 | Tajikistan 5.04099988937378 0.524713635444641 0.529235124588013 0.471566706895828
98 | Bhutan 5.01100015640259 0.885416388511658 0.495879292488098 0.501537680625916
99 | Kyrgyzstan 5.00400018692017 0.596220076084137 0.553457796573639 0.454943388700485
100 | Nepal 4.96199989318848 0.479820191860199 0.504130780696869 0.440305948257446
101 | Mongolia 4.95499992370605 1.02723586559296 0.557783484458923 0.394143968820572
102 | South Africa 4.8289999961853 1.05469870567322 0.187080070376396 0.479246735572815
103 | Tunisia 4.80499982833862 1.00726580619812 0.613212049007416 0.289680689573288
104 | Palestinian Territories 4.77500009536743 0.716249227523804 0.565666973590851 0.25471106171608
105 | Egypt 4.7350001335144 0.989701807498932 0.520187258720398 0.282110154628754
106 | Bulgaria 4.71400022506714 1.1614590883255 0.708217680454254 0.289231717586517
107 | Sierra Leone 4.70900011062622 0.36842092871666 0.00556475389748812 0.318697690963745
108 | Cameroon 4.69500017166138 0.564305365085602 0.132892116904259 0.430388748645782
109 | Iran 4.69199991226196 1.15687310695648 0.639333188533783 0.249322608113289
110 | Albania 4.64400005340576 0.996192753314972 0.731159746646881 0.381498634815216
111 | Bangladesh 4.60799980163574 0.586682975292206 0.533241033554077 0.478356659412384
112 | Namibia 4.57399988174438 0.964434325695038 0.33861181139946 0.520303547382355
113 | Kenya 4.55299997329712 0.560479462146759 0.309988349676132 0.452763766050339
114 | Mozambique 4.55000019073486 0.234305649995804 0.106654435396194 0.480791091918945
115 | Myanmar 4.54500007629395 0.367110550403595 0.397522568702698 0.514492034912109
116 | Senegal 4.53499984741211 0.479309022426605 0.409362852573395 0.377922266721725
117 | Zambia 4.51399993896484 0.636406779289246 0.257835894823074 0.461603492498398
118 | Iraq 4.49700021743774 1.10271048545837 0.50118046998977706 0.288555532693863
119 | Gabon 4.46500015258789 1.1982102394104 0.356578588485718 0.312328577041626
120 | Ethiopia 4.46000003814697 0.339233845472336 0.353409707546234 0.408842742443085
121 | Sri Lanka 4.44000005722046 1.00985014438629 0.625130832195282 0.561213254928589
122 | Armenia 4.37599992752075 0.900596737861633 0.637524425983429 0.198303267359734
123 | India 4.31500005722046 0.792221248149872 0.455427616834641 0.469987004995346
124 | Mauritania 4.29199981689453 0.648457288742065 0.285349279642105 0.0960980430245399
125 | Congo (Brazzaville) 4.29099988937378 0.808964252471924 0.28995743393898 0.435025870800018
126 | Georgia 4.28599977493286 0.950612664222717 0.649546980857849 0.309410035610199
127 | Congo (Kinshasa) 4.28000020980835 0.0921023488044739 0.191407024860382 0.235961347818375
128 | Mali 4.19000005722046 0.476180493831635 0.169365674257278 0.306613743305206
129 | Ivory Coast 4.17999982833862 0.603048920631409 0.0486421696841717 0.447706192731857
130 | Cambodia 4.16800022125244 0.601765096187592 0.429783403873444 0.633375823497772
131 | Sudan 4.13899993896484 0.65951669216156 0.290920823812485 0.0149958552792668
132 | Ghana 4.11999988555908 0.667224824428558 0.295637726783752 0.423026293516159
133 | Ukraine 4.09600019454956 0.89465194940567 0.575903952121735 0.122974775731564
134 | Uganda 4.08099985122681 0.381430715322495 0.217632606625557 0.443185955286026
135 | Burkina Faso 4.03200006484985 0.3502277135849 0.215844258666039 0.324367851018906
136 | Niger 4.02799987792969 0.161925330758095 0.26850500702858 0.36365869641304
137 | Malawi 3.97000002861023 0.233442038297653 0.315089583396912 0.466914653778076
138 | Chad 3.93600010871887 0.438012987375259 0.0411347150802612 0.16234202682972
139 | Zimbabwe 3.875 0.375846534967422 0.196763753890991 0.336384207010269
140 | Lesotho 3.80800008773804 0.521021246910095 0.0 0.390661299228668
141 | Angola 3.79500007629395 0.858428180217743 0.0498686656355858 0.0
142 | Afghanistan 3.79399991035461 0.401477217674255 0.180746778845787 0.106179520487785
143 | Botswana 3.76600003242493 1.12209415435791 0.341755509376526 0.505196332931519
144 | Benin 3.65700006484985 0.431085407733917 0.209930211305618 0.425962775945663
145 | Madagascar 3.64400005340576 0.305808693170547 0.375223308801651 0.189196765422821
146 | Haiti 3.6029999256134 0.368610262870789 0.277321130037308 0.0303698573261499
147 | Yemen 3.59299993515015 0.591683447360992 0.310080915689468 0.249463722109795
148 | South Sudan 3.59100008010864 0.39724862575531 0.163486003875732 0.147062435746193
149 | Liberia 3.53299999237061 0.119041793048382 0.229918196797371 0.332881182432175
150 | Guinea 3.50699996948242 0.244549930095673 0.194129139184952 0.348587512969971
151 | Togo 3.49499988555908 0.305444717407227 0.247105568647385 0.38042613863945
152 | Rwanda 3.47099995613098 0.368745893239975 0.326424807310104 0.581843852996826
153 | Syria 3.46199989318848 0.777153134346008 0.50053334236145 0.0815394446253777
154 | Tanzania 3.34899997711182 0.511135876178741 0.364509284496307 0.390017777681351
155 | Burundi 2.90499997138977 0.091622568666935 0.151610791683197 0.0599007532000542
156 | Central African Republic 2.69300007820129 0.0 0.0187726859003305 0.270842045545578
157 |
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report.csv:
--------------------------------------------------------------------------------
1 | country,happiness_score,GDP_per_capita,life_expectancy,freedom
2 | Norway,7.53700017929077,1.61646318435669,0.796666502952576,0.635422587394714
3 | Denmark,7.52199983596802,1.48238301277161,0.792565524578094,0.626006722450256
4 | Iceland,7.50400018692017,1.480633020401,0.833552122116089,0.627162635326385
5 | Switzerland,7.49399995803833,1.56497955322266,0.858131289482117,0.620070576667786
6 | Finland,7.4689998626709,1.44357192516327,0.80915766954422,0.617950856685638
7 | Netherlands,7.3769998550415,1.50394463539124,0.810696125030518,0.585384488105774
8 | Canada,7.31599998474121,1.47920441627502,0.83455765247345,0.611100912094116
9 | New Zealand,7.31400012969971,1.40570604801178,0.816759705543518,0.614062130451202
10 | Sweden,7.28399991989136,1.49438726902008,0.830875158309937,0.612924098968506
11 | Australia,7.28399991989136,1.484414935112,0.84388679265976,0.601607382297516
12 | Israel,7.21299982070923,1.37538242340088,0.83840399980545,0.405988603830338
13 | Costa Rica,7.0789999961853,1.10970628261566,0.759509265422821,0.580131649971008
14 | Austria,7.00600004196167,1.48709726333618,0.81532841920852706,0.567766189575195
15 | United States,6.99300003051758,1.54625928401947,0.77428662776947,0.505740523338318
16 | Ireland,6.97700023651123,1.53570663928986,0.80978262424469,0.573110342025757
17 | Germany,6.95100021362305,1.48792338371277,0.798950731754303,0.562511384487152
18 | Belgium,6.89099979400635,1.46378076076508,0.818091869354248,0.539770722389221
19 | Luxembourg,6.86299991607666,1.74194359779358,0.845089495182037,0.59662789106369
20 | United Kingdom,6.71400022506714,1.44163393974304,0.805335938930511,0.508190035820007
21 | Chile,6.65199995040894,1.25278460979462,0.819479703903198,0.376895278692245
22 | United Arab Emirates,6.64799976348877,1.62634336948395,0.726798236370087,0.60834527015686
23 | Brazil,6.63500022888184,1.10735321044922,0.616552352905273,0.437453746795654
24 | Czech Republic,6.60900020599365,1.35268235206604,0.754444003105164,0.490946173667908
25 | Argentina,6.59899997711182,1.18529546260834,0.695137083530426,0.494519203901291
26 | Mexico,6.57800006866455,1.15318381786346,0.709978997707367,0.412730008363724
27 | Singapore,6.57200002670288,1.69227766990662,0.949492394924164,0.549840569496155
28 | Malta,6.52699995040894,1.34327983856201,0.821944236755371,0.588767051696777
29 | Uruguay,6.4539999961853,1.21755969524384,0.719216823577881,0.57939225435257
30 | Guatemala,6.4539999961853,0.872001945972443,0.540239989757538,0.531310617923737
31 | Panama,6.4520001411438,1.23374843597412,0.706156134605408,0.550026834011078
32 | France,6.44199991226196,1.43092346191406,0.844465851783752,0.470222115516663
33 | Thailand,6.42399978637695,1.12786877155304,0.647239029407501,0.580200731754303
34 | Taiwan Province of China,6.42199993133545,1.43362653255463,0.793984234333038,0.361466586589813
35 | Spain,6.40299987792969,1.38439786434174,0.888960599899292,0.408781230449677
36 | Qatar,6.375,1.87076568603516,0.710098087787628,0.604130983352661
37 | Colombia,6.35699987411499,1.07062232494354,0.595027923583984,0.477487415075302
38 | Saudi Arabia,6.3439998626709,1.53062355518341,0.590148329734802,0.449750572443008
39 | Trinidad and Tobago,6.16800022125244,1.36135590076447,0.519983291625977,0.518630743026733
40 | Kuwait,6.10500001907349,1.63295245170593,0.632105708122253,0.496337592601776
41 | Slovakia,6.09800004959106,1.32539355754852,0.712732911109924,0.295817464590073
42 | Bahrain,6.08699989318848,1.48841226100922,0.653133034706116,0.536746919155121
43 | Malaysia,6.08400011062622,1.29121541976929,0.618784427642822,0.402264982461929
44 | Nicaragua,6.07100009918213,0.737299203872681,0.653095960617065,0.447551846504211
45 | Ecuador,6.00799989700317,1.00082039833069,0.685636222362518,0.4551981985569
46 | El Salvador,6.00299978256226,0.909784495830536,0.596018552780151,0.432452529668808
47 | Poland,5.97300004959106,1.29178786277771,0.699475347995758,0.520342111587524
48 | Uzbekistan,5.97100019454956,0.786441087722778,0.498272627592087,0.658248662948608
49 | Italy,5.96400022506714,1.39506661891937,0.853144347667694,0.256450712680817
50 | Russia,5.96299982070923,1.28177809715271,0.547349333763123,0.373783111572266
51 | Belize,5.95599985122681,0.907975316047668,0.450191766023636,0.547509372234344
52 | Japan,5.92000007629395,1.41691517829895,0.913475871086121,0.505625545978546
53 | Lithuania,5.90199995040894,1.31458234786987,0.62894994020462,0.234231784939766
54 | Algeria,5.87200021743774,1.09186446666718,0.617584645748138,0.233335807919502
55 | Latvia,5.84999990463257,1.26074862480164,0.638566970825195,0.325707912445068
56 | South Korea,5.83799982070923,1.40167844295502,0.900214076042175,0.257921665906906
57 | Moldova,5.83799982070923,0.728870630264282,0.589465200901031,0.240729048848152
58 | Romania,5.82499980926514,1.21768391132355,0.685158312320709,0.457003742456436
59 | Bolivia,5.82299995422363,0.833756566047668,0.473630249500275,0.558732926845551
60 | Turkmenistan,5.82200002670288,1.13077676296234,0.437726080417633,0.41827192902565
61 | Kazakhstan,5.81899976730347,1.28455626964569,0.606041550636292,0.437454283237457
62 | North Cyprus,5.80999994277954,1.3469113111496,0.834647238254547,0.471203625202179
63 | Slovenia,5.75799989700317,1.3412059545517,0.790828227996826,0.572575807571411
64 | Peru,5.71500015258789,1.03522527217865,0.630166113376617,0.450002878904343
65 | Mauritius,5.62900018692017,1.18939554691315,0.638007462024689,0.491247326135635
66 | Cyprus,5.62099981307983,1.35593807697296,0.84471470117569,0.355111539363861
67 | Estonia,5.61100006103516,1.32087934017181,0.695168316364288,0.479131430387497
68 | Belarus,5.56899976730347,1.15655755996704,0.637714266777039,0.295400261878967
69 | Libya,5.52500009536743,1.10180306434631,0.520169019699097,0.465733230113983
70 | Turkey,5.5,1.19827437400818,0.637605607509613,0.300740599632263
71 | Paraguay,5.49300003051758,0.932537317276001,0.579250693321228,0.473507791757584
72 | "Hong Kong S.A.R., China",5.47200012207031,1.55167484283447,0.943062424659729,0.490968644618988
73 | Philippines,5.42999982833862,0.85769921541214,0.468009054660797,0.585214674472809
74 | Serbia,5.39499998092651,1.06931757926941,0.65078467130661,0.208715528249741
75 | Jordan,5.33599996566772,0.991012394428253,0.604590058326721,0.418421149253845
76 | Hungary,5.32399988174438,1.2860119342804,0.687763452529907,0.175863519310951
77 | Jamaica,5.31099987030029,0.925579309463501,0.641022384166718,0.474307239055634
78 | Croatia,5.29300022125244,1.22255623340607,0.701288521289825,0.255772292613983
79 | Kosovo,5.27899980545044,0.951484382152557,0.541452050209045,0.260287940502167
80 | China,5.27299976348877,1.08116579055786,0.741415500640869,0.472787708044052
81 | Pakistan,5.26900005340576,0.72688353061676,0.402047783136368,0.23521526157856
82 | Indonesia,5.26200008392334,0.995538592338562,0.492345720529556,0.443323463201523
83 | Venezuela,5.25,1.12843120098114,0.617144227027893,0.153997123241425
84 | Montenegro,5.23699998855591,1.12112903594971,0.667464673519135,0.194989055395126
85 | Morocco,5.2350001335144,0.878114581108093,0.59771066904068,0.408158332109451
86 | Azerbaijan,5.23400020599365,1.15360176563263,0.540775775909424,0.398155838251114
87 | Dominican Republic,5.23000001907349,1.07937383651733,0.574873745441437,0.55258983373642
88 | Greece,5.22700023651123,1.28948748111725,0.810198903083801,0.0957312509417534
89 | Lebanon,5.22499990463257,1.07498753070831,0.73508107662200906,0.288515985012054
90 | Portugal,5.19500017166138,1.3151752948761,0.795843541622162,0.498465299606323
91 | Bosnia and Herzegovina,5.18200016021729,0.982409417629242,0.705186307430267,0.204403176903725
92 | Honduras,5.18100023269653,0.730573117733002,0.582569479942322,0.348079860210419
93 | Macedonia,5.17500019073486,1.06457793712616,0.644948184490204,0.325905978679657
94 | Somalia,5.15100002288818,0.0226431842893362,0.113989137113094,0.602126955986023
95 | Vietnam,5.07399988174438,0.788547575473785,0.652168989181519,0.571055591106415
96 | Nigeria,5.07399988174438,0.783756256103516,0.0569157302379608,0.394952565431595
97 | Tajikistan,5.04099988937378,0.524713635444641,0.529235124588013,0.471566706895828
98 | Bhutan,5.01100015640259,0.885416388511658,0.495879292488098,0.501537680625916
99 | Kyrgyzstan,5.00400018692017,0.596220076084137,0.553457796573639,0.454943388700485
100 | Nepal,4.96199989318848,0.479820191860199,0.504130780696869,0.440305948257446
101 | Mongolia,4.95499992370605,1.02723586559296,0.557783484458923,0.394143968820572
102 | South Africa,4.8289999961853,1.05469870567322,0.187080070376396,0.479246735572815
103 | Tunisia,4.80499982833862,1.00726580619812,0.613212049007416,0.289680689573288
104 | Palestinian Territories,4.77500009536743,0.716249227523804,0.565666973590851,0.25471106171608
105 | Egypt,4.7350001335144,0.989701807498932,0.520187258720398,0.282110154628754
106 | Bulgaria,4.71400022506714,1.1614590883255,0.708217680454254,0.289231717586517
107 | Sierra Leone,4.70900011062622,0.36842092871666,0.00556475389748812,0.318697690963745
108 | Cameroon,4.69500017166138,0.564305365085602,0.132892116904259,0.430388748645782
109 | Iran,4.69199991226196,1.15687310695648,0.639333188533783,0.249322608113289
110 | Albania,4.64400005340576,0.996192753314972,0.731159746646881,0.381498634815216
111 | Bangladesh,4.60799980163574,0.586682975292206,0.533241033554077,0.478356659412384
112 | Namibia,4.57399988174438,0.964434325695038,0.33861181139946,0.520303547382355
113 | Kenya,4.55299997329712,0.560479462146759,0.309988349676132,0.452763766050339
114 | Mozambique,4.55000019073486,0.234305649995804,0.106654435396194,0.480791091918945
115 | Myanmar,4.54500007629395,0.367110550403595,0.397522568702698,0.514492034912109
116 | Senegal,4.53499984741211,0.479309022426605,0.409362852573395,0.377922266721725
117 | Zambia,4.51399993896484,0.636406779289246,0.257835894823074,0.461603492498398
118 | Iraq,4.49700021743774,1.10271048545837,0.50118046998977706,0.288555532693863
119 | Gabon,4.46500015258789,1.1982102394104,0.356578588485718,0.312328577041626
120 | Ethiopia,4.46000003814697,0.339233845472336,0.353409707546234,0.408842742443085
121 | Sri Lanka,4.44000005722046,1.00985014438629,0.625130832195282,0.561213254928589
122 | Armenia,4.37599992752075,0.900596737861633,0.637524425983429,0.198303267359734
123 | India,4.31500005722046,0.792221248149872,0.455427616834641,0.469987004995346
124 | Mauritania,4.29199981689453,0.648457288742065,0.285349279642105,0.0960980430245399
125 | Congo (Brazzaville),4.29099988937378,0.808964252471924,0.28995743393898,0.435025870800018
126 | Georgia,4.28599977493286,0.950612664222717,0.649546980857849,0.309410035610199
127 | Congo (Kinshasa),4.28000020980835,0.0921023488044739,0.191407024860382,0.235961347818375
128 | Mali,4.19000005722046,0.476180493831635,0.169365674257278,0.306613743305206
129 | Ivory Coast,4.17999982833862,0.603048920631409,0.0486421696841717,0.447706192731857
130 | Cambodia,4.16800022125244,0.601765096187592,0.429783403873444,0.633375823497772
131 | Sudan,4.13899993896484,0.65951669216156,0.290920823812485,0.0149958552792668
132 | Ghana,4.11999988555908,0.667224824428558,0.295637726783752,0.423026293516159
133 | Ukraine,4.09600019454956,0.89465194940567,0.575903952121735,0.122974775731564
134 | Uganda,4.08099985122681,0.381430715322495,0.217632606625557,0.443185955286026
135 | Burkina Faso,4.03200006484985,0.3502277135849,0.215844258666039,0.324367851018906
136 | Niger,4.02799987792969,0.161925330758095,0.26850500702858,0.36365869641304
137 | Malawi,3.97000002861023,0.233442038297653,0.315089583396912,0.466914653778076
138 | Chad,3.93600010871887,0.438012987375259,0.0411347150802612,0.16234202682972
139 | Zimbabwe,3.875,0.375846534967422,0.196763753890991,0.336384207010269
140 | Lesotho,3.80800008773804,0.521021246910095,0.0,0.390661299228668
141 | Angola,3.79500007629395,0.858428180217743,0.0498686656355858,0.0
142 | Afghanistan,3.79399991035461,0.401477217674255,0.180746778845787,0.106179520487785
143 | Botswana,3.76600003242493,1.12209415435791,0.341755509376526,0.505196332931519
144 | Benin,3.65700006484985,0.431085407733917,0.209930211305618,0.425962775945663
145 | Madagascar,3.64400005340576,0.305808693170547,0.375223308801651,0.189196765422821
146 | Haiti,3.6029999256134,0.368610262870789,0.277321130037308,0.0303698573261499
147 | Yemen,3.59299993515015,0.591683447360992,0.310080915689468,0.249463722109795
148 | South Sudan,3.59100008010864,0.39724862575531,0.163486003875732,0.147062435746193
149 | Liberia,3.53299999237061,0.119041793048382,0.229918196797371,0.332881182432175
150 | Guinea,3.50699996948242,0.244549930095673,0.194129139184952,0.348587512969971
151 | Togo,3.49499988555908,0.305444717407227,0.247105568647385,0.38042613863945
152 | Rwanda,3.47099995613098,0.368745893239975,0.326424807310104,0.581843852996826
153 | Syria,3.46199989318848,0.777153134346008,0.50053334236145,0.0815394446253777
154 | Tanzania,3.34899997711182,0.511135876178741,0.364509284496307,0.390017777681351
155 | Burundi,2.90499997138977,0.091622568666935,0.151610791683197,0.0599007532000542
156 | Central African Republic,2.69300007820129,0.0,0.0187726859003305,0.270842045545578
157 |
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report_semicolon.csv:
--------------------------------------------------------------------------------
1 | country;happiness_score;GDP_per_capita;life_expectancy;freedom
2 | Norway;7,53700017929077;1,61646318435669;0,796666502952576;0,635422587394714
3 | Denmark;7,52199983596802;1,48238301277161;0,792565524578094;0,626006722450256
4 | Iceland;7,50400018692017;1,480633020401;0,833552122116089;0,627162635326385
5 | Switzerland;7,49399995803833;1,56497955322266;0,858131289482117;0,620070576667786
6 | Finland;7,4689998626709;1,44357192516327;0,80915766954422;0,617950856685638
7 | Netherlands;7,3769998550415;1,50394463539124;0,810696125030518;0,585384488105774
8 | Canada;7,31599998474121;1,47920441627502;0,83455765247345;0,611100912094116
9 | New Zealand;7,31400012969971;1,40570604801178;0,816759705543518;0,614062130451202
10 | Sweden;7,28399991989136;1,49438726902008;0,830875158309937;0,612924098968506
11 | Australia;7,28399991989136;1,484414935112;0,84388679265976;0,601607382297516
12 | Israel;7,21299982070923;1,37538242340088;0,83840399980545;0,405988603830338
13 | Costa Rica;7,0789999961853;1,10970628261566;0,759509265422821;0,580131649971008
14 | Austria;7,00600004196167;1,48709726333618;0,81532841920852706;0,567766189575195
15 | United States;6,99300003051758;1,54625928401947;0,77428662776947;0,505740523338318
16 | Ireland;6,97700023651123;1,53570663928986;0,80978262424469;0,573110342025757
17 | Germany;6,95100021362305;1,48792338371277;0,798950731754303;0,562511384487152
18 | Belgium;6,89099979400635;1,46378076076508;0,818091869354248;0,539770722389221
19 | Luxembourg;6,86299991607666;1,74194359779358;0,845089495182037;0,59662789106369
20 | United Kingdom;6,71400022506714;1,44163393974304;0,805335938930511;0,508190035820007
21 | Chile;6,65199995040894;1,25278460979462;0,819479703903198;0,376895278692245
22 | United Arab Emirates;6,64799976348877;1,62634336948395;0,726798236370087;0,60834527015686
23 | Brazil;6,63500022888184;1,10735321044922;0,616552352905273;0,437453746795654
24 | Czech Republic;6,60900020599365;1,35268235206604;0,754444003105164;0,490946173667908
25 | Argentina;6,59899997711182;1,18529546260834;0,695137083530426;0,494519203901291
26 | Mexico;6,57800006866455;1,15318381786346;0,709978997707367;0,412730008363724
27 | Singapore;6,57200002670288;1,69227766990662;0,949492394924164;0,549840569496155
28 | Malta;6,52699995040894;1,34327983856201;0,821944236755371;0,588767051696777
29 | Uruguay;6,4539999961853;1,21755969524384;0,719216823577881;0,57939225435257
30 | Guatemala;6,4539999961853;0,872001945972443;0,540239989757538;0,531310617923737
31 | Panama;6,4520001411438;1,23374843597412;0,706156134605408;0,550026834011078
32 | France;6,44199991226196;1,43092346191406;0,844465851783752;0,470222115516663
33 | Thailand;6,42399978637695;1,12786877155304;0,647239029407501;0,580200731754303
34 | Taiwan Province of China;6,42199993133545;1,43362653255463;0,793984234333038;0,361466586589813
35 | Spain;6,40299987792969;1,38439786434174;0,888960599899292;0,408781230449677
36 | Qatar;6,375;1,87076568603516;0,710098087787628;0,604130983352661
37 | Colombia;6,35699987411499;1,07062232494354;0,595027923583984;0,477487415075302
38 | Saudi Arabia;6,3439998626709;1,53062355518341;0,590148329734802;0,449750572443008
39 | Trinidad and Tobago;6,16800022125244;1,36135590076447;0,519983291625977;0,518630743026733
40 | Kuwait;6,10500001907349;1,63295245170593;0,632105708122253;0,496337592601776
41 | Slovakia;6,09800004959106;1,32539355754852;0,712732911109924;0,295817464590073
42 | Bahrain;6,08699989318848;1,48841226100922;0,653133034706116;0,536746919155121
43 | Malaysia;6,08400011062622;1,29121541976929;0,618784427642822;0,402264982461929
44 | Nicaragua;6,07100009918213;0,737299203872681;0,653095960617065;0,447551846504211
45 | Ecuador;6,00799989700317;1,00082039833069;0,685636222362518;0,4551981985569
46 | El Salvador;6,00299978256226;0,909784495830536;0,596018552780151;0,432452529668808
47 | Poland;5,97300004959106;1,29178786277771;0,699475347995758;0,520342111587524
48 | Uzbekistan;5,97100019454956;0,786441087722778;0,498272627592087;0,658248662948608
49 | Italy;5,96400022506714;1,39506661891937;0,853144347667694;0,256450712680817
50 | Russia;5,96299982070923;1,28177809715271;0,547349333763123;0,373783111572266
51 | Belize;5,95599985122681;0,907975316047668;0,450191766023636;0,547509372234344
52 | Japan;5,92000007629395;1,41691517829895;0,913475871086121;0,505625545978546
53 | Lithuania;5,90199995040894;1,31458234786987;0,62894994020462;0,234231784939766
54 | Algeria;5,87200021743774;1,09186446666718;0,617584645748138;0,233335807919502
55 | Latvia;5,84999990463257;1,26074862480164;0,638566970825195;0,325707912445068
56 | South Korea;5,83799982070923;1,40167844295502;0,900214076042175;0,257921665906906
57 | Moldova;5,83799982070923;0,728870630264282;0,589465200901031;0,240729048848152
58 | Romania;5,82499980926514;1,21768391132355;0,685158312320709;0,457003742456436
59 | Bolivia;5,82299995422363;0,833756566047668;0,473630249500275;0,558732926845551
60 | Turkmenistan;5,82200002670288;1,13077676296234;0,437726080417633;0,41827192902565
61 | Kazakhstan;5,81899976730347;1,28455626964569;0,606041550636292;0,437454283237457
62 | North Cyprus;5,80999994277954;1,3469113111496;0,834647238254547;0,471203625202179
63 | Slovenia;5,75799989700317;1,3412059545517;0,790828227996826;0,572575807571411
64 | Peru;5,71500015258789;1,03522527217865;0,630166113376617;0,450002878904343
65 | Mauritius;5,62900018692017;1,18939554691315;0,638007462024689;0,491247326135635
66 | Cyprus;5,62099981307983;1,35593807697296;0,84471470117569;0,355111539363861
67 | Estonia;5,61100006103516;1,32087934017181;0,695168316364288;0,479131430387497
68 | Belarus;5,56899976730347;1,15655755996704;0,637714266777039;0,295400261878967
69 | Libya;5,52500009536743;1,10180306434631;0,520169019699097;0,465733230113983
70 | Turkey;5,5;1,19827437400818;0,637605607509613;0,300740599632263
71 | Paraguay;5,49300003051758;0,932537317276001;0,579250693321228;0,473507791757584
72 | Hong Kong S,A,R,, China;5,47200012207031;1,55167484283447;0,943062424659729;0,490968644618988
73 | Philippines;5,42999982833862;0,85769921541214;0,468009054660797;0,585214674472809
74 | Serbia;5,39499998092651;1,06931757926941;0,65078467130661;0,208715528249741
75 | Jordan;5,33599996566772;0,991012394428253;0,604590058326721;0,418421149253845
76 | Hungary;5,32399988174438;1,2860119342804;0,687763452529907;0,175863519310951
77 | Jamaica;5,31099987030029;0,925579309463501;0,641022384166718;0,474307239055634
78 | Croatia;5,29300022125244;1,22255623340607;0,701288521289825;0,255772292613983
79 | Kosovo;5,27899980545044;0,951484382152557;0,541452050209045;0,260287940502167
80 | China;5,27299976348877;1,08116579055786;0,741415500640869;0,472787708044052
81 | Pakistan;5,26900005340576;0,72688353061676;0,402047783136368;0,23521526157856
82 | Indonesia;5,26200008392334;0,995538592338562;0,492345720529556;0,443323463201523
83 | Venezuela;5,25;1,12843120098114;0,617144227027893;0,153997123241425
84 | Montenegro;5,23699998855591;1,12112903594971;0,667464673519135;0,194989055395126
85 | Morocco;5,2350001335144;0,878114581108093;0,59771066904068;0,408158332109451
86 | Azerbaijan;5,23400020599365;1,15360176563263;0,540775775909424;0,398155838251114
87 | Dominican Republic;5,23000001907349;1,07937383651733;0,574873745441437;0,55258983373642
88 | Greece;5,22700023651123;1,28948748111725;0,810198903083801;0,0957312509417534
89 | Lebanon;5,22499990463257;1,07498753070831;0,73508107662200906;0,288515985012054
90 | Portugal;5,19500017166138;1,3151752948761;0,795843541622162;0,498465299606323
91 | Bosnia and Herzegovina;5,18200016021729;0,982409417629242;0,705186307430267;0,204403176903725
92 | Honduras;5,18100023269653;0,730573117733002;0,582569479942322;0,348079860210419
93 | Macedonia;5,17500019073486;1,06457793712616;0,644948184490204;0,325905978679657
94 | Somalia;5,15100002288818;0,0226431842893362;0,113989137113094;0,602126955986023
95 | Vietnam;5,07399988174438;0,788547575473785;0,652168989181519;0,571055591106415
96 | Nigeria;5,07399988174438;0,783756256103516;0,0569157302379608;0,394952565431595
97 | Tajikistan;5,04099988937378;0,524713635444641;0,529235124588013;0,471566706895828
98 | Bhutan;5,01100015640259;0,885416388511658;0,495879292488098;0,501537680625916
99 | Kyrgyzstan;5,00400018692017;0,596220076084137;0,553457796573639;0,454943388700485
100 | Nepal;4,96199989318848;0,479820191860199;0,504130780696869;0,440305948257446
101 | Mongolia;4,95499992370605;1,02723586559296;0,557783484458923;0,394143968820572
102 | South Africa;4,8289999961853;1,05469870567322;0,187080070376396;0,479246735572815
103 | Tunisia;4,80499982833862;1,00726580619812;0,613212049007416;0,289680689573288
104 | Palestinian Territories;4,77500009536743;0,716249227523804;0,565666973590851;0,25471106171608
105 | Egypt;4,7350001335144;0,989701807498932;0,520187258720398;0,282110154628754
106 | Bulgaria;4,71400022506714;1,1614590883255;0,708217680454254;0,289231717586517
107 | Sierra Leone;4,70900011062622;0,36842092871666;0,00556475389748812;0,318697690963745
108 | Cameroon;4,69500017166138;0,564305365085602;0,132892116904259;0,430388748645782
109 | Iran;4,69199991226196;1,15687310695648;0,639333188533783;0,249322608113289
110 | Albania;4,64400005340576;0,996192753314972;0,731159746646881;0,381498634815216
111 | Bangladesh;4,60799980163574;0,586682975292206;0,533241033554077;0,478356659412384
112 | Namibia;4,57399988174438;0,964434325695038;0,33861181139946;0,520303547382355
113 | Kenya;4,55299997329712;0,560479462146759;0,309988349676132;0,452763766050339
114 | Mozambique;4,55000019073486;0,234305649995804;0,106654435396194;0,480791091918945
115 | Myanmar;4,54500007629395;0,367110550403595;0,397522568702698;0,514492034912109
116 | Senegal;4,53499984741211;0,479309022426605;0,409362852573395;0,377922266721725
117 | Zambia;4,51399993896484;0,636406779289246;0,257835894823074;0,461603492498398
118 | Iraq;4,49700021743774;1,10271048545837;0,50118046998977706;0,288555532693863
119 | Gabon;4,46500015258789;1,1982102394104;0,356578588485718;0,312328577041626
120 | Ethiopia;4,46000003814697;0,339233845472336;0,353409707546234;0,408842742443085
121 | Sri Lanka;4,44000005722046;1,00985014438629;0,625130832195282;0,561213254928589
122 | Armenia;4,37599992752075;0,900596737861633;0,637524425983429;0,198303267359734
123 | India;4,31500005722046;0,792221248149872;0,455427616834641;0,469987004995346
124 | Mauritania;4,29199981689453;0,648457288742065;0,285349279642105;0,0960980430245399
125 | Congo (Brazzaville);4,29099988937378;0,808964252471924;0,28995743393898;0,435025870800018
126 | Georgia;4,28599977493286;0,950612664222717;0,649546980857849;0,309410035610199
127 | Congo (Kinshasa);4,28000020980835;0,0921023488044739;0,191407024860382;0,235961347818375
128 | Mali;4,19000005722046;0,476180493831635;0,169365674257278;0,306613743305206
129 | Ivory Coast;4,17999982833862;0,603048920631409;0,0486421696841717;0,447706192731857
130 | Cambodia;4,16800022125244;0,601765096187592;0,429783403873444;0,633375823497772
131 | Sudan;4,13899993896484;0,65951669216156;0,290920823812485;0,0149958552792668
132 | Ghana;4,11999988555908;0,667224824428558;0,295637726783752;0,423026293516159
133 | Ukraine;4,09600019454956;0,89465194940567;0,575903952121735;0,122974775731564
134 | Uganda;4,08099985122681;0,381430715322495;0,217632606625557;0,443185955286026
135 | Burkina Faso;4,03200006484985;0,3502277135849;0,215844258666039;0,324367851018906
136 | Niger;4,02799987792969;0,161925330758095;0,26850500702858;0,36365869641304
137 | Malawi;3,97000002861023;0,233442038297653;0,315089583396912;0,466914653778076
138 | Chad;3,93600010871887;0,438012987375259;0,0411347150802612;0,16234202682972
139 | Zimbabwe;3,875;0,375846534967422;0,196763753890991;0,336384207010269
140 | Lesotho;3,80800008773804;0,521021246910095;0,0;0,390661299228668
141 | Angola;3,79500007629395;0,858428180217743;0,0498686656355858;0,0
142 | Afghanistan;3,79399991035461;0,401477217674255;0,180746778845787;0,106179520487785
143 | Botswana;3,76600003242493;1,12209415435791;0,341755509376526;0,505196332931519
144 | Benin;3,65700006484985;0,431085407733917;0,209930211305618;0,425962775945663
145 | Madagascar;3,64400005340576;0,305808693170547;0,375223308801651;0,189196765422821
146 | Haiti;3,6029999256134;0,368610262870789;0,277321130037308;0,0303698573261499
147 | Yemen;3,59299993515015;0,591683447360992;0,310080915689468;0,249463722109795
148 | South Sudan;3,59100008010864;0,39724862575531;0,163486003875732;0,147062435746193
149 | Liberia;3,53299999237061;0,119041793048382;0,229918196797371;0,332881182432175
150 | Guinea;3,50699996948242;0,244549930095673;0,194129139184952;0,348587512969971
151 | Togo;3,49499988555908;0,305444717407227;0,247105568647385;0,38042613863945
152 | Rwanda;3,47099995613098;0,368745893239975;0,326424807310104;0,581843852996826
153 | Syria;3,46199989318848;0,777153134346008;0,50053334236145;0,0815394446253777
154 | Tanzania;3,34899997711182;0,511135876178741;0,364509284496307;0,390017777681351
155 | Burundi;2,90499997138977;0,091622568666935;0,151610791683197;0,0599007532000542
156 | Central African Republic;2,69300007820129;0,0;0,0187726859003305;0,270842045545578
157 |
--------------------------------------------------------------------------------
/worksheet_reading/data/happiness_report_metadata.csv:
--------------------------------------------------------------------------------
1 | The World Happiness 2017 ranks 155 contries by their happiness levels.
2 | Released by the United Nations at an event celebrating International Day of Happiness on March 20th.
3 |
4 | country,happiness_score,GDP_per_capita,life_expectancy,freedom
5 | Norway,7.53700017929077,1.61646318435669,0.796666502952576,0.635422587394714
6 | Denmark,7.52199983596802,1.48238301277161,0.792565524578094,0.626006722450256
7 | Iceland,7.50400018692017,1.480633020401,0.833552122116089,0.627162635326385
8 | Switzerland,7.49399995803833,1.56497955322266,0.858131289482117,0.620070576667786
9 | Finland,7.4689998626709,1.44357192516327,0.80915766954422,0.617950856685638
10 | Netherlands,7.3769998550415,1.50394463539124,0.810696125030518,0.585384488105774
11 | Canada,7.31599998474121,1.47920441627502,0.83455765247345,0.611100912094116
12 | New Zealand,7.31400012969971,1.40570604801178,0.816759705543518,0.614062130451202
13 | Sweden,7.28399991989136,1.49438726902008,0.830875158309937,0.612924098968506
14 | Australia,7.28399991989136,1.484414935112,0.84388679265976,0.601607382297516
15 | Israel,7.21299982070923,1.37538242340088,0.83840399980545,0.405988603830338
16 | Costa Rica,7.0789999961853,1.10970628261566,0.759509265422821,0.580131649971008
17 | Austria,7.00600004196167,1.48709726333618,0.81532841920852706,0.567766189575195
18 | United States,6.99300003051758,1.54625928401947,0.77428662776947,0.505740523338318
19 | Ireland,6.97700023651123,1.53570663928986,0.80978262424469,0.573110342025757
20 | Germany,6.95100021362305,1.48792338371277,0.798950731754303,0.562511384487152
21 | Belgium,6.89099979400635,1.46378076076508,0.818091869354248,0.539770722389221
22 | Luxembourg,6.86299991607666,1.74194359779358,0.845089495182037,0.59662789106369
23 | United Kingdom,6.71400022506714,1.44163393974304,0.805335938930511,0.508190035820007
24 | Chile,6.65199995040894,1.25278460979462,0.819479703903198,0.376895278692245
25 | United Arab Emirates,6.64799976348877,1.62634336948395,0.726798236370087,0.60834527015686
26 | Brazil,6.63500022888184,1.10735321044922,0.616552352905273,0.437453746795654
27 | Czech Republic,6.60900020599365,1.35268235206604,0.754444003105164,0.490946173667908
28 | Argentina,6.59899997711182,1.18529546260834,0.695137083530426,0.494519203901291
29 | Mexico,6.57800006866455,1.15318381786346,0.709978997707367,0.412730008363724
30 | Singapore,6.57200002670288,1.69227766990662,0.949492394924164,0.549840569496155
31 | Malta,6.52699995040894,1.34327983856201,0.821944236755371,0.588767051696777
32 | Uruguay,6.4539999961853,1.21755969524384,0.719216823577881,0.57939225435257
33 | Guatemala,6.4539999961853,0.872001945972443,0.540239989757538,0.531310617923737
34 | Panama,6.4520001411438,1.23374843597412,0.706156134605408,0.550026834011078
35 | France,6.44199991226196,1.43092346191406,0.844465851783752,0.470222115516663
36 | Thailand,6.42399978637695,1.12786877155304,0.647239029407501,0.580200731754303
37 | Taiwan Province of China,6.42199993133545,1.43362653255463,0.793984234333038,0.361466586589813
38 | Spain,6.40299987792969,1.38439786434174,0.888960599899292,0.408781230449677
39 | Qatar,6.375,1.87076568603516,0.710098087787628,0.604130983352661
40 | Colombia,6.35699987411499,1.07062232494354,0.595027923583984,0.477487415075302
41 | Saudi Arabia,6.3439998626709,1.53062355518341,0.590148329734802,0.449750572443008
42 | Trinidad and Tobago,6.16800022125244,1.36135590076447,0.519983291625977,0.518630743026733
43 | Kuwait,6.10500001907349,1.63295245170593,0.632105708122253,0.496337592601776
44 | Slovakia,6.09800004959106,1.32539355754852,0.712732911109924,0.295817464590073
45 | Bahrain,6.08699989318848,1.48841226100922,0.653133034706116,0.536746919155121
46 | Malaysia,6.08400011062622,1.29121541976929,0.618784427642822,0.402264982461929
47 | Nicaragua,6.07100009918213,0.737299203872681,0.653095960617065,0.447551846504211
48 | Ecuador,6.00799989700317,1.00082039833069,0.685636222362518,0.4551981985569
49 | El Salvador,6.00299978256226,0.909784495830536,0.596018552780151,0.432452529668808
50 | Poland,5.97300004959106,1.29178786277771,0.699475347995758,0.520342111587524
51 | Uzbekistan,5.97100019454956,0.786441087722778,0.498272627592087,0.658248662948608
52 | Italy,5.96400022506714,1.39506661891937,0.853144347667694,0.256450712680817
53 | Russia,5.96299982070923,1.28177809715271,0.547349333763123,0.373783111572266
54 | Belize,5.95599985122681,0.907975316047668,0.450191766023636,0.547509372234344
55 | Japan,5.92000007629395,1.41691517829895,0.913475871086121,0.505625545978546
56 | Lithuania,5.90199995040894,1.31458234786987,0.62894994020462,0.234231784939766
57 | Algeria,5.87200021743774,1.09186446666718,0.617584645748138,0.233335807919502
58 | Latvia,5.84999990463257,1.26074862480164,0.638566970825195,0.325707912445068
59 | South Korea,5.83799982070923,1.40167844295502,0.900214076042175,0.257921665906906
60 | Moldova,5.83799982070923,0.728870630264282,0.589465200901031,0.240729048848152
61 | Romania,5.82499980926514,1.21768391132355,0.685158312320709,0.457003742456436
62 | Bolivia,5.82299995422363,0.833756566047668,0.473630249500275,0.558732926845551
63 | Turkmenistan,5.82200002670288,1.13077676296234,0.437726080417633,0.41827192902565
64 | Kazakhstan,5.81899976730347,1.28455626964569,0.606041550636292,0.437454283237457
65 | North Cyprus,5.80999994277954,1.3469113111496,0.834647238254547,0.471203625202179
66 | Slovenia,5.75799989700317,1.3412059545517,0.790828227996826,0.572575807571411
67 | Peru,5.71500015258789,1.03522527217865,0.630166113376617,0.450002878904343
68 | Mauritius,5.62900018692017,1.18939554691315,0.638007462024689,0.491247326135635
69 | Cyprus,5.62099981307983,1.35593807697296,0.84471470117569,0.355111539363861
70 | Estonia,5.61100006103516,1.32087934017181,0.695168316364288,0.479131430387497
71 | Belarus,5.56899976730347,1.15655755996704,0.637714266777039,0.295400261878967
72 | Libya,5.52500009536743,1.10180306434631,0.520169019699097,0.465733230113983
73 | Turkey,5.5,1.19827437400818,0.637605607509613,0.300740599632263
74 | Paraguay,5.49300003051758,0.932537317276001,0.579250693321228,0.473507791757584
75 | "Hong Kong S.A.R., China",5.47200012207031,1.55167484283447,0.943062424659729,0.490968644618988
76 | Philippines,5.42999982833862,0.85769921541214,0.468009054660797,0.585214674472809
77 | Serbia,5.39499998092651,1.06931757926941,0.65078467130661,0.208715528249741
78 | Jordan,5.33599996566772,0.991012394428253,0.604590058326721,0.418421149253845
79 | Hungary,5.32399988174438,1.2860119342804,0.687763452529907,0.175863519310951
80 | Jamaica,5.31099987030029,0.925579309463501,0.641022384166718,0.474307239055634
81 | Croatia,5.29300022125244,1.22255623340607,0.701288521289825,0.255772292613983
82 | Kosovo,5.27899980545044,0.951484382152557,0.541452050209045,0.260287940502167
83 | China,5.27299976348877,1.08116579055786,0.741415500640869,0.472787708044052
84 | Pakistan,5.26900005340576,0.72688353061676,0.402047783136368,0.23521526157856
85 | Indonesia,5.26200008392334,0.995538592338562,0.492345720529556,0.443323463201523
86 | Venezuela,5.25,1.12843120098114,0.617144227027893,0.153997123241425
87 | Montenegro,5.23699998855591,1.12112903594971,0.667464673519135,0.194989055395126
88 | Morocco,5.2350001335144,0.878114581108093,0.59771066904068,0.408158332109451
89 | Azerbaijan,5.23400020599365,1.15360176563263,0.540775775909424,0.398155838251114
90 | Dominican Republic,5.23000001907349,1.07937383651733,0.574873745441437,0.55258983373642
91 | Greece,5.22700023651123,1.28948748111725,0.810198903083801,0.0957312509417534
92 | Lebanon,5.22499990463257,1.07498753070831,0.73508107662200906,0.288515985012054
93 | Portugal,5.19500017166138,1.3151752948761,0.795843541622162,0.498465299606323
94 | Bosnia and Herzegovina,5.18200016021729,0.982409417629242,0.705186307430267,0.204403176903725
95 | Honduras,5.18100023269653,0.730573117733002,0.582569479942322,0.348079860210419
96 | Macedonia,5.17500019073486,1.06457793712616,0.644948184490204,0.325905978679657
97 | Somalia,5.15100002288818,0.0226431842893362,0.113989137113094,0.602126955986023
98 | Vietnam,5.07399988174438,0.788547575473785,0.652168989181519,0.571055591106415
99 | Nigeria,5.07399988174438,0.783756256103516,0.0569157302379608,0.394952565431595
100 | Tajikistan,5.04099988937378,0.524713635444641,0.529235124588013,0.471566706895828
101 | Bhutan,5.01100015640259,0.885416388511658,0.495879292488098,0.501537680625916
102 | Kyrgyzstan,5.00400018692017,0.596220076084137,0.553457796573639,0.454943388700485
103 | Nepal,4.96199989318848,0.479820191860199,0.504130780696869,0.440305948257446
104 | Mongolia,4.95499992370605,1.02723586559296,0.557783484458923,0.394143968820572
105 | South Africa,4.8289999961853,1.05469870567322,0.187080070376396,0.479246735572815
106 | Tunisia,4.80499982833862,1.00726580619812,0.613212049007416,0.289680689573288
107 | Palestinian Territories,4.77500009536743,0.716249227523804,0.565666973590851,0.25471106171608
108 | Egypt,4.7350001335144,0.989701807498932,0.520187258720398,0.282110154628754
109 | Bulgaria,4.71400022506714,1.1614590883255,0.708217680454254,0.289231717586517
110 | Sierra Leone,4.70900011062622,0.36842092871666,0.00556475389748812,0.318697690963745
111 | Cameroon,4.69500017166138,0.564305365085602,0.132892116904259,0.430388748645782
112 | Iran,4.69199991226196,1.15687310695648,0.639333188533783,0.249322608113289
113 | Albania,4.64400005340576,0.996192753314972,0.731159746646881,0.381498634815216
114 | Bangladesh,4.60799980163574,0.586682975292206,0.533241033554077,0.478356659412384
115 | Namibia,4.57399988174438,0.964434325695038,0.33861181139946,0.520303547382355
116 | Kenya,4.55299997329712,0.560479462146759,0.309988349676132,0.452763766050339
117 | Mozambique,4.55000019073486,0.234305649995804,0.106654435396194,0.480791091918945
118 | Myanmar,4.54500007629395,0.367110550403595,0.397522568702698,0.514492034912109
119 | Senegal,4.53499984741211,0.479309022426605,0.409362852573395,0.377922266721725
120 | Zambia,4.51399993896484,0.636406779289246,0.257835894823074,0.461603492498398
121 | Iraq,4.49700021743774,1.10271048545837,0.50118046998977706,0.288555532693863
122 | Gabon,4.46500015258789,1.1982102394104,0.356578588485718,0.312328577041626
123 | Ethiopia,4.46000003814697,0.339233845472336,0.353409707546234,0.408842742443085
124 | Sri Lanka,4.44000005722046,1.00985014438629,0.625130832195282,0.561213254928589
125 | Armenia,4.37599992752075,0.900596737861633,0.637524425983429,0.198303267359734
126 | India,4.31500005722046,0.792221248149872,0.455427616834641,0.469987004995346
127 | Mauritania,4.29199981689453,0.648457288742065,0.285349279642105,0.0960980430245399
128 | Congo (Brazzaville),4.29099988937378,0.808964252471924,0.28995743393898,0.435025870800018
129 | Georgia,4.28599977493286,0.950612664222717,0.649546980857849,0.309410035610199
130 | Congo (Kinshasa),4.28000020980835,0.0921023488044739,0.191407024860382,0.235961347818375
131 | Mali,4.19000005722046,0.476180493831635,0.169365674257278,0.306613743305206
132 | Ivory Coast,4.17999982833862,0.603048920631409,0.0486421696841717,0.447706192731857
133 | Cambodia,4.16800022125244,0.601765096187592,0.429783403873444,0.633375823497772
134 | Sudan,4.13899993896484,0.65951669216156,0.290920823812485,0.0149958552792668
135 | Ghana,4.11999988555908,0.667224824428558,0.295637726783752,0.423026293516159
136 | Ukraine,4.09600019454956,0.89465194940567,0.575903952121735,0.122974775731564
137 | Uganda,4.08099985122681,0.381430715322495,0.217632606625557,0.443185955286026
138 | Burkina Faso,4.03200006484985,0.3502277135849,0.215844258666039,0.324367851018906
139 | Niger,4.02799987792969,0.161925330758095,0.26850500702858,0.36365869641304
140 | Malawi,3.97000002861023,0.233442038297653,0.315089583396912,0.466914653778076
141 | Chad,3.93600010871887,0.438012987375259,0.0411347150802612,0.16234202682972
142 | Zimbabwe,3.875,0.375846534967422,0.196763753890991,0.336384207010269
143 | Lesotho,3.80800008773804,0.521021246910095,0.0,0.390661299228668
144 | Angola,3.79500007629395,0.858428180217743,0.0498686656355858,0.0
145 | Afghanistan,3.79399991035461,0.401477217674255,0.180746778845787,0.106179520487785
146 | Botswana,3.76600003242493,1.12209415435791,0.341755509376526,0.505196332931519
147 | Benin,3.65700006484985,0.431085407733917,0.209930211305618,0.425962775945663
148 | Madagascar,3.64400005340576,0.305808693170547,0.375223308801651,0.189196765422821
149 | Haiti,3.6029999256134,0.368610262870789,0.277321130037308,0.0303698573261499
150 | Yemen,3.59299993515015,0.591683447360992,0.310080915689468,0.249463722109795
151 | South Sudan,3.59100008010864,0.39724862575531,0.163486003875732,0.147062435746193
152 | Liberia,3.53299999237061,0.119041793048382,0.229918196797371,0.332881182432175
153 | Guinea,3.50699996948242,0.244549930095673,0.194129139184952,0.348587512969971
154 | Togo,3.49499988555908,0.305444717407227,0.247105568647385,0.38042613863945
155 | Rwanda,3.47099995613098,0.368745893239975,0.326424807310104,0.581843852996826
156 | Syria,3.46199989318848,0.777153134346008,0.50053334236145,0.0815394446253777
157 | Tanzania,3.34899997711182,0.511135876178741,0.364509284496307,0.390017777681351
158 | Burundi,2.90499997138977,0.091622568666935,0.151610791683197,0.0599007532000542
159 | Central African Republic,2.69300007820129,0.0,0.0187726859003305,0.270842045545578
160 |
--------------------------------------------------------------------------------
/worksheet_regression2/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 |
4 | # Round double to precise integer
5 | #
6 | # `int_round` works to create an integer corresponding to a number that is
7 | # tested up to a particular decimal point of precision. This is useful when
8 | # there is a need to compare a numeric value using hashes.
9 | #
10 | # @param x Double vector of length one.
11 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
12 | #
13 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
14 | #
15 | # @examples
16 | # # to get an integer up to two decimals of precision from 234.56789
17 | # int_round(234.56789, 2)
18 | #
19 | # to get an integer rounded to the hundred digit from 234.56789
20 | # int_round(234.56789, -2)
21 | int_round <- function(x, digits){
22 | x = x * 10^digits
23 | xint = as.integer(x)
24 | xint1 = xint + 1L
25 | if (abs(xint - x) < abs(xint1 - x)){
26 | return(xint)
27 | }
28 | else {
29 | return(xint1)
30 | }
31 | }
32 |
33 | test_1.0 <- function() {
34 | test_that('Did not create an object named answer1.0', {
35 | expect_true(exists('answer1.0'))
36 | })
37 | test_that('Solution is incorrect', {
38 | expect_equal(digest(answer1.0), '3a5505c06543876fe45598b5e5e5195d')
39 | })
40 | print("Success!")
41 | }
42 |
43 | test_1.1 <- function() {
44 | test_that('Did not create an object named answer1.1', {
45 | expect_true(exists('answer1.1'))
46 | })
47 | test_that('Solution is incorrect', {
48 | expect_equal(digest(answer1.1), '475bf9280aab63a82af60791302736f6')
49 | })
50 | print("Success!")
51 | }
52 |
53 | test_1.2 <- function() {
54 | test_that('Did not create an object named answer1.2', {
55 | expect_true(exists('answer1.2'))
56 | })
57 | test_that('Solution is incorrect', {
58 | expect_equal(digest(answer1.2), '75f1160e72554f4270c809f041c7a776')
59 | })
60 | print("Success!")
61 | }
62 |
63 | test_2.0 <- function() {
64 | test_that('Did not create an object named answer2.0', {
65 | expect_true(exists('answer2.0'))
66 | })
67 | test_that('Solution is incorrect', {
68 | expect_equal(digest(int_round(answer2.0, 2)), '9a6564e67167bff7e7cf99a541a641f1')
69 | })
70 | print("Success!")
71 | }
72 |
73 | test_2.1 <- function() {
74 | test_that('Did not create an object named answer2.1', {
75 | expect_true(exists('answer2.1'))
76 | })
77 | test_that('Solution is incorrect', {
78 | expect_equal(digest(int_round(answer2.1, 2)), '9a6564e67167bff7e7cf99a541a641f1')
79 | })
80 | print("Success!")
81 | }
82 |
83 | test_2.2 <- function() {
84 | test_that('Did not create an object named answer2.2', {
85 | expect_true(exists('answer2.2'))
86 | })
87 | test_that('Solution is incorrect', {
88 | expect_equal(digest(int_round(answer2.2, 2)), '40755f30599581bfb1186f077db8f580')
89 | })
90 | print("Success!")
91 | }
92 |
93 | test_2.3 <- function() {
94 | test_that('Did not create an object named answer2.3', {
95 | expect_true(exists('answer2.3'))
96 | })
97 | test_that('Solution is incorrect', {
98 | expect_equal(digest(answer2.3), '475bf9280aab63a82af60791302736f6')
99 | })
100 | print("Success!")
101 | }
102 |
103 | test_3.0 <- function() {
104 | test_that('Did not create an object named marathon', {
105 | expect_true(exists("marathon"))
106 | })
107 | test_that('marathon should be a tibble.', {
108 | expect_true('tbl' %in% class(marathon))
109 | })
110 | test_that('marathon does not contain the correct number of rows and/or columns.', {
111 | expect_equal(dim(marathon), c(929, 13))
112 | })
113 | test_that('The marathon tibble does not contain the correct columns.', {
114 | expect_true("time_hrs" %in% colnames(marathon))
115 | expect_true("max" %in% colnames(marathon))
116 | })
117 | test_that('marathon contains the wrong data', {
118 | expect_equal(digest(int_round(sum(marathon$max), 0)), 'b64d424699e3efa872a878b15e4615fc')
119 | expect_equal(digest(int_round(sum(marathon$time_hrs), 0)), '0a386b4fbb992709ee886a69c311a49c')
120 | })
121 | print("Success!")
122 | }
123 |
124 | test_3.1 <- function() {
125 | test_that('Did not create an object named marathon_split', {
126 | expect_true(exists('marathon_split'))
127 | })
128 | test_that('marathon_split is not a split object (not a tibble)', {
129 | expect_true('rsplit' %in% class(marathon_split))
130 | })
131 | test_that('marathon_split does not contain marathon data', {
132 | expect_equal(dim(marathon_split$data), c(929, 13))
133 | expect_equal(digest(int_round(sum(marathon_split$data$max), 0)), 'b64d424699e3efa872a878b15e4615fc')
134 | expect_equal(digest(int_round(sum(marathon_split$data$time_hrs), 0)), '0a386b4fbb992709ee886a69c311a49c')
135 | })
136 | test_that('Did not create an object named marathon_training', {
137 | expect_true(exists('marathon_training'))
138 | })
139 | test_that('marathon_training is not a tibble', {
140 | expect_true('tbl' %in% class(marathon_training))
141 | })
142 | test_that('marathon_training does not contain 0.75 of the marathon data', {
143 | expect_equal(dim(marathon_training), c(696, 13))
144 | expect_equal(digest(int_round(sum(marathon_training$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
145 | expect_equal(digest(int_round(sum(marathon_training$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
146 | })
147 | test_that('Did not create an object named marathon_testing', {
148 | expect_true(exists('marathon_testing'))
149 | })
150 | test_that('marathon_testing is not a tibble', {
151 | expect_true('tbl' %in% class(marathon_testing))
152 | })
153 | test_that('marathon testing does not contain 0.25 of the marathon data', {
154 | expect_equal(dim(marathon_testing), c(233, 13))
155 | expect_equal(digest(int_round(sum(marathon_testing$max), 0)), 'bdb6d3e7a37786e1e246c0b54e3f7edd')
156 | expect_equal(digest(int_round(sum(marathon_testing$time_hrs), 0)), '6004c9f968d35059ea6d8f9eb654e09a')
157 | })
158 | print("Success!")
159 | }
160 |
161 | test_3.2 <- function() {
162 | properties <- c(marathon_eda$layers[[1]]$mapping, marathon_eda$mapping)
163 | labels <- marathon_eda$labels
164 | layers <- marathon_eda$layers[[1]]
165 | test_that('Did not create a plot named marathon_eda', {
166 | expect_true(exists("marathon_eda"))
167 | })
168 | test_that('max should be on the x-axis.', {
169 | expect_true("max" %in% c(rlang::get_expr(properties$x)))
170 | })
171 | test_that('time_hrs should be on the y-axis.', {
172 | expect_true("time_hrs" %in% c(rlang::get_expr(properties$y)))
173 | })
174 | test_that('marathon_eda should be a scatter plot.', {
175 | expect_equal(digest(class(rlang::get_expr(layers$geom))[1]), '911e5b9debfb523f25ad2ccc01a4b2dd')
176 | })
177 | test_that('Labels on the axes should be descriptive and human readable.', {
178 | expect_false((labels$y) == 'time_hrs')
179 | expect_false((labels$x) == 'max')
180 | })
181 | test_that('Only the training data set should be used to create the plot', {
182 | expect_equal(int_round(nrow(marathon_eda$data), 0), 696)
183 | })
184 | print("Success!")
185 | }
186 |
187 | test_3.3 <- function() {
188 | test_that('Did not create an object named lm_spec', {
189 | expect_true(exists("lm_spec"))
190 | })
191 | test_that('lm_spec is not a linear regression model', {
192 | expect_true('linear_reg' %in% class(lm_spec))
193 | })
194 | test_that('lm_spec does not contain the correct specifications', {
195 | expect_equal(digest(as.character(lm_spec$mode)), 'b8bdd7015e0d1c6037512fd1396aef1a')
196 | expect_equal(digest(as.character(lm_spec$engine)), '0995419f6f003f701c545d050292f42d')
197 | })
198 | print("Success!")
199 | }
200 |
201 | test_3.3.1 <- function() {
202 | test_that('Did not create an object named lm_recipe', {
203 | expect_true(exists('lm_recipe'))
204 | })
205 | test_that('lm_recipe is not a recipe', {
206 | expect_true('recipe' %in% class(lm_recipe))
207 | })
208 | test_that('lm_recipe does not contain the correct variables', {
209 | expect_equal(digest(int_round(sum(lm_recipe$template$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
210 | expect_equal(digest(int_round(sum(lm_recipe$template$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
211 | })
212 | test_that('Did not create an object named lm_fit', {
213 | expect_true(exists('lm_fit'))
214 | })
215 | test_that('lm_fit is not a workflow', {
216 | expect_true('workflow' %in% class(lm_fit))
217 | })
218 | test_that('lm_fit does not contain the correct data', {
219 | expect_equal(digest(int_round(sum(lm_fit$pre$actions$recipe$recipe$template$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
220 | expect_equal(digest(int_round(sum(lm_fit$pre$actions$recipe$recipe$template$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
221 | })
222 | test_that('lm_fit coefficients are incorrect', {
223 | expect_equal(digest(int_round(sum(lm_fit$fit$fit$fit$coefficients), 1)), '754bc61780613e9dbb928b88e1e3d6f5')
224 | })
225 | print("Success!")
226 | }
227 |
228 | test_3.4 <- function() {
229 | properties <- c(lm_predictions$layers[[1]]$mapping, lm_predictions$mapping)
230 | labels <- lm_predictions$labels
231 | layers <- c(lm_predictions$layers[[1]], lm_predictions$layers[[2]])
232 | layers2 <- c(lm_predictions$layers[[2]], lm_predictions$layers[[1]])
233 | test_that('Did not create a plot named lm_predictions', {
234 | expect_true(exists("lm_predictions"))
235 | })
236 | test_that('max should be on the x-axis.', {
237 | expect_true("max" %in% c(rlang::get_expr(properties$x)))
238 | })
239 | test_that('time_hrs should be on the y-axis.', {
240 | expect_true("time_hrs" %in% c(rlang::get_expr(properties$y)))
241 | })
242 | test_that('lm_predictions should be a scatter plot.', {
243 | expect_true('GeomPoint' %in% c(class(rlang::get_expr(lm_predictions$layers[[1]]$geom)),
244 | class(rlang::get_expr(lm_predictions$layers[[2]]$geom))))
245 |
246 | })
247 | test_that('lm_predictions should have a best fit line using a linear regression model.', {
248 | expect_true('GeomLine' %in% c(class(rlang::get_expr(lm_predictions$layers[[2]]$geom)),
249 | class(rlang::get_expr(lm_predictions$layers[[1]]$geom))))
250 | })
251 | test_that('Labels on the axes should be descriptive and human readable.', {
252 | expect_false((labels$y) == 'time_hrs')
253 | expect_false((labels$x) == 'max')
254 | })
255 | print("Success!")
256 | }
257 |
258 | test_3.5 <- function() {
259 | test_that('Did not create an object named lm_test_results', {
260 | expect_true(exists('lm_test_results'))
261 | })
262 | test_that('lm_test_results is not a tibble', {
263 | expect_true('tbl' %in% class(lm_test_results))
264 | })
265 | test_that('lm_test_results does not contain the correct data', {
266 | expect_equal(dim(lm_test_results), c(3, 3))
267 | expect_equal(digest(int_round(sum(lm_test_results$.estimate), 1)), '8ae1ac7bdf62dca7c19b427a9153445c')
268 | })
269 | test_that('Did not create an object named lm_rmspe', {
270 | expect_true(exists('lm_rmspe'))
271 | })
272 | test_that('lm_rmspe is not a numeric', {
273 | expect_true('numeric' %in% class(lm_rmspe))
274 | })
275 | test_that('lm_rmspe is not correct', {
276 | expect_equal(digest(int_round(lm_rmspe, 1)), '25e6a154090e35101d7678d6f034353a')
277 | })
278 | print("Success!")
279 | }
280 |
281 | test_3.5.1 <- function() {
282 | properties <- c(lm_predictions_test$mapping, lm_predictions_test$layers[[1]]$mapping)
283 | labels <- lm_predictions_test$labels
284 | layers <- lm_predictions_test$layers[[1]]
285 | test_that('Did not create a plot named lm_predictions_test', {
286 | expect_true(exists("lm_predictions_test"))
287 | })
288 | test_that('max should be on the x-axis.', {
289 | expect_true("max" %in% c(rlang::get_expr(properties$x)))
290 | })
291 | test_that('time_hrs should be on the y-axis.', {
292 | expect_true("time_hrs" %in% c(rlang::get_expr(properties$y)))
293 | })
294 | test_that('lm_predictions_test should be a scatter plot.', {
295 | expect_true(digest(class(rlang::get_expr(layers$geom))[1]) %in% c('911e5b9debfb523f25ad2ccc01a4b2dd','0c6e70bfd48a569f370e3a4dcae5dc1c'))
296 | })
297 | test_that('Labels on the axes should be descriptive and human readable.', {
298 | expect_false((labels$y) == 'time_hrs')
299 | expect_false((labels$x) == 'max')
300 | })
301 | test_that('Only the testing data set should be used to create the plot', {
302 | expect_equal(int_round(nrow(lm_predictions_test$data), 0), 233)
303 | })
304 | print("Success!")
305 | }
306 |
307 | test_3.6 <- function() {
308 | test_that('Did not create an object named answer3.6', {
309 | expect_true(exists('answer3.6'))
310 | })
311 | test_that('Solution is incorrect', {
312 | expect_equal(digest(answer3.6), '75f1160e72554f4270c809f041c7a776')
313 | })
314 | print("Success!")
315 | }
316 |
317 | test_3.7 <- function() {
318 | test_that('Did not create an object named answer3.7', {
319 | expect_true(exists('answer3.7'))
320 | })
321 | test_that('Solution is incorrect', {
322 | expect_equal(digest(answer3.7), '3a5505c06543876fe45598b5e5e5195d')
323 | })
324 | print("Success!")
325 | }
326 |
327 | test_3.8.1 <- function() {
328 | test_that('Did not create an object named answer3.8.1', {
329 | expect_true(exists('answer3.8.1'))
330 | })
331 | test_that('Solution is incorrect', {
332 | expect_equal(digest(answer3.8.1), '75f1160e72554f4270c809f041c7a776')
333 | })
334 | print("Success!")
335 | }
336 |
--------------------------------------------------------------------------------
/worksheet_inference1/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 |
4 | # Round double to precise integer
5 | #
6 | # `int_round` works to create an integer corresponding to a number that is
7 | # tested up to a particular decimal point of precision. This is useful when
8 | # there is a need to compare a numeric value using hashes.
9 | #
10 | # @param x Double vector of length one.
11 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
12 | #
13 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
14 | #
15 | # @examples
16 | # # to get an integer up to two decimals of precision from 234.56789
17 | # int_round(234.56789, 2)
18 | #
19 | # to get an integer rounded to the hundred digit from 234.56789
20 | # int_round(234.56789, -2)
21 | int_round <- function(x, digits){
22 | x = x * 10^digits
23 | xint = as.integer(x)
24 | xint1 = xint + 1L
25 | if (abs(xint - x) < abs(xint1 - x)){
26 | return(xint)
27 | }
28 | else {
29 | return(xint1)
30 | }
31 | }
32 |
33 | # function to extract attributes from cowplot objects
34 | # source: https://stackoverflow.com/questions/54051576/extracting-individual-plot-details-from-combined-plot-in-cowplot-for-unit-test?answertab=votes#tab-top
35 | fun <- function(p, what) {
36 | unlist(sapply(p$layers, function(x) {
37 | idx <- which(x$geom_params$grob$layout$name == what)
38 | x$geom_params$grob$grobs[[idx]]$children[[1]]$label
39 | }))
40 | }
41 |
42 | test_1.0 <- function(){
43 | test_that('Solution is incorrect', {
44 | expect_equal(digest(answer1.0), '3a5505c06543876fe45598b5e5e5195d')
45 | })
46 | print("Success!")
47 | }
48 |
49 | test_1.1 <- function(){
50 | test_that('variables should be assigned numeric values (do not include the definition in your answer, just the number associated with the definition)', {
51 | values <- c(point_estimate, population, random_sampling, representative_sampling, population_parameter, sample, observation, sampling_distribution)
52 | expect_is(values, 'numeric')
53 | })
54 |
55 | test_that('At least one term-definition match is incorrect', {
56 | expect_equal(digest(int_round(point_estimate, 0)), '25e6a154090e35101d7678d6f034353a')
57 | expect_equal(digest(int_round(population, 0)), '4b5630ee914e848e8d07221556b0a2fb')
58 | expect_equal(digest(int_round(random_sampling, 0)), 'c01f179e4b57ab8bd9de309e6d576c48')
59 | expect_equal(digest(int_round(representative_sampling, 0)), '7c7124efff5c7039a1b1e7cba65c5379')
60 | expect_equal(digest(int_round(population_parameter, 0)), '11946e7a3ed5e1776e81c0f0ecd383d0')
61 | expect_equal(digest(int_round(sample, 0)), 'dd4ad37ee474732a009111e3456e7ed7')
62 | expect_equal(digest(int_round(observation, 0)), '9d08099943f8627959cfb8ecee0d2f5d')
63 | expect_equal(digest(int_round(sampling_distribution, 0)), '234a2a5581872457b9fe1187d1616b13')
64 | })
65 | print("Success!")
66 | }
67 |
68 | test_1.2 <- function(){
69 | properties <- c(pop_dist$layers[[1]]$mapping, pop_dist$mapping)
70 | labels <- pop_dist$labels
71 | test_that('age should be on the x-axis.', {
72 | expect_true("age" == rlang::get_expr(properties$x))
73 | })
74 | test_that('pop_dist should be a histogram.', {
75 | expect_true("GeomBar" %in% class(pop_dist$layers[[1]]$geom))
76 | })
77 | test_that('can_seniors data should be used to create the histogram', {
78 | expect_equal(int_round(nrow(pop_dist$data), 0), 1027941)
79 | expect_equal(digest(int_round(sum(pop_dist$data$age), 0)), '0a65b77971cd131982c7117a5ab90242')
80 | })
81 | test_that('Labels on the x axis should be descriptive and human readable.', {
82 | expect_false((labels$x) == 'age')
83 | })
84 | print("Success!")
85 | }
86 |
87 | test_1.3 <- function(){
88 | test_that('pop_parameters has 3 columns and one row, with column names pop_mean, pop_med and pop_sd.', {
89 | expect_equal(int_round(nrow(pop_parameters), 0), 1)
90 | expect_equal(int_round(ncol(pop_parameters), 0), 3)
91 | expect_equal(digest(paste(sort(colnames(pop_parameters)), collapse = "")), '723d282ea6dad216da6b1074ca7cf688')
92 | })
93 | print("Success!")
94 | }
95 |
96 | test_1.4 <- function(){
97 | test_that('sample_1 should have 2 columns and 40 rows', {
98 | expect_equal(int_round(nrow(sample_1), 0), 40)
99 | expect_equal(int_round(ncol(sample_1), 0), 2)
100 | })
101 | test_that('the column names of sample_1 should be replicate and age', {
102 | expect_equal(digest(paste(sort(colnames(sample_1)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
103 | })
104 | print("Success!")
105 | }
106 |
107 | test_1.5 <- function(){
108 | properties <- c(sample_1_dist$layers[[1]]$mapping, sample_1_dist$mapping)
109 | labels <- sample_1_dist$labels
110 | test_that('age should be on the x-axis.', {
111 | expect_true("age" == rlang::get_expr(properties$x))
112 | })
113 | test_that('sample_1_dist should be a histogram.', {
114 | expect_true("GeomBar" %in% class(sample_1_dist$layers[[1]]$geom))
115 | })
116 | test_that('sample_1 data should be used to create the histogram', {
117 | expect_equal(int_round(nrow(sample_1_dist$data), 0), 40)
118 | expect_equal(digest(int_round(sum(sample_1_dist$data$age), 2)), 'f856ba7ffab8e669473a2ee7bf49de52')
119 | })
120 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
121 | expect_false((labels$x) == 'age')
122 | expect_false(is.null(labels$title))
123 | })
124 | print("Success!")
125 | }
126 |
127 | test_1.6 <- function(){
128 | test_that('sample_1_estimates should have at least 3 columns, and 1 row', {
129 | expect_equal(int_round(nrow(sample_1_estimates), 0), 1)
130 | expect_true(int_round(ncol(sample_1_estimates), 0) >= 3)
131 | })
132 | test_that('sample_1_estimates has columns with correct names', {
133 | expect_true("sample_1_mean" %in% colnames(sample_1_estimates))
134 | expect_true("sample_1_med" %in% colnames(sample_1_estimates))
135 | expect_true("sample_1_sd" %in% colnames(sample_1_estimates))
136 | })
137 | print("Success!")
138 | }
139 |
140 | test_1.7 <- function(){
141 | test_that('Solution is incorrect', {
142 | expect_equal(digest(answer1.7), '475bf9280aab63a82af60791302736f6')
143 | })
144 | print("Success!")
145 | }
146 |
147 |
148 | test_1.8.0 <- function(){
149 | test_that('sample_2 should have 2 columns and 40 rows', {
150 | expect_equal(int_round(nrow(sample_2), 0), 40)
151 | expect_equal(int_round(ncol(sample_2), 0), 2)
152 | })
153 | test_that('the column names of sample_2 should be replicate and age', {
154 | expect_equal(digest(paste(sort(colnames(sample_2)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
155 | })
156 | properties <- c(sample_2_dist$layers[[1]]$mapping, sample_2_dist$mapping)
157 | labels <- sample_2_dist$labels
158 | test_that('age should be on the x-axis.', {
159 | expect_true("age" == rlang::get_expr(properties$x))
160 | })
161 | test_that('sample_2_dist should be a histogram.', {
162 | expect_true("GeomBar" %in% class(sample_2_dist$layers[[1]]$geom))
163 | })
164 | test_that('sample_2 data should be used to create the histogram', {
165 | expect_equal(int_round(nrow(sample_2_dist$data), 0), 40)
166 | expect_equal(digest(int_round(sum(sample_2_dist$data$age), 2)), '199d472897c57c820c8c694f44d7786c')
167 | })
168 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
169 | expect_false((labels$x) == 'age')
170 | expect_false(is.null(labels$title))
171 | })
172 | test_that('sample_2_estimates should have at least 3 columns, and 1 row', {
173 | expect_equal(int_round(nrow(sample_2_estimates), 0), 1)
174 | expect_true(int_round(ncol(sample_2_estimates), 0) >= 3)
175 | })
176 | test_that('sample_2_estimates has columns with correct names', {
177 | expect_true("sample_2_mean" %in% colnames(sample_2_estimates))
178 | expect_true("sample_2_med" %in% colnames(sample_2_estimates))
179 | expect_true("sample_2_sd" %in% colnames(sample_2_estimates))
180 | })
181 | print("Success!")
182 | }
183 |
184 | test_1.8.1 <- function(){
185 | test_that('Solution is incorrect', {
186 | expect_equal(digest(answer1.8.1), '475bf9280aab63a82af60791302736f6')
187 | })
188 | print("Success!")
189 | }
190 |
191 | test_1.9 <- function(){
192 | test_that('samples should have 60000 rows and 2 columns', {
193 | expect_equal(int_round(ncol(samples), 0), 2)
194 | expect_equal(int_round(nrow(samples), 0), 60000)
195 | })
196 | test_that('the column names of samples should be replicate and age', {
197 | expect_equal(digest(paste(sort(colnames(samples)), collapse = "")), 'f4f0b2eff0a0eb0d22ac4df99afd13b7')
198 | })
199 | print("Success!")
200 | }
201 |
202 | test_2.0 <- function(){
203 | test_that('sample_estimates should have 1500 rows and 2 columns', {
204 | expect_equal(int_round(ncol(sample_estimates), 0), 2)
205 | expect_equal(int_round(nrow(sample_estimates), 0), 1500)
206 | })
207 | test_that('the column names of sample_estimates should be replicate and mean_age', {
208 | expect_equal(digest(paste(sort(colnames(sample_estimates)), collapse = "")), '8339e02a763670b945b364971d27d042')
209 | })
210 | print("Success!")
211 | }
212 |
213 | test_2.1 <- function(){
214 | properties <- c(sampling_distribution$layers[[1]]$mapping, sampling_distribution$mapping)
215 | labels <- sampling_distribution$labels
216 | test_that('mean_age should be on the x-axis.', {
217 | expect_true("mean_age" == rlang::get_expr(properties$x))
218 | })
219 | test_that('sampling_distribution should be a histogram.', {
220 | expect_true("GeomBar" %in% class(sampling_distribution$layers[[1]]$geom))
221 | })
222 | test_that('sampling_distribution data should be used to create the histogram', {
223 | expect_equal(int_round(nrow(sampling_distribution$data), 0), 1500)
224 | expect_equal(digest(int_round(sum(sampling_distribution$data$mean_age), 2)), 'e20a3a6689ccb7122ce8aaa71bab55bf')
225 | })
226 | test_that('Labels on the x axis should be descriptive. The plot should have a descriptive title.', {
227 | expect_false((labels$x) == 'mean_age')
228 | expect_false(is.null(labels$title))
229 | })
230 | print("Success!")
231 | }
232 |
233 | test_2.2 <- function(){
234 | test_that('Solution is incorrect', {
235 | expect_equal(digest(int_round(answer2.2, 2)), '0ddc7e7a0d2654650cba2f2a15cbca52')
236 | })
237 | print("Success!")
238 | }
239 |
240 | test_2.3 <- function(){
241 | test_that('Solution is incorrect', {
242 | expect_equal(digest(answer2.3), '3a5505c06543876fe45598b5e5e5195d')
243 | })
244 | print("Success!")
245 | }
246 |
247 | test_2.4 <- function(){
248 | test_that('Solution is incorrect', {
249 | expect_equal(digest(tolower(answer2.4)), '05ca18b596514af73f6880309a21b5dd')
250 | })
251 | print("Success!")
252 | }
253 |
254 | test_2.5 <- function(){
255 | properties <- c(sampling_distribution_20$layers[[1]]$mapping, sampling_distribution_20$mapping)
256 | labels <- sampling_distribution_20$labels
257 | test_that('mean_age should be on the x-axis.', {
258 | expect_true("mean_age" == rlang::get_expr(properties$x))
259 | })
260 | test_that('sampling_distribution should be a histogram.', {
261 | expect_true("GeomBar" %in% class(sampling_distribution_20$layers[[1]]$geom))
262 | })
263 | test_that('sampling_distribution data should be used to create the histogram', {
264 | expect_equal(int_round(nrow(sampling_distribution_20$data), 0), 1500)
265 | expect_equal(digest(int_round(sum(sampling_distribution_20$data$mean_age), 2)), '49a66adc63b05e7e8f90b66202de0b84')
266 | })
267 | test_that('Labels on the x axis should be descriptive.', {
268 | expect_false((labels$x) == 'age')
269 | })
270 | test_that('Plot title should be "Sampling Distribution (n=20) (just copy and paste that--careful with spaces!)"', {
271 | expect_true((labels$title) == 'Sampling Distribution (n=20)')
272 | })
273 |
274 | print("Success!")
275 | }
276 |
277 | test_2.6 <- function(){
278 | properties <- c(sampling_distribution_100$layers[[1]]$mapping, sampling_distribution_100$mapping)
279 | labels <- sampling_distribution_100$labels
280 | test_that('mean_age should be on the x-axis.', {
281 | expect_true("mean_age" == rlang::get_expr(properties$x))
282 | })
283 | test_that('sampling_distribution should be a histogram.', {
284 | expect_true("GeomBar" %in% class(sampling_distribution_100$layers[[1]]$geom))
285 | })
286 | test_that('sampling_distribution data should be used to create the histogram', {
287 | expect_equal(int_round(nrow(sampling_distribution_100$data), 0), 1500)
288 | expect_equal(digest(int_round(sum(sampling_distribution_100$data$mean_age), 2)), '59c92b151db8f38ba93a364fd62ae7c9')
289 | })
290 | test_that('Labels on the x axis should be descriptive.', {
291 | expect_false((labels$x) == 'age')
292 | })
293 | test_that('Plot title should be "Sampling Distribution (n=100) (just copy and paste that--careful with spaces!)"', {
294 | expect_true((labels$title) == 'Sampling Distribution (n=100)')
295 | })
296 |
297 | print("Success!")
298 | }
299 |
300 | test_2.7 <- function(){
301 | test_that('object is named sampling_distribution_panel.', {
302 | expect_true(exists("sampling_distribution_panel"))
303 | })
304 | test_that('sampling distributions are plotted side-by-side with the correct titles of "Sampling Distribution (n=20)", "Sampling Distribution (n=40)", and "Sampling Distribution (n=100)".', {
305 | expect_equal(fun(sampling_distribution_panel, "title"), c("Sampling Distribution (n=20)", "Sampling Distribution (n=40)", "Sampling Distribution (n=100)"))
306 | })
307 | print("Success!")
308 | }
309 |
310 | test_2.8 <- function(){
311 | test_that('Solution is incorrect', {
312 | expect_equal(digest(answer2.8), 'c1f86f7430df7ddb256980ea6a3b57a4')
313 | })
314 | print("Success!")
315 | }
316 |
317 | test_2.9 <- function(){
318 | test_that('Solution is incorrect', {
319 | expect_equal(digest(tolower(answer2.9)), 'd2a90307aac5ae8d0ef58e2fe730d38b')
320 | })
321 | print("Success!")
322 | }
323 |
--------------------------------------------------------------------------------
/worksheet_viz/data/world_vaccination.csv:
--------------------------------------------------------------------------------
1 | who_region,yr,pct_vaccinated,vaccine
2 | Africa,2017,71,polio
3 | Americas,2017,90,polio
4 | South-East Asia,2017,88,polio
5 | Europe,2017,93,polio
6 | Eastern Mediterranean,2017,81,polio
7 | Western Pacific,2017,97,polio
8 | (WHO) Global,2017,85,polio
9 | Africa,2016,70,polio
10 | Americas,2016,87,polio
11 | South-East Asia,2016,87,polio
12 | Europe,2016,94,polio
13 | Eastern Mediterranean,2016,81,polio
14 | Western Pacific,2016,95,polio
15 | (WHO) Global,2016,84,polio
16 | Africa,2015,71,polio
17 | Americas,2015,91,polio
18 | South-East Asia,2015,87,polio
19 | Europe,2015,94,polio
20 | Eastern Mediterranean,2015,79,polio
21 | Western Pacific,2015,96,polio
22 | (WHO) Global,2015,NA,polio
23 | Africa,2014,71,polio
24 | Americas,2014,90,polio
25 | South-East Asia,2014,85,polio
26 | Europe,2014,94,polio
27 | Eastern Mediterranean,2014,79,polio
28 | Western Pacific,2014,96,polio
29 | (WHO) Global,2014,NA,polio
30 | Africa,2013,70,polio
31 | Americas,2013,89,polio
32 | South-East Asia,2013,84,polio
33 | Europe,2013,96,polio
34 | Eastern Mediterranean,2013,79,polio
35 | Western Pacific,2013,96,polio
36 | (WHO) Global,2013,NA,polio
37 | Africa,2012,71,polio
38 | Americas,2012,93,polio
39 | South-East Asia,2012,82,polio
40 | Europe,2012,96,polio
41 | Eastern Mediterranean,2012,78,polio
42 | Western Pacific,2012,97,polio
43 | (WHO) Global,2012,NA,polio
44 | Africa,2011,71,polio
45 | Americas,2011,93,polio
46 | South-East Asia,2011,82,polio
47 | Europe,2011,95,polio
48 | Eastern Mediterranean,2011,79,polio
49 | Western Pacific,2011,97,polio
50 | (WHO) Global,2011,NA,polio
51 | Africa,2010,74,polio
52 | Americas,2010,93,polio
53 | South-East Asia,2010,80,polio
54 | Europe,2010,95,polio
55 | Eastern Mediterranean,2010,77,polio
56 | Western Pacific,2010,96,polio
57 | (WHO) Global,2010,NA,polio
58 | Africa,2009,75,polio
59 | Americas,2009,93,polio
60 | South-East Asia,2009,79,polio
61 | Europe,2009,95,polio
62 | Eastern Mediterranean,2009,76,polio
63 | Western Pacific,2009,97,polio
64 | (WHO) Global,2009,NA,polio
65 | Africa,2008,72,polio
66 | Americas,2008,94,polio
67 | South-East Asia,2008,75,polio
68 | Europe,2008,96,polio
69 | Eastern Mediterranean,2008,76,polio
70 | Western Pacific,2008,97,polio
71 | (WHO) Global,2008,NA,polio
72 | Africa,2007,71,polio
73 | Americas,2007,93,polio
74 | South-East Asia,2007,73,polio
75 | Europe,2007,96,polio
76 | Eastern Mediterranean,2007,76,polio
77 | Western Pacific,2007,93,polio
78 | (WHO) Global,2007,NA,polio
79 | Africa,2006,67,polio
80 | Americas,2006,94,polio
81 | South-East Asia,2006,72,polio
82 | Europe,2006,95,polio
83 | Eastern Mediterranean,2006,75,polio
84 | Western Pacific,2006,93,polio
85 | (WHO) Global,2006,NA,polio
86 | Africa,2005,65,polio
87 | Americas,2005,92,polio
88 | South-East Asia,2005,72,polio
89 | Europe,2005,95,polio
90 | Eastern Mediterranean,2005,77,polio
91 | Western Pacific,2005,88,polio
92 | (WHO) Global,2005,NA,polio
93 | Africa,2004,63,polio
94 | Americas,2004,92,polio
95 | South-East Asia,2004,66,polio
96 | Europe,2004,95,polio
97 | Eastern Mediterranean,2004,77,polio
98 | Western Pacific,2004,88,polio
99 | (WHO) Global,2004,NA,polio
100 | Africa,2003,61,polio
101 | Americas,2003,93,polio
102 | South-East Asia,2003,66,polio
103 | Europe,2003,91,polio
104 | Eastern Mediterranean,2003,76,polio
105 | Western Pacific,2003,88,polio
106 | (WHO) Global,2003,NA,polio
107 | Africa,2002,59,polio
108 | Americas,2002,92,polio
109 | South-East Asia,2002,66,polio
110 | Europe,2002,93,polio
111 | Eastern Mediterranean,2002,74,polio
112 | Western Pacific,2002,85,polio
113 | (WHO) Global,2002,NA,polio
114 | Africa,2001,55,polio
115 | Americas,2001,91,polio
116 | South-East Asia,2001,65,polio
117 | Europe,2001,94,polio
118 | Eastern Mediterranean,2001,75,polio
119 | Western Pacific,2001,85,polio
120 | (WHO) Global,2001,NA,polio
121 | Africa,2000,54,polio
122 | Americas,2000,91,polio
123 | South-East Asia,2000,64,polio
124 | Europe,2000,94,polio
125 | Eastern Mediterranean,2000,74,polio
126 | Western Pacific,2000,86,polio
127 | (WHO) Global,2000,NA,polio
128 | Africa,1999,52,polio
129 | Americas,1999,91,polio
130 | South-East Asia,1999,66,polio
131 | Europe,1999,93,polio
132 | Eastern Mediterranean,1999,74,polio
133 | Western Pacific,1999,86,polio
134 | (WHO) Global,1999,NA,polio
135 | Africa,1998,52,polio
136 | Americas,1998,89,polio
137 | South-East Asia,1998,67,polio
138 | Europe,1998,93,polio
139 | Eastern Mediterranean,1998,71,polio
140 | Western Pacific,1998,85,polio
141 | (WHO) Global,1998,NA,polio
142 | Africa,1997,54,polio
143 | Americas,1997,88,polio
144 | South-East Asia,1997,68,polio
145 | Europe,1997,93,polio
146 | Eastern Mediterranean,1997,68,polio
147 | Western Pacific,1997,85,polio
148 | (WHO) Global,1997,NA,polio
149 | Africa,1996,53,polio
150 | Americas,1996,86,polio
151 | South-East Asia,1996,71,polio
152 | Europe,1996,91,polio
153 | Eastern Mediterranean,1996,67,polio
154 | Western Pacific,1996,84,polio
155 | (WHO) Global,1996,NA,polio
156 | Africa,1995,54,polio
157 | Americas,1995,85,polio
158 | South-East Asia,1995,72,polio
159 | Europe,1995,89,polio
160 | Eastern Mediterranean,1995,69,polio
161 | Western Pacific,1995,82,polio
162 | (WHO) Global,1995,NA,polio
163 | Africa,1994,55,polio
164 | Americas,1994,81,polio
165 | South-East Asia,1994,70,polio
166 | Europe,1994,88,polio
167 | Eastern Mediterranean,1994,62,polio
168 | Western Pacific,1994,86,polio
169 | (WHO) Global,1994,NA,polio
170 | Africa,1993,50,polio
171 | Americas,1993,77,polio
172 | South-East Asia,1993,65,polio
173 | Europe,1993,85,polio
174 | Eastern Mediterranean,1993,64,polio
175 | Western Pacific,1993,88,polio
176 | (WHO) Global,1993,NA,polio
177 | Africa,1992,50,polio
178 | Americas,1992,76,polio
179 | South-East Asia,1992,60,polio
180 | Europe,1992,85,polio
181 | Eastern Mediterranean,1992,65,polio
182 | Western Pacific,1992,90,polio
183 | (WHO) Global,1992,NA,polio
184 | Africa,1991,51,polio
185 | Americas,1991,77,polio
186 | South-East Asia,1991,62,polio
187 | Europe,1991,81,polio
188 | Eastern Mediterranean,1991,67,polio
189 | Western Pacific,1991,92,polio
190 | (WHO) Global,1991,NA,polio
191 | Africa,1990,58,polio
192 | Americas,1990,74,polio
193 | South-East Asia,1990,67,polio
194 | Europe,1990,83,polio
195 | Eastern Mediterranean,1990,71,polio
196 | Western Pacific,1990,94,polio
197 | (WHO) Global,1990,NA,polio
198 | Africa,1989,51,polio
199 | Americas,1989,77,polio
200 | South-East Asia,1989,56,polio
201 | Europe,1989,81,polio
202 | Eastern Mediterranean,1989,66,polio
203 | Western Pacific,1989,92,polio
204 | (WHO) Global,1989,NA,polio
205 | Africa,1988,46,polio
206 | Americas,1988,80,polio
207 | South-East Asia,1988,39,polio
208 | Europe,1988,83,polio
209 | Eastern Mediterranean,1988,63,polio
210 | Western Pacific,1988,91,polio
211 | (WHO) Global,1988,NA,polio
212 | Africa,1987,43,polio
213 | Americas,1987,76,polio
214 | South-East Asia,1987,30,polio
215 | Europe,1987,83,polio
216 | Eastern Mediterranean,1987,54,polio
217 | Western Pacific,1987,76,polio
218 | (WHO) Global,1987,NA,polio
219 | Africa,1986,37,polio
220 | Americas,1986,72,polio
221 | South-East Asia,1986,21,polio
222 | Europe,1986,82,polio
223 | Eastern Mediterranean,1986,53,polio
224 | Western Pacific,1986,67,polio
225 | (WHO) Global,1986,NA,polio
226 | Africa,1985,32,polio
227 | Americas,1985,66,polio
228 | South-East Asia,1985,15,polio
229 | Europe,1985,91,polio
230 | Eastern Mediterranean,1985,48,polio
231 | Western Pacific,1985,82,polio
232 | (WHO) Global,1985,NA,polio
233 | Africa,1984,24,polio
234 | Americas,1984,72,polio
235 | South-East Asia,1984,12,polio
236 | Europe,1984,84,polio
237 | Eastern Mediterranean,1984,38,polio
238 | Western Pacific,1984,77,polio
239 | (WHO) Global,1984,NA,polio
240 | Africa,1983,19,polio
241 | Americas,1983,67,polio
242 | South-East Asia,1983,10,polio
243 | Europe,1983,81,polio
244 | Eastern Mediterranean,1983,30,polio
245 | Western Pacific,1983,74,polio
246 | (WHO) Global,1983,NA,polio
247 | Africa,1982,13,polio
248 | Americas,1982,66,polio
249 | South-East Asia,1982,8,polio
250 | Europe,1982,78,polio
251 | Eastern Mediterranean,1982,31,polio
252 | Western Pacific,1982,72,polio
253 | (WHO) Global,1982,NA,polio
254 | Africa,1981,11,polio
255 | Americas,1981,61,polio
256 | South-East Asia,1981,4,polio
257 | Europe,1981,79,polio
258 | Eastern Mediterranean,1981,24,polio
259 | Western Pacific,1981,7,polio
260 | (WHO) Global,1981,NA,polio
261 | Africa,1980,6,polio
262 | Americas,1980,66,polio
263 | South-East Asia,1980,3,polio
264 | Europe,1980,75,polio
265 | Eastern Mediterranean,1980,21,polio
266 | Western Pacific,1980,5,polio
267 | (WHO) Global,1980,NA,polio
268 | Africa,2017,72,hepatitis_b
269 | Americas,2017,90,hepatitis_b
270 | South-East Asia,2017,88,hepatitis_b
271 | Europe,2017,82,hepatitis_b
272 | Eastern Mediterranean,2017,81,hepatitis_b
273 | Western Pacific,2017,93,hepatitis_b
274 | (WHO) Global,2017,84,hepatitis_b
275 | Africa,2016,72,hepatitis_b
276 | Americas,2016,90,hepatitis_b
277 | South-East Asia,2016,88,hepatitis_b
278 | Europe,2016,81,hepatitis_b
279 | Eastern Mediterranean,2016,81,hepatitis_b
280 | Western Pacific,2016,93,hepatitis_b
281 | (WHO) Global,2016,84,hepatitis_b
282 | Africa,2015,72,hepatitis_b
283 | Americas,2015,89,hepatitis_b
284 | South-East Asia,2015,87,hepatitis_b
285 | Europe,2015,82,hepatitis_b
286 | Eastern Mediterranean,2015,79,hepatitis_b
287 | Western Pacific,2015,90,hepatitis_b
288 | (WHO) Global,2015,83,hepatitis_b
289 | Africa,2014,71,hepatitis_b
290 | Americas,2014,88,hepatitis_b
291 | South-East Asia,2014,82,hepatitis_b
292 | Europe,2014,81,hepatitis_b
293 | Eastern Mediterranean,2014,79,hepatitis_b
294 | Western Pacific,2014,91,hepatitis_b
295 | (WHO) Global,2014,81,hepatitis_b
296 | Africa,2013,70,hepatitis_b
297 | Americas,2013,89,hepatitis_b
298 | South-East Asia,2013,76,hepatitis_b
299 | Europe,2013,82,hepatitis_b
300 | Eastern Mediterranean,2013,79,hepatitis_b
301 | Western Pacific,2013,90,hepatitis_b
302 | (WHO) Global,2013,79,hepatitis_b
303 | Africa,2012,70,hepatitis_b
304 | Americas,2012,91,hepatitis_b
305 | South-East Asia,2012,77,hepatitis_b
306 | Europe,2012,81,hepatitis_b
307 | Eastern Mediterranean,2012,76,hepatitis_b
308 | Western Pacific,2012,93,hepatitis_b
309 | (WHO) Global,2012,80,hepatitis_b
310 | Africa,2011,71,hepatitis_b
311 | Americas,2011,91,hepatitis_b
312 | South-East Asia,2011,56,hepatitis_b
313 | Europe,2011,79,hepatitis_b
314 | Eastern Mediterranean,2011,78,hepatitis_b
315 | Western Pacific,2011,92,hepatitis_b
316 | (WHO) Global,2011,75,hepatitis_b
317 | Africa,2010,71,hepatitis_b
318 | Americas,2010,90,hepatitis_b
319 | South-East Asia,2010,54,hepatitis_b
320 | Europe,2010,78,hepatitis_b
321 | Eastern Mediterranean,2010,74,hepatitis_b
322 | Western Pacific,2010,91,hepatitis_b
323 | (WHO) Global,2010,73,hepatitis_b
324 | Africa,2009,72,hepatitis_b
325 | Americas,2009,91,hepatitis_b
326 | South-East Asia,2009,53,hepatitis_b
327 | Europe,2009,77,hepatitis_b
328 | Eastern Mediterranean,2009,73,hepatitis_b
329 | Western Pacific,2009,92,hepatitis_b
330 | (WHO) Global,2009,73,hepatitis_b
331 | Africa,2008,64,hepatitis_b
332 | Americas,2008,89,hepatitis_b
333 | South-East Asia,2008,47,hepatitis_b
334 | Europe,2008,77,hepatitis_b
335 | Eastern Mediterranean,2008,74,hepatitis_b
336 | Western Pacific,2008,89,hepatitis_b
337 | (WHO) Global,2008,69,hepatitis_b
338 | Africa,2007,64,hepatitis_b
339 | Americas,2007,89,hepatitis_b
340 | South-East Asia,2007,30,hepatitis_b
341 | Europe,2007,78,hepatitis_b
342 | Eastern Mediterranean,2007,73,hepatitis_b
343 | Western Pacific,2007,85,hepatitis_b
344 | (WHO) Global,2007,63,hepatitis_b
345 | Africa,2006,46,hepatitis_b
346 | Americas,2006,90,hepatitis_b
347 | South-East Asia,2006,27,hepatitis_b
348 | Europe,2006,75,hepatitis_b
349 | Eastern Mediterranean,2006,69,hepatitis_b
350 | Western Pacific,2006,85,hepatitis_b
351 | (WHO) Global,2006,58,hepatitis_b
352 | Africa,2005,42,hepatitis_b
353 | Americas,2005,89,hepatitis_b
354 | South-East Asia,2005,24,hepatitis_b
355 | Europe,2005,75,hepatitis_b
356 | Eastern Mediterranean,2005,67,hepatitis_b
357 | Western Pacific,2005,76,hepatitis_b
358 | (WHO) Global,2005,54,hepatitis_b
359 | Africa,2004,33,hepatitis_b
360 | Americas,2004,85,hepatitis_b
361 | South-East Asia,2004,19,hepatitis_b
362 | Europe,2004,73,hepatitis_b
363 | Eastern Mediterranean,2004,61,hepatitis_b
364 | Western Pacific,2004,72,hepatitis_b
365 | (WHO) Global,2004,49,hepatitis_b
366 | Africa,2003,28,hepatitis_b
367 | Americas,2003,83,hepatitis_b
368 | South-East Asia,2003,11,hepatitis_b
369 | Europe,2003,68,hepatitis_b
370 | Eastern Mediterranean,2003,61,hepatitis_b
371 | Western Pacific,2003,69,hepatitis_b
372 | (WHO) Global,2003,44,hepatitis_b
373 | Africa,2002,25,hepatitis_b
374 | Americas,2002,75,hepatitis_b
375 | South-East Asia,2002,10,hepatitis_b
376 | Europe,2002,63,hepatitis_b
377 | Eastern Mediterranean,2002,43,hepatitis_b
378 | Western Pacific,2002,59,hepatitis_b
379 | (WHO) Global,2002,38,hepatitis_b
380 | Africa,2001,6,hepatitis_b
381 | Americas,2001,72,hepatitis_b
382 | South-East Asia,2001,10,hepatitis_b
383 | Europe,2001,49,hepatitis_b
384 | Eastern Mediterranean,2001,42,hepatitis_b
385 | Western Pacific,2001,56,hepatitis_b
386 | (WHO) Global,2001,32,hepatitis_b
387 | Africa,2000,5,hepatitis_b
388 | Americas,2000,70,hepatitis_b
389 | South-East Asia,2000,10,hepatitis_b
390 | Europe,2000,42,hepatitis_b
391 | Eastern Mediterranean,2000,40,hepatitis_b
392 | Western Pacific,2000,48,hepatitis_b
393 | (WHO) Global,2000,29,hepatitis_b
394 | Africa,1999,4,hepatitis_b
395 | Americas,1999,48,hepatitis_b
396 | South-East Asia,1999,11,hepatitis_b
397 | Europe,1999,30,hepatitis_b
398 | Eastern Mediterranean,1999,37,hepatitis_b
399 | Western Pacific,1999,9,hepatitis_b
400 | (WHO) Global,1999,18,hepatitis_b
401 | Africa,1998,4,hepatitis_b
402 | Americas,1998,31,hepatitis_b
403 | South-East Asia,1998,11,hepatitis_b
404 | Europe,1998,28,hepatitis_b
405 | Eastern Mediterranean,1998,32,hepatitis_b
406 | Western Pacific,1998,8,hepatitis_b
407 | (WHO) Global,1998,16,hepatitis_b
408 | Africa,1997,4,hepatitis_b
409 | Americas,1997,28,hepatitis_b
410 | South-East Asia,1997,10,hepatitis_b
411 | Europe,1997,23,hepatitis_b
412 | Eastern Mediterranean,1997,35,hepatitis_b
413 | Western Pacific,1997,8,hepatitis_b
414 | (WHO) Global,1997,15,hepatitis_b
415 | Africa,1996,1,hepatitis_b
416 | Americas,1996,30,hepatitis_b
417 | South-East Asia,1996,10,hepatitis_b
418 | Europe,1996,20,hepatitis_b
419 | Eastern Mediterranean,1996,31,hepatitis_b
420 | Western Pacific,1996,9,hepatitis_b
421 | (WHO) Global,1996,14,hepatitis_b
422 | Africa,1995,NA,hepatitis_b
423 | Americas,1995,24,hepatitis_b
424 | South-East Asia,1995,8,hepatitis_b
425 | Europe,1995,12,hepatitis_b
426 | Eastern Mediterranean,1995,29,hepatitis_b
427 | Western Pacific,1995,9,hepatitis_b
428 | (WHO) Global,1995,11,hepatitis_b
429 | Africa,1994,NA,hepatitis_b
430 | Americas,1994,12,hepatitis_b
431 | South-East Asia,1994,7,hepatitis_b
432 | Europe,1994,9,hepatitis_b
433 | Eastern Mediterranean,1994,25,hepatitis_b
434 | Western Pacific,1994,3,hepatitis_b
435 | (WHO) Global,1994,8,hepatitis_b
436 | Africa,1993,NA,hepatitis_b
437 | Americas,1993,5,hepatitis_b
438 | South-East Asia,1993,7,hepatitis_b
439 | Europe,1993,7,hepatitis_b
440 | Eastern Mediterranean,1993,7,hepatitis_b
441 | Western Pacific,1993,2,hepatitis_b
442 | (WHO) Global,1993,4,hepatitis_b
443 | Africa,1992,NA,hepatitis_b
444 | Americas,1992,NA,hepatitis_b
445 | South-East Asia,1992,4,hepatitis_b
446 | Europe,1992,6,hepatitis_b
447 | Eastern Mediterranean,1992,6,hepatitis_b
448 | Western Pacific,1992,2,hepatitis_b
449 | (WHO) Global,1992,3,hepatitis_b
450 | Africa,1991,NA,hepatitis_b
451 | Americas,1991,NA,hepatitis_b
452 | South-East Asia,1991,NA,hepatitis_b
453 | Europe,1991,4,hepatitis_b
454 | Eastern Mediterranean,1991,4,hepatitis_b
455 | Western Pacific,1991,2,hepatitis_b
456 | (WHO) Global,1991,1,hepatitis_b
457 | Africa,1990,NA,hepatitis_b
458 | Americas,1990,NA,hepatitis_b
459 | South-East Asia,1990,NA,hepatitis_b
460 | Europe,1990,NA,hepatitis_b
461 | Eastern Mediterranean,1990,3,hepatitis_b
462 | Western Pacific,1990,2,hepatitis_b
463 | (WHO) Global,1990,1,hepatitis_b
464 | Africa,1989,NA,hepatitis_b
465 | Americas,1989,NA,hepatitis_b
466 | South-East Asia,1989,NA,hepatitis_b
467 | Europe,1989,NA,hepatitis_b
468 | Eastern Mediterranean,1989,NA,hepatitis_b
469 | Western Pacific,1989,1,hepatitis_b
470 | (WHO) Global,1989,NA,hepatitis_b
471 |
--------------------------------------------------------------------------------
/worksheet_clustering/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 | library(rlang)
4 |
5 | # Round double to precise integer
6 | #
7 | # `int_round` works to create an integer corresponding to a number that is
8 | # tested up to a particular decimal point of precision. This is useful when
9 | # there is a need to compare a numeric value using hashes.
10 | #
11 | # @param x Double vector of length one.
12 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
13 | #
14 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
15 | #
16 | # @examples
17 | # # to get an integer up to two decimals of precision from 234.56789
18 | # int_round(234.56789, 2)
19 | #
20 | # to get an integer rounded to the hundred digit from 234.56789
21 | # int_round(234.56789, -2)
22 | int_round <- function(x, digits){
23 | x = x * 10^digits
24 | xint = as.integer(x)
25 | xint1 = xint + 1L
26 | if (abs(xint - x) < abs(xint1 - x)){
27 | return(xint)
28 | }
29 | else {
30 | return(xint1)
31 | }
32 | }
33 |
34 | test_0.0 <- function(){
35 | test_that('Solution is incorrect', {
36 | expect_equal(digest(answer0.0), '01a75cb73d67b0f895ff0e61449c7bf8')
37 | })
38 | print("Success!")
39 | }
40 | test_0.1 <- function(){
41 | test_that('Solution is incorrect', {
42 | expect_true(digest(answer0.1) == 'd19d62a873f08af0488f0df720cfd293' ||
43 | digest(answer0.1) == 'e5b57f323c7b3719bbaaf9f96b260d39')
44 | })
45 | print("Success!")
46 | }
47 |
48 | test_1.0 <- function(){
49 | test_that('Did not create an object named beer', {
50 | expect_true(exists("beer"))
51 | })
52 | test_that('beer should be a tibble.', {
53 | expect_true('tbl' %in% class(beer))
54 | })
55 | test_that('beer does not contain the correct number of rows and/or columns.', {
56 | expect_equal(dim(beer), c(2410, 8))
57 | })
58 | test_that('The beer tibble is missing columns.', {
59 | expect_true("abv" %in% colnames(beer))
60 | expect_true("ibu" %in% colnames(beer))
61 | expect_true("id" %in% colnames(beer))
62 | expect_true("name" %in% colnames(beer))
63 | expect_true("style" %in% colnames(beer))
64 | expect_true("brewery_id" %in% colnames(beer))
65 | expect_true("ounces" %in% colnames(beer))
66 | })
67 | print("Success!")
68 | }
69 |
70 | test_1.1 <- function(){
71 | test_that('Did not create a plot named beer_plot', {
72 | expect_true(exists("beer_plot"))
73 | })
74 | properties <- c(beer_plot$layers[[1]]$mapping, beer_plot$mapping)
75 | labels <- beer_plot$labels
76 | test_that('ibu should be on the x-axis.', {
77 | expect_true("ibu" == rlang::get_expr(properties$x))
78 | })
79 | test_that('abv should be on the y-axis.', {
80 | expect_true("abv" == rlang::get_expr(properties$y))
81 | })
82 | test_that('beer_plot should be a scatter plot.', {
83 | expect_true("GeomPoint" %in% c(class(beer_plot$layers[[1]]$geom)))
84 | })
85 | test_that('Labels on the axes should be descriptive and human readable.', {
86 | expect_false((labels$y) == 'abv')
87 | expect_false((labels$x) == 'ibu')
88 | })
89 | print("Success!")
90 | }
91 |
92 | test_1.2 <- function(){
93 | test_that('Did not create an object named clean_beer', {
94 | expect_true(exists("clean_beer"))
95 | })
96 | test_that('clean_beer should be a tibble.', {
97 | expect_true('tbl' %in% class(clean_beer))
98 | })
99 | test_that('clean_beer should only contain the columns ibu and abv', {
100 | expect_true("ibu" %in% colnames(clean_beer))
101 | expect_true("abv" %in% colnames(clean_beer))
102 | expect_false("id" %in% colnames(clean_beer))
103 | expect_false("name" %in% colnames(clean_beer))
104 | expect_false("style" %in% colnames(clean_beer))
105 | expect_false("brewery_id" %in% colnames(clean_beer))
106 | expect_false("ounces" %in% colnames(clean_beer))
107 | })
108 | test_that('clean_beer does not contain the correct number of rows and/or columns.', {
109 | expect_equal(dim(clean_beer), c(1405, 2))
110 | })
111 |
112 | print("Success!")
113 | }
114 |
115 | test_1.3 <- function(){
116 | test_that('Solution is incorrect', {
117 | expect_equal(digest(answer1.3), '75f1160e72554f4270c809f041c7a776')
118 | })
119 | print("Success!")
120 | }
121 |
122 | test_1.4 <- function(){
123 | test_that('Did not create a object named kmeans_recipe', {
124 | expect_true(exists("kmeans_recipe"))
125 | })
126 | test_that('kmeans_recipe is not a recipe object', {
127 | expect_equal(digest(class(kmeans_recipe)), '4b3ed1334bff94d43e32a36a1f16a2f2')
128 | })
129 | test_that('kmeans_recipe does not standardize the data.', {
130 | expect_equal(dim(bake(prep(kmeans_recipe), clean_beer)), c(1405,2))
131 | expect_true(abs(mean(bake(prep(kmeans_recipe), clean_beer)$ibu)) < 1e-5)
132 | expect_true(abs(mean(bake(prep(kmeans_recipe), clean_beer)$abv)) < 1e-5)
133 | expect_true(abs(sd(bake(prep(kmeans_recipe), clean_beer)$ibu)-1.0) < 1e-5)
134 | expect_true(abs(sd(bake(prep(kmeans_recipe), clean_beer)$abv)-1.0) < 1e-5)
135 | })
136 | print("Success!")
137 | }
138 |
139 | test_1.5 <- function(){
140 | test_that('Did not create a object named kmeans_spec', {
141 | expect_true(exists("kmeans_spec"))
142 | })
143 | test_that('kmeans_spec class should be a k_means model specification', {
144 | expect_true("k_means" %in% class(kmeans_spec))
145 | expect_true("cluster_spec" %in% class(kmeans_spec))
146 | })
147 | test_that('kmeans_spec should specify to use 2 centers', {
148 | expect_equal(get_expr(kmeans_spec$args$num_clusters), 2)
149 | })
150 | test_that('kmeans_spec should use the "stats" engine', {
151 | expect_equal(kmeans_spec$engine, "stats")
152 | })
153 | print("Success!")
154 | }
155 |
156 | test_1.6 <- function(){
157 | test_that('Did not create a object named kmeans_fit', {
158 | expect_true(exists("kmeans_fit"))
159 | })
160 | test_that('kmeans_fit class should be a tidymodels workflow object', {
161 | expect_true("workflow" %in% class(kmeans_fit))
162 | })
163 | test_that('kmeans_fit has the wrong total within-cluster sum-of-squared distances',{
164 | expect_equal(digest(int_round(kmeans_fit$fit$fit$fit$tot.withinss, 2)), 'a3487cbd1a6cd4b181bb878433738a9f')
165 | })
166 | test_that('kmeans_fit must be a trained workflow. Remember to call the fit() function!', {
167 | expect_equal(digest(kmeans_fit$trained), 'bb73ad91bcb7e948250d465016f7bea8')
168 | })
169 | test_that('kmeans_fit has the wrong clustering', {
170 | expect_equal(digest(kmeans_fit$fit$fit$fit$cluster), '14f5153f8735994b439ae722cf451f77')
171 | })
172 | print("Success!")
173 | }
174 |
175 | test_1.7 <- function(){
176 | test_that('Did not create a object named labelled_beer', {
177 | expect_true(exists("labelled_beer"))
178 | })
179 | test_that('labelled_beer should be a tibble.', {
180 | expect_true('tbl' %in% class(labelled_beer))
181 | })
182 | test_that('labelled_beer should contain a column with cluster assignments named .pred_cluster',{
183 | expect_true('.pred_cluster' %in% colnames(labelled_beer))
184 | })
185 | test_that('labelled_beer should be the same as clean_beer except with an additional column of cluster assignments',{
186 | expect_equal(dim(select(labelled_beer, ibu, abv)), c(1405, 2))
187 | })
188 | }
189 |
190 | test_1.8 <- function(){
191 | properties <- c(cluster_plot$layers[[1]]$mapping, cluster_plot$mapping)
192 | labels <- cluster_plot$labels
193 | test_that('Did not create a plot named cluster_plot', {
194 | expect_true(exists("cluster_plot"))
195 | })
196 | test_that('cluster_plot should contain information from labelled_beer', {
197 | expect_equal(cluster_plot$data, labelled_beer)
198 | })
199 | test_that('ibu should be on the x-axis.', {
200 | expect_true("ibu" == rlang::get_expr(properties$x))
201 | })
202 | test_that('abv should be on the y-axis.', {
203 | expect_true("abv" == rlang::get_expr(properties$y))
204 | })
205 | test_that('.pred_cluster should be used to colour the points.', {
206 | expect_true(".pred_cluster" == rlang::get_expr(properties$colour))
207 | })
208 | test_that('cluster_plot should be a scatter plot.', {
209 | expect_true("GeomPoint" %in% c(class(cluster_plot$layers[[1]]$geom)))
210 | })
211 | test_that('Labels on the axes should be descriptive and human readable.', {
212 | expect_false((labels$y) == 'abv')
213 | expect_false((labels$x) == 'ibu')
214 | expect_false((labels$colour) == '.cluster')
215 | })
216 | print("Success!")
217 | }
218 |
219 | test_1.9.1 <- function(){
220 | test_that('Solution is incorrect', {
221 | expect_equal(digest(answer1.9.1), '475bf9280aab63a82af60791302736f6')
222 | })
223 | print("Success!")
224 | }
225 |
226 | test_1.9.2 <- function(){
227 | test_that('Did not create an object named clustering_stats', {
228 | expect_true(exists("clustering_stats"))
229 | })
230 | test_that('clustering_stats should be a tibble.', {
231 | expect_true('tbl' %in% class(clustering_stats))
232 | })
233 | test_that('clustering_stats should have 1 row of 4 different statistics.', {
234 | expect_equal(dim(clustering_stats), c(1, 4))
235 | })
236 | test_that('clustering_stats should contain total within sum of squares (tot.withinss).', {
237 | expect_true('tot.withinss' %in% colnames(clustering_stats))
238 | })
239 | test_that('clustering_stats should have the right total within sum of squares', {
240 | expect_equal(digest(int_round(clustering_stats$tot.withinss, 2)), 'a3487cbd1a6cd4b181bb878433738a9f')
241 | })
242 | print("Success!")
243 | }
244 |
245 | test_1.9.3 <- function(){
246 | test_that('Did not create an object named totalWSSD', {
247 | expect_true(exists("totalWSSD"))
248 | })
249 | test_that('The type of totalWSSD should be numeric.', {
250 | expect_equal('numeric', class(totalWSSD))
251 | })
252 | test_that('The value of totalWSSD is not correct.', {
253 | expect_equal(digest(int_round(totalWSSD, 2)), 'a3487cbd1a6cd4b181bb878433738a9f')
254 | })
255 | print("Success!")
256 | }
257 |
258 | test_2.0 <- function(){
259 | test_that('beer_ks should be a tbl.', {
260 | expect_true('tbl' %in% class(beer_ks))
261 | })
262 | test_that('beer_ks should have 1 column containing k values from 1 to 10.', {
263 | expect_equal(int_round(nrow(beer_ks), 0), 10)
264 | expect_equal(int_round(ncol(beer_ks), 0), 1)
265 | expect_equal(colnames(beer_ks), 'num_clusters')
266 | })
267 | print("Success!")
268 | }
269 |
270 | test_2.1 <- function(){
271 | test_that('Did not create a object named kmeans_spec_tune', {
272 | expect_true(exists("kmeans_spec_tune"))
273 | })
274 | test_that('kmeans_spec_tune class should be a k_means model specification', {
275 | expect_true("k_means" %in% class(kmeans_spec_tune))
276 | expect_true("cluster_spec" %in% class(kmeans_spec_tune))
277 | })
278 | test_that('kmeans_spec_tune should specify to tune the number of centers', {
279 | expect_equal(as.character(get_expr(kmeans_spec_tune$args$num_clusters)), 'tune')
280 | })
281 | test_that('kmeans_spec_tune should use the "stats" engine', {
282 | expect_equal(kmeans_spec_tune$engine, "stats")
283 | })
284 | test_that('kmeans_spec_tune should set nstart to 10',{
285 | expect_equal(get_expr(kmeans_spec_tune$eng_args$nstart), 10)
286 | })
287 | print("Success!")
288 | }
289 |
290 | test_2.2 <- function(){
291 | test_that('Did not create an object named kmeans_tuning_stats', {
292 | expect_true(exists("kmeans_tuning_stats"))
293 | })
294 | test_that('kmeans_tuning_stats should be a tibble.', {
295 | expect_true('tbl' %in% class(kmeans_tuning_stats))
296 | })
297 | test_that('kmeans_tuning_stats should have 2 rows for each value of K tested (20 rows total) and 7 columns.', {
298 | expect_equal(dim(kmeans_tuning_stats), c(20, 7))
299 | })
300 | test_that('kmeans_tuning_stats should have num_clusters, .metric, and mean in its column names.', {
301 | expect_true('.metric' %in% colnames(kmeans_tuning_stats))
302 | expect_true('mean' %in% colnames(kmeans_tuning_stats))
303 | expect_true('num_clusters' %in% colnames(kmeans_tuning_stats))
304 | })
305 | print("Success!")
306 | }
307 |
308 | test_2.3 <- function(){
309 | test_that('Did not create an object named tidy_tuning_stats', {
310 | expect_true(exists("tidy_tuning_stats"))
311 | })
312 | test_that('tidy_tuning_stats should be a tibble.', {
313 | expect_true('tbl' %in% class(tidy_tuning_stats))
314 | })
315 | test_that('tidy_tuning_stats should have 10 rows (one for each value of K) and 2 columns.', {
316 | expect_equal(dim(tidy_tuning_stats), c(10, 2))
317 | })
318 | test_that('tidy_tuning_stats should have two columns named num_clusters and total_WSSD.', {
319 | expect_true('num_clusters' %in% colnames(tidy_tuning_stats))
320 | expect_true('total_WSSD' %in% colnames(tidy_tuning_stats))
321 | })
322 | test_that('tidy_tuning_stats should have the numbers 1 through 10 in the num_clusters column',{
323 | expect_equal(digest(tidy_tuning_stats$num_clusters), 'c08951d2c283a799ab013bf845ed822e')
324 | })
325 | print("Success!")
326 | }
327 |
328 | test_2.4 <- function(){
329 | properties <- c(choose_beer_k$layers[[1]]$mapping, choose_beer_k$mapping)
330 | labels <- choose_beer_k$labels
331 | test_that('Did not create a plot named choose_beer_k', {
332 | expect_true(exists("choose_beer_k"))
333 | })
334 | test_that('# clusters should be on the x-axis.', {
335 | expect_true("num_clusters" == rlang::get_expr(properties$x))
336 | })
337 | test_that('total within-cluster sum-of-squares should be on the y-axis.', {
338 | expect_true("total_WSSD" == rlang::get_expr(properties$y))
339 | })
340 | test_that('choose_beer_k should be a line and scatter plot.', {
341 | expect_true("GeomLine" %in% c(class(choose_beer_k$layers[[1]]$geom),class(choose_beer_k$layers[[2]]$geom)))
342 | })
343 | test_that('choose_beer_k should be a line and scatter plot.', {
344 | expect_true("GeomPoint" %in% c(class(choose_beer_k$layers[[1]]$geom),class(choose_beer_k$layers[[2]]$geom)))
345 | })
346 | test_that('Labels on the axes should be descriptive and human readable.', {
347 | expect_false((labels$y) == 'total_WSSD')
348 | expect_false((labels$x) == 'num_clusters')
349 | })
350 | print("Success!")
351 | }
352 |
353 | test_2.5 <- function(){
354 | test_that('Solution is incorrect', {
355 | expect_true(digest(answer2.5) %in% c('0e4033b8c0b56afbea35dc749ced4e1d',
356 | 'd19d62a873f08af0488f0df720cfd293',
357 | '00713fac580bcb0691658403f8e6f4e3',
358 | 'db8e490a925a60e62212cefc7674ca02',
359 | 'e5b57f323c7b3719bbaaf9f96b260d39',
360 | 'dbc09cba9fe2583fb01d63c70e1555a8'))
361 | })
362 | print("Success!")
363 | }
364 |
365 | test_2.6 <- function(){
366 | test_that('Solution is incorrect', {
367 | expect_equal(digest(answer2.6), '475bf9280aab63a82af60791302736f6')
368 | })
369 | print("Success!")
370 | }
371 |
372 | test_2.7 <- function(){
373 | test_that('Solution is incorrect', {
374 | expect_equal(digest(answer2.7), '3a5505c06543876fe45598b5e5e5195d')
375 | })
376 | print("Success!")
377 | }
378 |
379 | test_2.8 <- function(){
380 | test_that('Solution is incorrect', {
381 | expect_equal(digest(answer2.8), '05ca18b596514af73f6880309a21b5dd')
382 | })
383 | print("Success!")
384 | }
385 |
--------------------------------------------------------------------------------
/worksheet_regression1/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 | library(rlang)
4 |
5 | # Round double to precise integer
6 | #
7 | # `int_round` works to create an integer corresponding to a number that is
8 | # tested up to a particular decimal point of precision. This is useful when
9 | # there is a need to compare a numeric value using hashes.
10 | #
11 | # @param x Double vector of length one.
12 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
13 | #
14 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
15 | #
16 | # @examples
17 | # # to get an integer up to two decimals of precision from 234.56789
18 | # int_round(234.56789, 2)
19 | #
20 | # to get an integer rounded to the hundred digit from 234.56789
21 | # int_round(234.56789, -2)
22 | int_round <- function(x, digits){
23 | x = x * 10^digits
24 | xint = as.integer(x)
25 | xint1 = xint + 1L
26 | if (abs(xint - x) < abs(xint1 - x)){
27 | return(xint)
28 | }
29 | else {
30 | return(xint1)
31 | }
32 | }
33 |
34 | test_0.0 <- function(){
35 | test_that('Solution is incorrect', {
36 | expect_equal(digest(answer0.0), '3a5505c06543876fe45598b5e5e5195d')
37 | })
38 | print("Success!")
39 | }
40 |
41 | test_0.1 <- function(){
42 | test_that('Solution is incorrect', {
43 | expect_equal(digest(answer0.1), '475bf9280aab63a82af60791302736f6')
44 | })
45 | print("Success!")
46 | }
47 |
48 | test_0.2 <- function(){
49 | test_that('Solution is incorrect', {
50 | expect_equal(digest(int_round(answer0.2, 2)), '6953b334169bd7ec7da1c1eda5aaf6a5')
51 | })
52 | print("Success!")
53 | }
54 |
55 | test_0.3 <- function(){
56 | test_that('Solution is incorrect', {
57 | expect_equal(digest(answer0.3), '75f1160e72554f4270c809f041c7a776')
58 | })
59 | print("Success!")
60 | }
61 |
62 | test_1.0 <- function(){
63 | test_that('Did not create an object named marathon', {
64 | expect_true(exists("marathon"))
65 | })
66 | test_that('marathon should be a tibble.', {
67 | expect_true('tbl' %in% class(marathon))
68 | })
69 | test_that('marathon does not contain the correct number of rows and/or columns.', {
70 | expect_equal(dim(marathon), c(929, 13))
71 | })
72 | test_that('The marathon tibble is missing columns.', {
73 | expect_true("time_hrs" %in% colnames(marathon))
74 | expect_true("max" %in% colnames(marathon))
75 | })
76 | print("Success!")
77 | }
78 |
79 | test_2.0 <- function(){
80 | properties <- c(answer2$mapping, answer2$layers[[1]]$mapping)
81 | labels <- answer2$labels
82 | test_that('Did not create a plot named answer2', {
83 | expect_true(exists("answer2"))
84 | })
85 | test_that('marathon_50 does not contain the correct number of rows and/or columns.', {
86 | expect_equal(dim(marathon_50), c(50, 13))
87 | })
88 | test_that('answer2 should use information from marathon_50', {
89 | expect_equal(answer2$data, marathon_50)
90 | })
91 | test_that('max should be on the x-axis.', {
92 | expect_true("max" %in% c(rlang::get_expr(properties$x),
93 | rlang::get_expr(properties$x)))
94 | })
95 | test_that('time_hrs should be on the y-axis.', {
96 | expect_true("time_hrs" %in% c(rlang::get_expr(properties$y),
97 | rlang::get_expr(properties$y)))
98 | })
99 | test_that('answer2 should be a scatter plot.', {
100 | expect_equal(digest(class(rlang::get_expr(answer2$layers[[1]]$geom))[1]),
101 | '911e5b9debfb523f25ad2ccc01a4b2dd')
102 | })
103 | test_that('Labels on the axes should be descriptive and human readable.', {
104 | expect_false((labels$y) == 'time_hrs')
105 | expect_false((labels$x) == 'max')
106 | })
107 | print("Success!")
108 | }
109 |
110 | test_3.0 <- function(){
111 | test_that('Did not create an object called answer3', {
112 | expect_true(exists('answer3'))
113 | })
114 | test_that('answer3 is incorrect', {
115 | expect_equal(digest(int_round(answer3, 1)), 'a266aa4a0aa711355be22e0f3b8d91af')
116 | })
117 | print("Success!")
118 | }
119 |
120 | test_4.0 <- function(){
121 | test_that('Did not create an object called answer4', {
122 | expect_true(exists('answer4'))
123 | })
124 | test_that('answer4 is incorrect', {
125 | expect_equal(digest(int_round(answer4, 1)), '285d156b1b700fbb489df058fdb9e2ee')
126 | })
127 | print("Success!")
128 | }
129 |
130 | test_5.0 <- function(){
131 | test_that('Did not create an object called answer5', {
132 | expect_true(exists('answer5'))
133 | })
134 | test_that('Solution is incorrect', {
135 | expect_equal(digest(answer5), '475bf9280aab63a82af60791302736f6')
136 | })
137 | print("Success!")
138 | }
139 |
140 | test_6.0 <- function(){
141 | test_that('Did not create an object named marathon_split', {
142 | expect_true(exists("marathon_split"))
143 | })
144 | test_that('marathon_split should be rsplit (not a tibble)', {
145 | expect_true('rsplit' %in% class(marathon_split))
146 | })
147 | test_that('Did not create an object named marathon_training', {
148 | expect_true(exists('marathon_training'))
149 | })
150 | test_that('marathon_training does not contain 0.75 of the data.', {
151 | expect_equal(dim(marathon_training), c(696,13))
152 | expect_equal(digest(int_round(sum(marathon_training$age), 0)), 'fbf206d474a56038342d51f17b0ba4c8')
153 | })
154 | test_that('Did not create an object named marathon_testing', {
155 | expect_true(exists('marathon_testing'))
156 | })
157 | test_that('marathon_testing does not contain 0.25 of the data.', {
158 | expect_equal(dim(marathon_testing), c(233, 13))
159 | expect_equal(digest(int_round(sum(marathon_testing$age), 0)), '4a09fa6ca41f8e9bff7eea7fd4565399')
160 | })
161 | print("Success!")
162 | }
163 |
164 | test_7.0 <- function(){
165 | test_that('Did not create an object named marathon_spec', {
166 | expect_true(exists("marathon_spec"))
167 | })
168 | test_that('neighbors argument is incorrect', {
169 | expect_equal(digest(as.character(get_expr(marathon_spec$args$neighbors))), '4b89cff22bb78b28a0a6b7fe28d371f6')
170 | })
171 | test_that('weight_func is incorrect', {
172 | expect_equal(digest(as.character(get_expr(marathon_spec$args$weight_func))), '989de78e881829b4499af3610dfe54fd')
173 | })
174 | test_that('set_engine is incorrect', {
175 | expect_equal(digest(as.character(marathon_spec$engine)), '93fe1d3f0a1fa2e625af1e1eb51a5c33')
176 | })
177 | test_that('mode is incorrect', {
178 | expect_equal(digest(as.character(marathon_spec$mode)), 'b8bdd7015e0d1c6037512fd1396aef1a')
179 | })
180 | test_that('Did not create an object named marathon_recipe', {
181 | expect_true(exists("marathon_recipe"))
182 | })
183 | test_that('Data in marathon_recipe is not scaled and centered', {
184 | expect_equal(digest(int_round(sum(marathon_recipe$template$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
185 | expect_equal(digest(int_round(sum(marathon_recipe$template$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
186 | })
187 | print("Success!")
188 | }
189 |
190 | test_7.1 <- function(){
191 | test_that('Did not create an object called marathon_vfold', {
192 | expect_true(exists("marathon_vfold"))
193 | })
194 | test_that('marathon_vfold does not contain 5 folds', {
195 | expect_equal(int_round(length(marathon_vfold$id), 0), 5)
196 | })
197 | test_that('marathon_vfold should be a cross-validation object', {
198 | expect_true('vfold_cv' %in% class(marathon_vfold))
199 | })
200 | test_that('Did not create an object called marathon_workflow', {
201 | expect_true(exists("marathon_workflow"))
202 | })
203 | test_that('marathon_workflow is not a workflow object', {
204 | expect_true('workflow' %in% class(marathon_workflow))
205 | })
206 | test_that('marathon_workflow does not contain the correct model specification', {
207 | expect_equal(digest(as_label(marathon_workflow$fit$actions$model$spec$args$neighbors)), 'c77d97a68a64b2275e17f3075c96d102')
208 | expect_equal(digest(as_label(marathon_workflow$fit$actions$model$spec$mode)), 'ac823aa7d8cf42de9175927e6f7682e5')
209 | expect_equal(digest(as_label(marathon_workflow$fit$actions$model$spec$engine)), '141555abd68c42d32c04aba2636361c6')
210 | expect_true('nearest_neighbor' %in% class(marathon_workflow$fit$actions$model$spec))
211 | })
212 | test_that('marathon_workflow does not contain the correct recipe', {
213 | expect_true('recipe' %in% class(marathon_workflow$pre$actions$recipe$recipe))
214 | expect_equal(digest(int_round(sum(marathon_workflow$pre$actions$recipe$recipe$template$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
215 | expect_equal(digest(int_round(sum(marathon_workflow$pre$actions$recipe$recipe$template$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
216 | })
217 | print("Success!")
218 | }
219 |
220 |
221 | test_8.0 <- function(){
222 | test_that('Did not create an object named gridvals', {
223 | expect_true(exists('gridvals'))
224 | })
225 | test_that('gridvals does not contain the correct data and column name', {
226 | expect_true('tbl' %in% class(gridvals))
227 | expect_true('neighbors' %in% colnames(gridvals))
228 | expect_equal(digest(int_round(sum(gridvals), 0)), '251921ac8b52641fc990099b8c3d3b19')
229 | })
230 | test_that('Did not create an object named marathon_results', {
231 | expect_true(exists('marathon_results'))
232 | })
233 | test_that('marathon_results is not a tibble', {
234 | expect_true('tbl' %in% class(marathon_results))
235 | })
236 | test_that('marathon_results does not contain the correct data', {
237 | expect_equal(dim(marathon_results), c(18, 7))
238 | expect_equal(digest(int_round(sum(marathon_results$neighbors), 0)), 'f7783fc3ee9f29933ddb6b84b210f0f6')
239 | expect_equal(int_round(unique(marathon_results$n), 0), 5)
240 | expect_equal(digest(int_round(sum(marathon_results$mean), 0)), '8eaca7c9b35d05ab15c9125bc92372fa')
241 | expect_equal(digest(int_round(sum(marathon_results$std_err), 0)), '1473d70e5646a26de3c52aa1abd85b1f')
242 | })
243 | print("Success!")
244 | }
245 |
246 |
247 | test_8.1 <- function(){
248 | test_that('Did not create an object named marathon_min', {
249 | expect_true(exists('marathon_min'))
250 | })
251 | test_that('marathon_min is not a tibble', {
252 | expect_true('tbl' %in% class(marathon_min))
253 | })
254 | test_that('marathon_min does not contain the correct data', {
255 | expect_equal(dim(marathon_min), c(1, 7))
256 | expect_true('neighbors' %in% colnames(marathon_min))
257 | expect_true('.metric' %in% colnames(marathon_min))
258 | expect_true('.estimator' %in% colnames(marathon_min))
259 | expect_true('mean' %in% colnames(marathon_min))
260 | expect_true('n' %in% colnames(marathon_min))
261 | expect_true('std_err' %in% colnames(marathon_min))
262 | expect_true('.config' %in% colnames(marathon_min))
263 | })
264 | test_that('Best K value is incorrect', {
265 | expect_equal(digest(int_round(marathon_min$neighbors, 2)), 'd35f53c853d2daeb8607b7f873601c34')
266 | })
267 | test_that('Metric is incorrect', {
268 | expect_equal(digest(marathon_min$.metric), '91a8c46d46a2a25459eaabfa08f35967')
269 | })
270 | print("Success!")
271 | }
272 |
273 | test_8.2 <- function(){
274 | test_that('Did not create an object named k_min', {
275 | expect_true(exists('k_min'))
276 | })
277 | test_that('k_min is not correct', {
278 | expect_equal(digest(int_round(k_min, 2)), 'd35f53c853d2daeb8607b7f873601c34')
279 | })
280 | test_that('Did not create an object named marathon_best_spec', {
281 | expect_true(exists('marathon_best_spec'))
282 | })
283 | test_that('marathon_best_spec has incorrect specifications', {
284 | expect_equal(digest(as.character(get_expr(marathon_best_spec$args$neighbors))), '0b942c90bc01f15b084d00fa29bf4cc0')
285 | })
286 | test_that('weight_func is incorrect', {
287 | expect_equal(digest(as.character(get_expr(marathon_best_spec$args$weight_func))), '989de78e881829b4499af3610dfe54fd')
288 | })
289 | test_that('set_engine is incorrect', {
290 | expect_equal(digest(as.character(marathon_best_spec$engine)), '93fe1d3f0a1fa2e625af1e1eb51a5c33')
291 | })
292 | test_that('mode is incorrect', {
293 | expect_equal(digest(as.character(marathon_best_spec$mode)), 'b8bdd7015e0d1c6037512fd1396aef1a')
294 | })
295 | test_that('Did not create an object named marathon_best_fit', {
296 | expect_true(exists('marathon_best_fit'))
297 | })
298 | test_that('marathon_best_fit should be a workflow', {
299 | expect_true('workflow' %in% class(marathon_best_fit))
300 | })
301 | test_that('marathon_best_fit does not contain the correct model specification', {
302 | expect_equal(digest(get_expr(marathon_best_fit$fit$actions$model$spec$args$neighbors)), '7ad692ee809beafa13e6d291d0d5372f')
303 | expect_equal(digest(as.character(marathon_best_fit$fit$actions$model$spec$mode)), 'b8bdd7015e0d1c6037512fd1396aef1a')
304 | expect_equal(digest(as.character(marathon_best_fit$fit$actions$model$spec$engine)), '93fe1d3f0a1fa2e625af1e1eb51a5c33')
305 | expect_true('nearest_neighbor' %in% class(marathon_best_fit$fit$actions$model$spec))
306 | })
307 | test_that('marathon_best_fit does not contain the correct recipe', {
308 | expect_true('recipe' %in% class(marathon_best_fit$pre$actions$recipe$recipe))
309 | expect_equal(digest(int_round(sum(marathon_best_fit$pre$actions$recipe$recipe$template$max), 0)), 'f51f00d1db12d6567be874b8acd7d2e0')
310 | expect_equal(digest(int_round(sum(marathon_best_fit$pre$actions$recipe$recipe$template$time_hrs), 0)), '241691b869a7ec8e10915214932a8d86')
311 | })
312 | test_that('Did not create an object named marathon_summary', {
313 | expect_true(exists('marathon_summary'))
314 | })
315 | test_that('marathon_summary is not a tibble', {
316 | expect_true('tbl' %in% class(marathon_summary))
317 | })
318 | test_that('marathon_summary contains the incorrect data', {
319 | expect_true('.metric' %in% colnames(marathon_summary))
320 | expect_true('.estimator' %in% colnames(marathon_summary))
321 | expect_true('.estimate' %in% colnames(marathon_summary))
322 | expect_equal(digest(int_round(sum(marathon_summary$.estimate), 0)), '4b5630ee914e848e8d07221556b0a2fb')
323 | })
324 | print("Success!")
325 | }
326 |
327 | test_8.3 <- function(){
328 | test_that('Did not create an objected named answer8.3', {
329 | expect_true(exists('answer8.3'))
330 | })
331 | test_that('answer is incorrect', {
332 | expect_equal(digest(answer8.3), 'd2a90307aac5ae8d0ef58e2fe730d38b')
333 | })
334 | print("Success!")
335 | }
336 |
337 | test_9.0 <- function(){
338 | properties <- c(marathon_plot$layers[[1]]$mapping, marathon_plot$mapping)
339 | labels <- marathon_plot$labels
340 | test_that('Did not create an object named marathon_preds', {
341 | expect_true(exists('marathon_preds'))
342 | })
343 | test_that('marathon_preds should be a tibble', {
344 | expect_true('tbl' %in% class(marathon_preds))
345 | })
346 | test_that('marathon_preds contains incorrect data', {
347 | expect_equal(dim(marathon_preds), c(696, 14))
348 | expect_true('.pred' %in% colnames(marathon_preds))
349 | expect_equal(digest(int_round(sum(marathon_preds$.pred), 2)), '6796478bc90c68268ec527deb6473273')
350 | expect_equal(digest(int_round(sum(marathon_preds$time_hrs), 2)), '8b88838a2398216f8b3254aad44c6f8f')
351 | })
352 | test_that('Did not create an object called marathon_plot', {
353 | expect_true(exists('marathon_plot'))
354 | })
355 | test_that('max should be on the x-axis.', {
356 | expect_true("max" == rlang::get_expr(properties$x))
357 | })
358 | test_that('time_hrs should be on the y-axis (try adding geom_point *before* geom_line!)', {
359 | expect_true("time_hrs" == rlang::get_expr(properties$y))
360 | })
361 | test_that('marathon_plot should have full_predictions plotted as a blue line over the data points.', {
362 | expect_true('blue' %in% as.character(marathon_plot$layers[[2]]$aes_params))
363 | expect_true('GeomLine' %in% c(class(rlang::get_expr(marathon_plot$layers[[1]]$geom)), class(rlang::get_expr(marathon_plot$layers[[2]]$geom))))
364 | })
365 | test_that('max should be the x argument for geom_line, and geom_line should come *after* geom_point', {
366 | expect_true('max' == rlang::get_expr(marathon_plot$layers[[2]]$mapping$x))
367 | })
368 | test_that('.pred should be the y argument for geom_line, and geom_line should come *after* geom_point',{
369 | expect_true('.pred' == rlang::get_expr(marathon_plot$layers[[2]]$mapping$y))
370 | })
371 | test_that('Labels on the axes/title and legend need to be changed to be descriptive, nicely formatted, and human readable.', {
372 | expect_false((labels$y) == 'time_hrs')
373 | expect_false((labels$x) == 'max')
374 | expect_false((labels$title == 'k_min'))
375 | })
376 | print("Success!")
377 | }
378 |
--------------------------------------------------------------------------------
/worksheet_classification2/tests.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(digest)
3 | library(rlang)
4 |
5 | # Round double to precise integer
6 | #
7 | # `int_round` works to create an integer corresponding to a number that is
8 | # tested up to a particular decimal point of precision. This is useful when
9 | # there is a need to compare a numeric value using hashes.
10 | #
11 | # @param x Double vector of length one.
12 | # @param digits Double vector of length one to specify decimal point of precision. Negative numbers can be used to specifying significant digits > 0.1.
13 | #
14 | # @return Integer vector of length one corresponding to a particular decimal point of precision.
15 | #
16 | # @examples
17 | # # to get an integer up to two decimals of precision from 234.56789
18 | # int_round(234.56789, 2)
19 | #
20 | # to get an integer rounded to the hundred digit from 234.56789
21 | # int_round(234.56789, -2)
22 | int_round <- function(x, digits){
23 | x = x * 10^digits
24 | xint = as.integer(x)
25 | xint1 = xint + 1L
26 | if (abs(xint - x) < abs(xint1 - x)){
27 | return(xint)
28 | }
29 | else {
30 | return(xint1)
31 | }
32 | }
33 |
34 | test_0.1 <- function(){
35 | test_that('Did not create an object named answer0.1', {
36 | expect_true(exists('answer0.1'))
37 | })
38 | test_that('Solution is incorrect', {
39 | expect_equal(digest(answer0.1), '475bf9280aab63a82af60791302736f6')
40 | })
41 | print("Success!")
42 |
43 | }
44 |
45 | test_1.0 <- function(){
46 | test_that('Did not create an object named fruit_data', {
47 | expect_true(exists("fruit_data"))
48 | })
49 | test_that('fruit_data does not contain the correct number of rows and/or columns.', {
50 | expect_equal(dim(fruit_data), c(59, 7))
51 | })
52 | test_that('The fruit_name column in fruit_data should be of class factor.', {
53 | expect_true(is.factor(fruit_data$fruit_name))
54 | })
55 | test_that('Columns in fruit_data contain incorrect values.', {
56 | expect_equal(digest(int_round(sum(fruit_data$mass, na.rm = TRUE), 2)), '8c7433f4d278ef1e1e0f8d0ccb217614') # we hid the answer to the test here so you can't see it, but we can still run the test
57 | })
58 | print("Success!")
59 | }
60 |
61 | # # +
62 | test_1.1 <- function(){
63 | test_that('Did not create an object called answer1.1', {
64 | expect_true(exists('answer1.1'))
65 | })
66 | test_that('Solution is incorrect', {
67 | expect_equal(digest(answer1.1), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test
68 |
69 | })
70 | print("Success!")
71 | }
72 | # -
73 |
74 | test_1.2 <- function(){
75 | test_that('Did not create an object named fruit_dist_2', {
76 | expect_true(exists("fruit_dist_2"))
77 | })
78 | test_that('fruit_dist_2 is incorrect.', {
79 | expect_equal(digest(int_round(fruit_dist_2, 3)), 'a29a5d18050c6ce0aa2dc501684e1375')
80 | })
81 | print("Success!")
82 | }
83 |
84 | test_1.3 <- function(){
85 | test_that('Did not create an object named fruit_dist_44', {
86 | expect_true(exists("fruit_dist_44"))
87 | })
88 | test_that('fruit_dist_44 is incorrect.', {
89 | expect_equal(digest(int_round(fruit_dist_44, 2)), 'ea07cf8b74030ff04b56ac69dd094adc')
90 | })
91 | print("Success!")
92 | }
93 |
94 |
95 | test_1.4 <- function(){
96 | test_that('Did not create an object named answer1.4', {
97 | expect_true(exists('answer1.4'))
98 | })
99 | test_that('Solution is incorrect', {
100 | expect_equal(digest(answer1.4), 'c1f86f7430df7ddb256980ea6a3b57a4') # we hid the answer to the test here so you can't see it, but we can still run the test
101 | })
102 | print("Success!")
103 | }
104 |
105 | test_1.5 <- function(){
106 | test_that('Did not create an object named fruit_data_scaled', {
107 | expect_true(exists("fruit_data_scaled"))
108 | })
109 | test_that('fruit_data_scaled does not contain the correct number of rows and/or columns.', {
110 | expect_equal(dim(fruit_data_scaled), c(59, 11))
111 | })
112 | test_that('The fruit_name column in fruit_data_scaled should be of class factor.', {
113 | expect_true(is.factor(fruit_data_scaled$fruit_name))
114 | })
115 | test_that('Columns in fruit_data_scaled contain incorrect values.', {
116 | expect_equal(digest(int_round(sum(fruit_data_scaled$mass, na.rm = TRUE), 2)), '8c7433f4d278ef1e1e0f8d0ccb217614') # we hid the answer to the test here so you can't see it, but we can still run the test
117 | })
118 | test_that('The mass, height, color score, and width columns in fruit_data_Scaled should be scaled.', {
119 | expect_equal(digest(int_round(sum(fruit_data_scaled$scaled_mass), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
120 | expect_equal(digest(int_round(sum(fruit_data_scaled$scaled_width), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
121 | expect_equal(digest(int_round(sum(fruit_data_scaled$scaled_height), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
122 | expect_equal(digest(int_round(sum(fruit_data_scaled$scaled_color_score), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
123 | })
124 | print("Success!")
125 | }
126 |
127 | test_1.6 <- function(){
128 | test_that('Did not create an object named distance_44', {
129 | expect_true(exists("distance_44"))
130 | })
131 | test_that('Did not create an object named distance_2', {
132 | expect_true(exists("distance_2"))
133 | })
134 | test_that('distance_44 should be a distance.', {
135 | expect_true('dist' %in% class(distance_44))
136 | })
137 | test_that('distance_2 should be a distance.', {
138 | expect_true('dist' %in% class(distance_2))
139 | })
140 | test_that('distance_44 is incorrect.', {
141 | expect_equal(digest(int_round(distance_2, 2)), '192b298ed4661ab6d9a4a193b2e60b49')
142 | })
143 | test_that('distance_2 is incorrect.', {
144 | expect_equal(digest(int_round(distance_44, 2)), '78f799aab6957dffdfd2bfb504f8cab5')
145 | })
146 | print("Success!")
147 | }
148 |
149 | test_2.0 <- function(){
150 | test_that('Did not create an object named fruit_train', {
151 | expect_true(exists("fruit_train"))
152 | })
153 | test_that('Did not create an object named fruit_test', {
154 | expect_true(exists("fruit_test"))
155 | })
156 | test_that('fruit_train does not contain the correct number of rows and/or columns', {
157 | expect_equal(dim(fruit_train), c(43, 7))
158 | })
159 | test_that('fruit_test does not contain the correct number of rows and/or columns',{
160 | expect_equal(dim(fruit_test), c(16, 7))
161 | })
162 | test_that('fruit_train contains the wrong data', {
163 | expect_equal(digest(int_round(sum(fruit_train$mass), 2)), '9bf942a5a6abebbd695206d1702daf85')
164 | })
165 | test_that('fruit_test contains the wrong data', {
166 | expect_equal(digest(int_round(sum(fruit_test$mass), 2)), '2c94ccd3848af6dda07a29737ae9bff9')
167 | })
168 | print("Success!")
169 | }
170 |
171 |
172 | test_2.1 <- function(){
173 | test_that('Did not create an object named fruit_recipe', {
174 | expect_true(exists("fruit_recipe"))
175 | })
176 | test_that('fruit_recipe should be a recipe.', {
177 | expect_true('recipe' %in% class(fruit_recipe))
178 | })
179 | test_that('fruit_recipe contains the wrong columns', {
180 | expect_true('color_score' %in% colnames(fruit_recipe$template))
181 | expect_true('mass' %in% colnames(fruit_recipe$template))
182 | expect_true('fruit_name' %in% colnames(fruit_recipe$template))
183 | })
184 | test_that('fruit_recipe contains the wrong data', {
185 | expect_equal(digest(int_round(sum(fruit_recipe$template$mass), 2)), '9bf942a5a6abebbd695206d1702daf85')
186 | expect_equal(digest(int_round(sum(fruit_recipe$template$color_score), 2)), '10247a99309183ca46c8bc0cbcfc4862')
187 | })
188 | test_that('all_predictors() is not scaled and centered', {
189 | expect_equal(digest(as.character(get_expr(fruit_recipe$steps[[1]]$terms))), 'f34b27deb5a8023de51b602e9aacf535')
190 | expect_equal(digest(as.character(get_expr(fruit_recipe$steps[[2]]$terms))), 'f34b27deb5a8023de51b602e9aacf535')
191 | })
192 | test_that('fruit_name was not placed before predictors', {
193 | expect_equal(digest(as.character(fruit_recipe$var_info$variable[3])), '1298acdeb848b96767603d30382d6aff')
194 | })
195 | print("Success!")
196 | }
197 |
198 | test_2.2 <- function(){
199 | test_that('Did not create an object named knn_spec', {
200 | expect_true(exists("knn_spec"))
201 | })
202 | test_that('knn_spec should be a model specification', {
203 | expect_true("model_spec" %in% class(knn_spec))
204 | })
205 | test_that('k is not 3', {
206 | expect_equal(int_round(get_expr(knn_spec$args$neighbors), 0), 3)
207 | })
208 | test_that('weight_func is incorrect', {
209 | expect_equal(digest(as.character(get_expr(knn_spec$args$weight_func))), '989de78e881829b4499af3610dfe54fd')
210 | })
211 | test_that('set_engine is incorrect', {
212 | expect_equal(digest(as.character(knn_spec$engine)), '93fe1d3f0a1fa2e625af1e1eb51a5c33')
213 | })
214 | test_that('mode is incorrect', {
215 | expect_equal(digest(as.character(knn_spec$mode)), 'f361ba6f6b32d068e56f61f53d35e26a')
216 | })
217 | test_that('Did not create an object named fruit_fit', {
218 | expect_true(exists("fruit_fit"))
219 | })
220 | test_that('fruit_fit should be a workflow.', {
221 | expect_true('workflow' %in% class(fruit_fit))
222 | })
223 | test_that('fruit_fit does not contain scaled data', {
224 | expect_equal(digest(int_round(sum(fruit_fit$pre$mold$predictors$mass), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
225 | expect_equal(digest(int_round(sum(fruit_fit$pre$mold$predictors$color_score), 2)), '1473d70e5646a26de3c52aa1abd85b1f')
226 | })
227 | test_that('you should only fit the model on the training dataset', {
228 | expect_equal(nrow(fruit_fit$pre$mold$outcomes), nrow(fruit_train))
229 | })
230 | print("Success!")
231 | }
232 |
233 | test_2.3 <- function(){
234 | test_that('Did not create an object named fruit_test_predictions', {
235 | expect_true(exists("fruit_test_predictions"))
236 | })
237 | test_that('fruit_test_predictions should be a tibble.', {
238 | expect_true('tbl' %in% class(fruit_test_predictions))
239 | })
240 | test_that('fruit_test_predictions should contain the original data and the new prediction column', {
241 | expect_equal(dim(fruit_test_predictions), c(16, 8))
242 | expect_true('.pred_class' %in% colnames(fruit_test_predictions))
243 | })
244 | print("Success!")
245 | }
246 |
247 | test_2.4 <- function(){
248 | test_that('Did not create an object named fruit_prediction_accuracy', {
249 | expect_true(exists("fruit_prediction_accuracy"))
250 | })
251 | test_that('fruit_prediction_accuracy should be a tibble', {
252 | expect_true('tbl' %in% class(fruit_prediction_accuracy))
253 | })
254 | test_that('estimates are incorrect', {
255 | expect_equal(digest(int_round(sum(fruit_prediction_accuracy$.estimate), 2)), 'aa46ec0eda6b9268581f7b6334fe5368')
256 | })
257 | test_that('the estimator should be a multiclass classification', {
258 | expect_true('multiclass' %in% fruit_prediction_accuracy$.estimator)
259 | })
260 | print("Success!")
261 | }
262 |
263 | test_2.5 <- function(){
264 | test_that('Did not create an object named fruit_mat', {
265 | expect_true(exists("fruit_mat"))
266 | })
267 | test_that('fruit_mat is not a confusion matrix', {
268 | expect_true('conf_mat' %in% class(fruit_mat))
269 | })
270 | test_that('Number of observations is incorrect', {
271 | expect_equal(digest(int_round(sum(as_tibble(fruit_mat$table)[3]), 2)), '9770d56d568e4493bed5636f1fe8e1f3')
272 | })
273 | print("Success!")
274 | }
275 |
276 |
277 | test_2.6 <- function(){
278 | test_that('Did not create an object named answer2.6', {
279 | expect_true(exists("answer2.6"))
280 | })
281 | test_that('Answer is incorrect', {
282 | expect_equal(digest(answer2.6), 'c1f86f7430df7ddb256980ea6a3b57a4')
283 | })
284 | print("Success!")
285 | }
286 |
287 | test_3.1 <- function(){
288 | test_that('Did not create an object named fruit_vfold', {
289 | expect_true(exists("fruit_vfold"))
290 | })
291 | test_that('fruit_vfold is not a cross validation object',{
292 | expect_true('vfold_cv' %in% class(fruit_vfold))
293 | })
294 | test_that('fruit_vfold does not contain 5 folds', {
295 | expect_equal(int_round(length(fruit_vfold$id), 0), 5)
296 | })
297 | test_that('fruit_vfold contains the incorrect data', {
298 | expect_equal(dim(fruit_vfold), c(5, 2))
299 | })
300 | test_that('fruit_vfold does not use the training data', {
301 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[1]]$data$color_score), 2)), '10247a99309183ca46c8bc0cbcfc4862')
302 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[1]]$data$mass), 2)), '9bf942a5a6abebbd695206d1702daf85')
303 | })
304 | test_that('strata argument is not fruit_name', {
305 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[1]]$in_id), 2)), 'f9057f509d538da8293fcdedc62f73aa')
306 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[2]]$in_id), 2)), 'b58260193fe0f701941c6e0cfc96ad00')
307 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[3]]$in_id), 2)), 'b845fe9fbc8f608114d10197f7452d3a')
308 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[4]]$in_id), 2)), '39c92dfe53b2bac3aa745c3b1bf0e2e8')
309 | expect_equal(digest(int_round(sum(fruit_vfold$splits[[5]]$in_id), 2)), '699513ef5a64b16969e02508265f4880')
310 | })
311 | print("Success!")
312 | }
313 |
314 | test_3.2 <- function(){
315 | test_that('Did not create an object named fruit_resample_fit', {
316 | expect_true(exists("fruit_resample_fit"))
317 | })
318 | test_that('fruit_resample_fit is not a resample_result', {
319 | expect_true('resample_results' %in% class(fruit_resample_fit))
320 | })
321 | test_that('fruit_resample_fit contains the incorrect data', {
322 | expect_equal(dim(fruit_resample_fit), c(5, 4))
323 | })
324 | test_that('number of splits is not 5' ,{
325 | expect_equal(int_round(length(fruit_resample_fit$splits), 0), 5)
326 | })
327 | test_that('fruit_vfold should contain 5 folds', {
328 | expect_equal(int_round(length(fruit_vfold$id), 0), 5)
329 | })
330 | test_that('fruit_vfold contains the incorrect data', {
331 | expect_equal(dim(fruit_vfold), c(5, 2))
332 | })
333 | print("Success!")
334 | }
335 |
336 | test_3.3 <- function(){
337 | test_that('Did not create an object named fruit_metrics', {
338 | expect_true(exists("fruit_metrics"))
339 | })
340 | test_that('fruit_metrics contains the wrong data', {
341 | expect_equal(dim(fruit_metrics), c(2, 6))
342 | expect_true('mean' %in% colnames(fruit_metrics))
343 | expect_true('std_err' %in% colnames(fruit_metrics))
344 | expect_equal(digest(int_round(sum(fruit_metrics$mean), 2)), '3bb12916e7f6fda4645dd4ecaedb76b9')
345 | expect_equal(digest(int_round(sum(fruit_metrics$std_err), 2)), 'dd4ad37ee474732a009111e3456e7ed7')
346 | expect_equal(digest(int_round(sum(fruit_metrics$n), 2)), 'b6a6227038bf9be67533a45a6511cc7e')
347 | })
348 | print("Success!")
349 | }
350 |
351 | test_4.0 <- function(){
352 | test_that('Did not create an object named knn_tune', {
353 | expect_true(exists("knn_tune"))
354 | })
355 | test_that('knn_tune should be a model specification', {
356 | expect_true("model_spec" %in% class(knn_tune))
357 | })
358 | test_that('k is not set to tune', {
359 | expect_equal(as.character(get_expr(knn_tune$args$neighbors)), 'tune')
360 | })
361 | test_that('weight_func is incorrect', {
362 | expect_equal(digest(as.character(get_expr(knn_tune$args$weight_func))), '989de78e881829b4499af3610dfe54fd')
363 | })
364 | test_that('set_engine is incorrect', {
365 | expect_equal(digest(as.character(knn_tune$engine)), '93fe1d3f0a1fa2e625af1e1eb51a5c33')
366 | })
367 | test_that('mode is incorrect', {
368 | expect_equal(digest(as.character(knn_tune$mode)), 'f361ba6f6b32d068e56f61f53d35e26a')
369 | })
370 | print("Success!")
371 | }
372 |
373 | test_4.1 <- function(){
374 | test_that('Did not create an object called knn_results',{
375 | expect_true(exists("knn_results"))
376 | })
377 | test_that('knn_results should be a tibble', {
378 | expect_true('tbl' %in% class(knn_results))
379 | })
380 | test_that('knn_results does not contain the correct data',{
381 | expect_equal(dim(knn_results), c(20, 7))
382 | expect_equal(digest(int_round(sum(knn_results$neighbors), 2)), 'bc0bb1b780c5a2b3fbe18f1017288655')
383 | expect_equal(digest(int_round(sum(knn_results$mean), 2)), '2b7ae7814dec0da4b82acdfb80a9549b')
384 | expect_equal(digest(int_round(sum(knn_results$std_err), 2)), '376fd1e6227fbec1b4f0dfc602df8ac2')
385 | })
386 | test_that('grid is not set to 10', {
387 | expect_equal(int_round(length(unique(knn_results$.config)), 0), 10)
388 | })
389 | print("Success!")
390 | }
391 |
392 |
393 | test_4.2 <- function(){
394 | test_that('Did not create an object called accuracies', {
395 | expect_true(exists("accuracies"))
396 | })
397 | test_that('accuracies .metric column should only contain accuracy', {
398 | expect_true(unique(accuracies$.metric) == "accuracy")
399 | })
400 | properties <- c(accuracy_versus_k$layers[[1]]$mapping, accuracy_versus_k$mapping)
401 | labels <- accuracy_versus_k$labels
402 | test_that('Did not create a plot named accuracy_versus_k', {
403 | expect_true(exists("accuracy_versus_k"))
404 | })
405 | test_that('neighbors should be on the x-axis.', {
406 | expect_true("neighbors" == rlang::get_expr(properties$x))
407 | })
408 | test_that('mean should be on the y-axis.', {
409 | expect_true("mean" == rlang::get_expr(properties$y))
410 | })
411 | test_that('accuracy_versus_k should be a scatter/line plot.', {
412 | expect_true("GeomPoint" %in% c(class(accuracy_versus_k$layers[[1]]$geom)))
413 | expect_true("GeomLine" %in% c(class(accuracy_versus_k$layers[[2]]$geom)))
414 | })
415 | print("Success!")
416 | }
417 |
--------------------------------------------------------------------------------