Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
strohne committed May 29, 2024
2 parents 065b816 + 654cd08 commit 94d470d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ revdep
^_pkgdown\.yml$
^docs$
^pkgdown$
^doc$
^Meta$
2 changes: 1 addition & 1 deletion R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ data_rm_negatives <- function(data, cols) {
cases <- sum(dplyr::select(data, {{ cols }}) < 0, na.rm=TRUE)

if (cases > 0) {
data |>
data <- data |>
labs_store() |>
dplyr::mutate(dplyr::across({{ cols }}, ~ ifelse(. < 0, NA, .))) |>
labs_restore()
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tab_metrics(data, starts_with("cg_adoption_social"))
```

See further [examples in the introduction
vignette](vignettes/introduction.Rmd).
vignette](articles/introduction.html).

Don't miss the template feature: Within RStudio, create a new Markdown
document, select `From template`, choose and finally knit the **volkeR
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ High-level functions for tabulating, charting and reporting survey data.
tab_metrics(data, starts_with("cg_adoption_social"))

See further [examples in the introduction
vignette](vignettes/introduction.Rmd).
vignette](articles/introduction.html).

Don’t miss the template feature: Within RStudio, create a new Markdown
document, select `From template`, choose and finally knit the **volkeR
Expand Down
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ navbar:
introduction:
text: Introduction
href: articles/introduction.html
vignettes:
- title: "Introduction"
name: "introduction"

reference:
- title: Analysis
Expand Down
20 changes: 16 additions & 4 deletions tests/testthat/_snaps/clean.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Negatives are cleaned
# Residual negatives values are removes

Code
data_clean(tibble::tibble(var1 = c(1, 2, -9)))
data_clean(tibble::tibble(var1 = c(1, 2, -1, -9)))
Output
# A tibble: 3 x 1
# A tibble: 4 x 1
var1
<dbl>
1 1
2 2
3 -1
4 NA

# All negatives are removed

Code
data_rm_negatives(tibble::tibble(var1 = c(1, 2, -1, -9)), var1)
Output
# A tibble: 2 x 1
var1
<dbl>
1 1
2 2
3 NA

# Negatives are kept

Expand Down
15 changes: 12 additions & 3 deletions tests/testthat/test-clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ library(volker)
# Load and recode data
data <- volker::chatgpt

# Remove negative values
test_that("Negatives are cleaned", {

tibble::tibble(var1 = c(1,2,-9)) |>
# Remove residual negative values
test_that("Residual negatives values are removes", {

tibble::tibble(var1 = c(1,2,-1,-9)) |>
data_clean() |>
expect_snapshot(cran= TRUE)

})

# Remove all negative values
test_that("All negatives are removed", {

tibble::tibble(var1 = c(1,2,-1,-9)) |>
data_rm_negatives(var1) |>
expect_snapshot(cran= TRUE)
})


# Keep negative values
test_that("Negatives are kept", {
Expand Down
10 changes: 9 additions & 1 deletion vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,17 @@ ds %>%
```

Alternatively, save the result of `codebook(ds)` to an Excel file,
change the labels and then call `labs_apply()` with your new codebook.
change the labels manually and then call `labs_apply()` with your new codebook.

```{r, eval = FALSE}
codes <- codebook(ds)
write_xlsx(codes,"codebook.xlsx")
codes <- read_xlsx("codebook-new.xlsx")
ds <- labs_apply(codebook)
```

# Index calculation for item batteries

Expand Down

0 comments on commit 94d470d

Please sign in to comment.