Skip to content

Commit

Permalink
Dev2 (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
sda030 authored Jan 1, 2025
2 parents 76ee1ad + a85fc12 commit 2dd17be
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data-raw/goodpractice
^docs$
^vignettes/articles$
^vignettes/\.quarto$
^\.quarto$
^LICENSE\.md$
^CODE_OF_CONDUCT\.md$
^notes$
^vignettes/*_files$
^vignettes$
35 changes: 18 additions & 17 deletions 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.4.0
Version: 1.4.1
Authors@R: c(
person(given = "Stephan",
family = "Daus",
Expand Down Expand Up @@ -35,37 +35,38 @@ BugReports: https://github.com/NIFU-NO/saros/issues
Depends:
R (>= 4.2.0)
Imports:
lifecycle,
grDevices,
cli,
utils,
vctrs,
glue,
dplyr,
tidyr,
tidyselect,
rlang,
stringi,
forcats,
ggplot2,
fs,
ggiraph,
ggplot2,
glue,
grDevices,
lifecycle,
mschart,
officer,
fs
rlang,
stringi,
tidyr,
tidyselect,
utils,
vctrs
Suggests:
covr,
srvyr,
writexl,
haven,
readr,
labelled,
quarto,
knitr,
readr,
scales,
spelling,
srvyr,
testthat (>= 3.0.0),
tibble,
vdiffr,
withr,
spelling,
vdiffr
writexl
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.3.2
Expand Down
51 changes: 51 additions & 0 deletions R/_aggregate_metadata_yml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# #' Aggregate _metadata.yml
# #'
# #' For use within a qmd-file to obtain list parameters from _metadata.yml-files in the subfolders.
# #' Parameters are inherited and updated from parent to child folders.
# #'
# #' @export
# #'
# aggregate_metadata_yml <- function() {
# # Get the current input directory
# current_dir <- knitr::current_input(dir = TRUE) |> fs::path_dir()

# # Initialize an empty list to store metadata
# aggregated_metadata <- list()

# # Traverse up the directory hierarchy until no _metadata.yml is found
# dirs <- list()
# tmp <- current_dir
# while (TRUE) {
# metadata_file <- fs::path(tmp, "_metadata.yml")

# if (fs::file_exists(metadata_file)) {
# dirs <- c(tmp, dirs)
# } else {
# break
# }

# parent_folder <- fs::path(tmp, "..") |> fs::path_norm()

# # Stop if the parent folder is the same as the current folder (root reached)
# if (tmp == parent_folder) {
# break
# }

# tmp <- parent_folder
# }

# # Traverse from the upper-most directory downward
# for (dir in dirs) {
# metadata_file <- fs::path(dir, "_metadata.yml")

# if (fs::file_exists(metadata_file)) {
# # Read the metadata and merge it into the aggregated metadata
# metadata_content <- yaml::read_yaml(metadata_file)
# aggregated_metadata <- utils::modifyList(aggregated_metadata, metadata_content)
# }
# }

# return(aggregated_metadata)
# }

# aggregate_metadata_yaml <- aggregate_metadata_yml
15 changes: 15 additions & 0 deletions R/check_no_duplicated_label_suffix.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
check_no_duplicated_label_suffix <- function(data_summary, error_on_duplicates = TRUE) {
duplicates <-
data_summary |>
dplyr::grouped_df(vars = c(".variable_label")) |>
dplyr::filter(dplyr::n_distinct(.data[[".variable_name"]], na.rm = FALSE) > 1) |>
dplyr::ungroup()
if (nrow(duplicates) > 0 && !all(is.na(duplicates[[".variable_label"]]))) {
msg <- "Found duplicated variable labels: {unique(duplicates[['.variable_label']])}"
if (isTRUE(error_on_duplicates)) {
cli::cli_abort(msg)
} else {
cli::cli_warn(msg)
}
}
}
12 changes: 11 additions & 1 deletion R/makeme.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,16 @@
#'
#' Separator for main question from sub-question.
#'
#' @param error_on_duplicates *Error or warn on duplicate labels*
#'
#' `scalar<logical>` // *default:* `TRUE` (`optional`)
#'
#' Whether to abort (`TRUE`) or warn (`FALSE`) if the same label (suffix) is
#' used across multiple variables.
#'
#' @param require_common_categories *Check common categories*
#'
#' `scalar<logical>` // *default:* `NULL` (`optional`)
#' `scalar<logical>` // *default:* `TRUE` (`optional`)
#'
#' Whether to check if all items share common categories.
#'
Expand Down Expand Up @@ -412,6 +419,7 @@ makeme <-
totals = FALSE,
categories_treated_as_na = NULL,
label_separator = " - ",
error_on_duplicates = TRUE,
showNA = c("ifany", "always", "never"),
data_label = c("percentage_bare", "percentage", "proportion", "count"),
html_interactive = TRUE,
Expand Down Expand Up @@ -654,6 +662,8 @@ makeme <-
args$main_question <-
as.character(unique(args$data_summary[[".variable_label_prefix"]]))

check_no_duplicated_label_suffix(data_summary = args$data_summary, error_on_duplicates = args$error_on_duplicates)

if (!args$type %in% c("sigtest_table_html")) {
args$data_summary <-
post_process_makeme_data(
Expand Down
5 changes: 4 additions & 1 deletion R/summarize_cat_cat_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ sort_data <- function(data_summary,
#' Both the absolute and relative folderpaths are required, as strings.
#' @importFrom rlang !!!
#' @keywords internal
#' @return Dataset
#' @return Dataset with the columns: `.variable_name`, `.variable_label`, `.category`,
#' `.count`, `.count_se`, `.count_per_dep`, `.count_per_indep_group`, `.proportion`, `.proportion_se`,
#' `.mean`, `.mean_se`, <indep>-variable(s), `.data_label`, `.comb_categories`, `.sum_value`,
#' `.variable_label_prefix`
#'
summarize_cat_cat_data <-
function(data,
Expand Down
10 changes: 9 additions & 1 deletion man/makeme.Rd

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

5 changes: 4 additions & 1 deletion man/summarize_cat_cat_data.Rd

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

2 changes: 2 additions & 0 deletions vignettes/for_chapter_author.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ vignette: >
%\VignetteIndexEntry{Editing a Saros-drafted chapter - for chapter authors}
%\VignetteEngine{quarto::html}
%\VignetteEncoding{UTF-8}
execute:
eval: false
---

# Configuring your computer
Expand Down
2 changes: 2 additions & 0 deletions vignettes/for_developers.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ vignette: >
%\VignetteIndexEntry{Understanding Saros architecture and constructing extensions}
%\VignetteEngine{quarto::html}
%\VignetteEncoding{UTF-8}
execute:
eval: false
---

```{r setup}
Expand Down
4 changes: 3 additions & 1 deletion vignettes/for_readers.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ vignette: >
%\VignetteIndexEntry{Maximizing the fun of exploring a Saros-based report - for the readers}
%\VignetteEngine{quarto::html}
%\VignetteEncoding{UTF-8}
execute:
eval: false
---

```{r setup}
```{r setup2}
library(saros)
```
2 changes: 2 additions & 0 deletions vignettes/saros_name.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ vignette: >
%\VignetteIndexEntry{What's in a name?}
%\VignetteEngine{quarto::html}
%\VignetteEncoding{UTF-8}
execute:
eval: false
---

# Connection to the Astronomical concept of Saros
Expand Down

0 comments on commit 2dd17be

Please sign in to comment.