Skip to content

Commit

Permalink
Minor fixes for release (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
sda030 authored Mar 9, 2024
2 parents 96ceb0d + a920a4d commit 4ee768f
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 73 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.0.1
Date: 2024-01-25 08:55:36 UTC
SHA: 634055424dfbbb642ab2a7b79b7fb1aa5e4268d6
Version: 1.0.4
Date: 2024-02-28 21:56:01 UTC
SHA: 19c35ea247d31386d052a43cd34827a010b15bdf
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: saros
Title: Semi-Automatic Reporting of Ordinary Surveys
Version: 1.0.1.9003
Version: 1.0.4
Authors@R: c(
person(given = "Stephan",
family = "Daus",
Expand Down
19 changes: 11 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->

# saros 1.0.1.9003
# saros 1.0.3

- Added more arguments for plot text sizes, with more useful defaults for Word and HTML layouts.


# saros 1.0.1.9002

# saros 1.0.1.9001

* Minor fix in sanitize_labels
- `attach_qualtrics_labels` is now more flexible.
- Minor fix in `sanitize_labels`.
- Internal change to accommodate ggplot2 3.5.0.
- Improved performance for argument validation checks.
- `setup_access_restrictions` now accepts NULL password input.
- `setup_access_restrictions` now can warn instead of error if `rel_parent_path` does not exist.
- `sort_by` now correctly sorts with `descend=TRUE` for ".upper", etc.
- Fixed `list_available_element_types`
- Set one long-running test for `draft_report` to only run on maintainer's local computer.
- `sanitize_labels` now has option to translate ASCII HTML-escaped characters to unicode.

# saros 1.0.1

Expand Down
2 changes: 2 additions & 0 deletions R/cat_prop_plot_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ prep_cat_prop_plot_html <-
#' @export
#'
#' @examples
#' \donttest{
#' embed_cat_prop_plot(data = ex_survey, dep = b_1:b_3)
#' }
embed_cat_prop_plot <-
function(data,
...,
Expand Down
18 changes: 13 additions & 5 deletions R/qualtrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ attach_qualtrics_labels <- function(data, questions, reverse_stata_replacement=F
#' @param data data.frame or tibble
#' @param sep String, separates main question from subquestion
#' @param multi_sep_replacement String. If multiple sep are found, replace the first ones with this.
#' @param replace_ascii_with_utf Flag. If TRUE, downloads a list from W3 used to convert html characters as ASCII to UTF8.
#' @param questions Data frame with questions obtained from `qualtRics::survey_questions()`
#'
#' @return Identical data.frame as input, with only variable labels changed.
Expand All @@ -61,9 +62,11 @@ attach_qualtrics_labels <- function(data, questions, reverse_stata_replacement=F
sanitize_labels <- function(data,
sep = " - ",
multi_sep_replacement = ": ",
replace_ascii_with_utf = FALSE,
questions = NULL) {

# scrape lookup table of accented char html codes, from the 2nd table on this page
if(isTRUE(replace_ascii_with_utf)) {
ref_url <- 'http://www.w3schools.com/charsets/ref_html_8859.asp'
cols <- c("Character", "Entity Name")
char_table <- rvest::read_html(ref_url)
Expand All @@ -72,6 +75,7 @@ sanitize_labels <- function(data,
char_table <- lapply(char_table, function(x) x[, cols])
char_table <- do.call(rbind, char_table)
char_table <- char_table[!duplicated(char_table[[cols[2]]]) & char_table[[cols[2]]] != "", ]
}

# here's a test string loaded with different html accents
# test_str <- '&Agrave; &Aacute; &Acirc; &Atilde; &Auml; &Aring; &AElig; &Ccedil; &Egrave; &Eacute; &Ecirc; &Euml; &Igrave; &Iacute; &Icirc; &Iuml; &ETH; &Ntilde; &Ograve; &Oacute; &Ocirc; &Otilde; &Ouml; &times; &Oslash; &Ugrave; &Uacute; &Ucirc; &Uuml; &Yacute; &THORN; &szlig; &agrave; &aacute; &acirc; &atilde; &auml; &aring; &aelig; &ccedil; &egrave; &eacute; &ecirc; &euml; &igrave; &iacute; &icirc; &iuml; &eth; &ntilde; &ograve; &oacute; &ocirc; &otilde; &ouml; &divide; &oslash; &ugrave; &uacute; &ucirc; &uuml; &yacute; &thorn; &yuml;'
Expand All @@ -83,11 +87,7 @@ sanitize_labels <- function(data,
label <- attr(data[[var]], "label")

if(is_string(label)) {
for(i in seq_len(nrow(char_table))) {
label <- stringi::stri_replace_all_fixed(str = label,
pattern = char_table[i, cols[2], drop=TRUE],
replacement = char_table[i, cols[1], drop=TRUE])
}


# Replace references with those provided in questions, if any
if(!is.null(questions) &&
Expand All @@ -108,6 +108,14 @@ sanitize_labels <- function(data,
}
}

if(isTRUE(replace_ascii_with_utf)) {
for(i in seq_len(nrow(char_table))) {
label <- stringi::stri_replace_all_fixed(str = label,
pattern = char_table[i, cols[2], drop=TRUE],
replacement = char_table[i, cols[1], drop=TRUE])
}
}

label <- stringi::stri_replace_all_regex(label, pattern = "- Selected Choice ", replacement = "- ")
label <- stringi::stri_replace_all_regex(label, pattern = "<.+?>|\\[.*\\]| - tekst", replacement = "")
label <- stringi::stri_replace_all_regex(label, pattern = "\\$\\{[[:alnum:]]+[^[:alnum:]]([[:alnum:]]+)\\}", replacement = "$1")
Expand Down
9 changes: 0 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ pak::pak("sda030/saros")
```


## Initialize a social science project

```{r example}
### CURRENTLY NOT WORKING. MOVE TO ANOTHER PACKAGE?
#> saros::initialize(folder = getwd())
```

## Draft a report
```{r example2}
# Define temporary folder for storing the elements
Expand Down Expand Up @@ -99,8 +92,6 @@ output_index_qmd <-
hide_label_if_prop_below = .05,
hide_test_if_n_below = 10,
mesos_first = TRUE,
colour_palette_nominal = nifutheme::nifu_cols(),
colour_palette_ordinal = nifutheme::nifu_cols("reds"),
digits = 0,
data_label_decimal_symbol = ",",
path = tempdir())
Expand Down
25 changes: 3 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ install.packages("pak")
pak::pak("sda030/saros")
```

## Initialize a social science project

``` r
### CURRENTLY NOT WORKING. MOVE TO ANOTHER PACKAGE?
#> saros::initialize(folder = getwd())
```

## Draft a report

``` r
Expand All @@ -82,7 +75,7 @@ output_index_qmd <-
)
#> Refining chapter_overview...Not using the following variables in `data`: `x2_human`, `a_7`, `a_8`, and
#> `resp_status`. Generating for chapter Introduction: 1_Introduction Generating for chapter Ambivalence: 2_Ambivalence Generating for chapter Big mysteries: 3_Big_mysterie Generating for chapter Confidence: 4_Confidence Generating for chapter Doubt: 5_Doubt
#> 77.14 4.67 105.45 NA NA
#> 200.06 28.83 275.59 NA NA
quarto::quarto_render(output_index_qmd, as_job = FALSE)
#> pandoc
#> to: html
Expand Down Expand Up @@ -133,27 +126,15 @@ output_index_qmd <-
hide_label_if_prop_below = .05,
hide_test_if_n_below = 10,
mesos_first = TRUE,
colour_palette_nominal = nifutheme::nifu_cols(),
colour_palette_ordinal = nifutheme::nifu_cols("reds"),
digits = 0,
data_label_decimal_symbol = ",",
path = tempdir())
#> Refining chapter_overview...Not using the following variables in `data`: `a_7`,
#> `a_8`, and `resp_status`. Generating for chapter Introduction: 1_Introduction
#> Generating for chapter Ambivalence: 2_Ambivalence Generating for chapter Big
#> mysteries: 3_Big_mysterie Generating for chapter Confidence: 4_Confidence
#> Warning: Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Fewer colours in user-provided colour palette than needed.
#> Generating for chapter Doubt: 5_Doubt
#> 85.45 6.3 108.1 NA NA
#> 216.97 32.25 296.64 NA NA
```

``` r
Expand Down Expand Up @@ -185,7 +166,7 @@ system.time( # 519 sec
#>
#> Output created: main_index.html
#> user system elapsed
#> 0.05 0.00 2.99
#> 0.00 0.00 6.02
if(interactive()) {
browseURL(fs::path(tempdir(), "Uni of C", "Uni of C_main_index.html"))
}
Expand Down
18 changes: 4 additions & 14 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
## Resubmission to new release

## R CMD check results

0 errors | 0 warnings | 2 notes

## Responses to manual review:
* Note that there are not yet any references to describe the methods used in the package, nor are there any new statistical methods applied.
* Description field in DESCRIPTION now has only single spaces.
* list_available_element_types and render_full_reports now have return values.
* Unexported functions now have no examples.
* All \dontrun-tags are removed, except one which is supposed to result in error and \donttest for embed_cat_freq_plot which takes > 5 sec.
* Removed default save locations and getwd() in arguments.
* No function writes by default to working directory/package folder.
* The NOTE: Found the following files/directories: ''NULL'' is due to a bug in running the examples. (I can prove this is not particular to my package).
* Additonally, customizable has been rewritten to customized, in the description field.
* Following {goodpractice}-package I have also replaced sapply with vapply to ensure robustness.
* All cran checks have been rerun again.
## Note

- Set one long-running test only locally, saving many minutes.
- Early update due to changes in ggplot2.
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ htpasswd
https
ifany
indep
maintainer's
mesos
missingess
mschart
Expand All @@ -73,5 +74,6 @@ tabset
tibble
tibbles
tidyselect
unicode
vec
yaml
2 changes: 2 additions & 0 deletions man/embed_cat_prop_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/sanitize_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions saros.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-draft_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ testthat::test_that("draft_report", {


##############################

if(Sys.getenv("USERNAME") == "py128") { # Run expensive >10 min test only for maintainer
tmpdir <- file.path(tempdir(), "test-draft_report2")
data <- saros::ex_survey |>
dplyr::filter(f_uni %in% c("Uni of A", "Uni of B"))
Expand All @@ -35,4 +37,5 @@ testthat::test_that("draft_report", {
object = length(output_files),
expected = nrow(saros::ex_survey_ch_overview[1:3, ]) * dplyr::n_distinct(data$f_uni))

}
})
10 changes: 5 additions & 5 deletions tests/testthat/test-gen_qmd_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testthat::test_that("gen_qmd_index works as expected", {
# Test 1: Basic test with title, authors, and chapter files
index_filepath <- tempfile(fileext = ".qmd")
chapter_filepaths <- c(tempfile(fileext = ".qmd"), tempfile(fileext = ".qmd"))
result <- gen_qmd_index(
result <- saros:::gen_qmd_index(
authors = c("Author 1", "Author 2"),
index_filepath = index_filepath,
chapter_filepaths = chapter_filepaths
Expand All @@ -15,7 +15,7 @@ testthat::test_that("gen_qmd_index works as expected", {

# Test 2: Test with only title and chapter files
index_filepath <- tempfile(fileext = ".qmd")
result <- gen_qmd_index(
result <- saros:::gen_qmd_index(
index_filepath = index_filepath,
chapter_filepaths = chapter_filepaths
)
Expand All @@ -24,7 +24,7 @@ testthat::test_that("gen_qmd_index works as expected", {

# Test 3: Test with only authors and chapter files
index_filepath <- tempfile(fileext = ".qmd")
result <- gen_qmd_index(
result <- saros:::gen_qmd_index(
authors = c("Author 1", "Author 2"),
index_filepath = index_filepath,
chapter_filepaths = chapter_filepaths
Expand All @@ -34,7 +34,7 @@ testthat::test_that("gen_qmd_index works as expected", {

# Test 4: Test with only chapter files
index_filepath <- tempfile(fileext = ".qmd")
result <- gen_qmd_index(
result <- saros:::gen_qmd_index(
index_filepath = index_filepath,
chapter_filepaths = chapter_filepaths
)
Expand All @@ -44,7 +44,7 @@ testthat::test_that("gen_qmd_index works as expected", {

# Test 5: Test with empty chapter filepaths
index_filepath <- tempfile(fileext = ".qmd")
result <- gen_qmd_index(
result <- saros:::gen_qmd_index(
authors = c("Author 1", "Author 2"),
index_filepath = index_filepath,
chapter_filepaths = NULL
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rename_by_labels.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("rename_by_labels", {
testthat::test_that("rename_by_labels", {
suppressMessages(library(dplyr))
library(labelled)
testthat::expect_warning(object = {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-summarize_data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
testthat::test_that("summarize_data", {
#Takes on average 5 sec to run all.

testthat::expect_equal(
saros:::summarize_data(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ungroup_data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("ungroup_data", {
testthat::test_that("ungroup_data", {
x <- saros::ex_survey %>%
dplyr::group_by(.data$f_uni)
testthat::expect_false(inherits(saros:::ungroup_data(x), "grouped_df"))
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
testthat::test_that("col_to_binaries", {
suppressMessages(library(dplyr))
test <-
ex_survey %>%
col_to_binaries(col = b_3, label_separator = " - ") %>%
pull(`b_3___A bit`)
col_to_binaries(ex_survey, col = b_3, label_separator = " - ") |>
dplyr::pull(`b_3___A bit`)
testthat::expect_true(object = all(as.vector(test) %in% 0:1))
testthat::expect_equal(attr(test, "label"),
expected = "How much do you like living in - Budapest - A bit")
Expand Down

0 comments on commit 4ee768f

Please sign in to comment.