diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..21b8a93 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/README.Rmd b/README.Rmd index 6eb1432..580cedb 100644 --- a/README.Rmd +++ b/README.Rmd @@ -43,7 +43,7 @@ library(responsesR) ### Simulating survey data The following sample code creates a simulated survey data. The hypothetical survey simulation is roughly based on the actual [comparative study](https://arxiv.org/abs/2201.12960) on teaching and learning R in a pair of introductory statistics labs. -Imagine a situation in which 10 participants from course A and 20 participants from course B have completed the survey. Suppose that the initial question was: +Consider a scenario where 10 participants who completed Course A and 20 participants who completed Course B have taken the survey. Let's assume the initial question was: > "How would you rate your experience with the course?" @@ -51,7 +51,7 @@ with four possible answers: > Poor, Fair, Good, and Excellent. -Let's assume that the participants in course A were neutral regarding the question and participants in Course B had a more positive experience on average. +Let's suppose that participants in Course A had a neutral opinion regarding the question, while those in Course B, on average, had a more positive experience. By choosing appropriate parameters for the latent distributions and setting number of categories `K = 4`, we can generate hypothetical responses (standard deviation `sd = 1` and skewness `gamma1 = 0`, by default): ```{r} @@ -116,15 +116,15 @@ knitr::include_graphics("./figures/articles_courses_grouped_bar_chart-1.png") Suppose that the survey also asked the participants to rate their skills on a 5-point Likert scale, ranging from 1 (very poor) to 5 (very good) in: -* programming, -* searching online, -* solving problems. +* Programming, +* Searching Online, +* Solving Problems. The survey was completed by the participants both before and after taking the course for a pre and post-comparison. Suppose that participants' assessments of: -* programming skills on average increased, -* searching online stayed about the same, -* solving problems increased in course A, but decreased for participants in course B. +* Programming skills on average increased, +* Searching Online stayed about the same, +* Solving Problems increased in Course A, but decreased for participants in Course B. Let's simulate the survey data for this scenario (number of categories is `K = 5` by default): ```{r} @@ -139,7 +139,7 @@ pre_B <- get_responses(n = 20, mu = c(-1, 0, 1)) post_B <- get_responses(n = 20, mu = c(0, 0, 0)) # <-- decrease for skill 3 ``` -Pre- and post-survey responses to Likert-scale questions visualized using a grouped bar chart: +The grouped bar chart below displays the responses to Likert-scale questions before and after the survey:
Click here to expand diff --git a/README.md b/README.md index e3977d5..5c7dbf8 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ hypothetical survey simulation is roughly based on the actual [comparative study](https://arxiv.org/abs/2201.12960) on teaching and learning R in a pair of introductory statistics labs. -Imagine a situation in which 10 participants from course A and 20 -participants from course B have completed the survey. Suppose that the -initial question was: +Consider a scenario where 10 participants who completed Course A and 20 +participants who completed Course B have taken the survey. Let’s assume +the initial question was: > “How would you rate your experience with the course?” @@ -58,9 +58,9 @@ with four possible answers: > Poor, Fair, Good, and Excellent. -Let’s assume that the participants in course A were neutral regarding -the question and participants in Course B had a more positive experience -on average. +Let’s suppose that participants in Course A had a neutral opinion +regarding the question, while those in Course B, on average, had a more +positive experience. By choosing appropriate parameters for the latent distributions and setting number of categories `K = 4`, we can generate hypothetical @@ -133,18 +133,18 @@ Suppose that the survey also asked the participants to rate their skills on a 5-point Likert scale, ranging from 1 (very poor) to 5 (very good) in: -- programming, -- searching online, -- solving problems. +- Programming, +- Searching Online, +- Solving Problems. The survey was completed by the participants both before and after taking the course for a pre and post-comparison. Suppose that participants’ assessments of: -- programming skills on average increased, -- searching online stayed about the same, -- solving problems increased in course A, but decreased for participants - in course B. +- Programming skills on average increased, +- Searching Online stayed about the same, +- Solving Problems increased in Course A, but decreased for participants + in Course B. Let’s simulate the survey data for this scenario (number of categories is `K = 5` by default): @@ -161,8 +161,8 @@ pre_B <- get_responses(n = 20, mu = c(-1, 0, 1)) post_B <- get_responses(n = 20, mu = c(0, 0, 0)) # <-- decrease for skill 3 ``` -Pre- and post-survey responses to Likert-scale questions visualized -using a grouped bar chart: +The grouped bar chart below displays the responses to Likert-scale +questions before and after the survey:
Click here to expand diff --git a/tests/helper_functions_testthat.R b/tests/helper_functions_testthat.R new file mode 100644 index 0000000..00e00f7 --- /dev/null +++ b/tests/helper_functions_testthat.R @@ -0,0 +1,46 @@ +library("testthat") +library("responsesR") +context("Testing helper functions") + +test_that("prop_table gives the correct result", { + data <- rep(c(1,2,3,4), each=2) + prob_tab <- get_prop_table(data, K=4) + correct_prob_tab <- rep(0.25, 4) + names(correct_prob_tab) <- 1:4 + expect_that( identical(prob_tab, correct_prob_tab), equals(TRUE) ) +}) + +test_that("pad_levels gives the correct result", { + pk <- rep(0.25, 4) + names(pk) <- 1:4 + padded_pk <- pad_levels(pk = pk, K = 5) + + correct_pk <- c(rep(0.25, 4), 0) + names(correct_pk) <- 1:5 + expect_that( identical(padded_pk, correct_pk), equals(TRUE) ) +}) + +test_that("percentify gives the correct result", { + xbreaks <- seq(from = 0, to = 1, length.out = 6) + xlabs <- sapply(xbreaks, percentify) + correct_xlabs <- c("0%", "20%", "40%", "60%", "80%", "100%") + expect_that( identical(xlabs, correct_xlabs), equals(TRUE) ) +}) + + + + + + + + + + + + + + + + + +