Title: | Base Tools for Semi-Automatic Reporting of Ordinary Surveys |
---|---|
Description: | Scaffold an entire web-based report using template chunks, based on a small chapter overview and a dataset. Highly adaptable with prefixes, suffixes, translations, etc. Also contains tools for password-protecting, e.g. for each organization's report on a website. Developed for the common case of a survey across multiple organizations/sites where each organization wants to obtain results for their organization compared with everyone else. See 'saros' (<https://CRAN.R-project.org/package=saros>) for tools used for authors in the drafted reports. |
Authors: | Stephan Daus [aut, cre, cph] , Nordic Institute for The Studies of Innovation, Research and Education (NIFU) [fnd], Kristiania University College [fnd] |
Maintainer: | Stephan Daus <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-09-19 05:23:39 UTC |
Source: | https://github.com/nifu-no/saros.base |
Convenience Function to Copy Only the Contents of A Folder to Another Folder
copy_folder_contents_to_dir( from, to, overwrite = FALSE, only_copy_folders = FALSE )
copy_folder_contents_to_dir( from, to, overwrite = FALSE, only_copy_folders = FALSE )
to , from
|
String, path from where to copy the contents, and where to copy them to. |
overwrite |
Flag. Defaults to FALSE. |
only_copy_folders |
Flag. Defaults to FALSE. If TRUE, only copies folders. |
No return value, called for side effects
copy_folder_contents_to_dir( from = system.file("help", "figures", package = "dplyr"), to = tempdir() )
copy_folder_contents_to_dir( from = system.file("help", "figures", package = "dplyr"), to = tempdir() )
Create a Pre-defined Directory Hierarchy on Disk
create_directory_structure( path, structure_path = system.file("templates", "_project_structure_en.yaml", package = "saros.base"), numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, word_separator = NULL, numbering_parent_child_separator = word_separator, numbering_name_separator = " ", case = c("asis", "sentence", "title", "lower", "upper", "snake"), replacement_list = c(project_initials = "SSN"), create = FALSE, count_existing_folders = FALSE )
create_directory_structure( path, structure_path = system.file("templates", "_project_structure_en.yaml", package = "saros.base"), numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, word_separator = NULL, numbering_parent_child_separator = word_separator, numbering_name_separator = " ", case = c("asis", "sentence", "title", "lower", "upper", "snake"), replacement_list = c(project_initials = "SSN"), create = FALSE, count_existing_folders = FALSE )
path |
String, path to where to create the project files |
structure_path |
String. Path to the YAML file that defines the folder structure. Defaults to system.file("templates", "_project_structure_en.yaml"). |
numbering_prefix |
String. One of c("none", "max_local", "max_global"). |
numbering_inheritance |
Flag. Whether to inherit numbering from parent folder. |
word_separator |
String. Replace separators between words in folder names. Defaults to NULL. |
numbering_parent_child_separator |
String. Defaults to word_separator. |
numbering_name_separator |
String. Separator between numbering part and name. |
case |
String. One of c("asis", "sentence", "lower", "upper", "title", "snake"). |
replacement_list |
named character vector. Each name in this vector will be replaced with its |
create |
Boolean. Defaults to TRUE in initialize_saros_project(), FALSE in create_directory_structure(). |
count_existing_folders |
Boolean. Defaults to FALSE. |
No return value, called for side effects
create_directory_structure(path = tempdir())
create_directory_structure(path = tempdir())
Create Data Frame Containing Email Drafts with User Credentials
create_email_credentials( email_data_frame, email_col = "email", username_col = "username", local_main_password_path = ".htpasswd_private", ignore_missing_emails = FALSE, email_body = "Login credentials are \nUsername: {username},\nPassword: {password}", email_subject = "User credentials for website example.net.", ... )
create_email_credentials( email_data_frame, email_col = "email", username_col = "username", local_main_password_path = ".htpasswd_private", ignore_missing_emails = FALSE, email_body = "Login credentials are \nUsername: {username},\nPassword: {password}", email_subject = "User credentials for website example.net.", ... )
email_data_frame |
Data.frame/tibble with (at least) emails and usernames |
email_col |
String, name of email column |
username_col |
String, name of username column in email_data_frame |
local_main_password_path |
Path to a local .htpasswd file containing username:password header and : as separator. |
ignore_missing_emails |
Flag, defaults to FALSE. Whether usernames existing in password file but not email file will result in warnings. |
email_body , email_subject
|
String, subject line and email body respectively. Supports glue syntax referring to columns found in the email data frame or password file. |
... |
Dynamic dots forwarded to quarto::quarto_render |
Data.frame
Create Folder with Placeholder R-files Based on Structure in CSV-file
create_r_files( r_files_out_path, r_files_source_path = system.file("templates", "r_files.csv", package = "saros.base"), r_optionals = TRUE, r_add_file_scope = TRUE, r_prefix_file_scope = "### ", r_add_folder_scope_as_README = FALSE, word_separator = NULL, case = c("asis", "sentence", "title", "lower", "upper", "snake"), numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, numbering_parent_child_separator = word_separator, numbering_name_separator = " " )
create_r_files( r_files_out_path, r_files_source_path = system.file("templates", "r_files.csv", package = "saros.base"), r_optionals = TRUE, r_add_file_scope = TRUE, r_prefix_file_scope = "### ", r_add_folder_scope_as_README = FALSE, word_separator = NULL, case = c("asis", "sentence", "title", "lower", "upper", "snake"), numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, numbering_parent_child_separator = word_separator, numbering_name_separator = " " )
r_files_out_path |
String, path to where to place R placeholder files. If NULL, will not create any. |
r_files_source_path |
String, path to where to find CSV-field containing the columns folder_name, folder_scope, file_name, file_scope. If NULL, defaults to system.file("templates", "r_files.csv")). |
r_optionals |
Flag. Whether to add files marked as 1 (or TRUE) in the optional column. Defaults to TRUE. |
r_add_file_scope |
Flag. Whether to add value from column 'file_scope' to beginning of each file. Default to TRUE. |
r_prefix_file_scope |
String to add before file_scope. Defaults to "### " |
r_add_folder_scope_as_README |
Flag. Whether to create README file in each folder with the folder_scope column cell in r_files_source_path. Defaults to FALSE. |
word_separator |
String. Replace separators between words in folder names. Defaults to NULL. |
case |
String. One of c("asis", "sentence", "lower", "upper", "title", "snake"). |
numbering_prefix |
String. One of c("none", "max_local", "max_global"). |
numbering_inheritance |
Flag. Whether to inherit numbering from parent folder. |
numbering_parent_child_separator |
String. Defaults to word_separator. |
numbering_name_separator |
String. Separator between numbering part and name. |
No return value, called for side effects
create_r_files(r_files_out_path = tempdir())
create_r_files(r_files_out_path = tempdir())
Wrapper to Download and Unzip a Github Repository to A Folder
download_zip_to_folder( github_zip_url = "https://github.com/NIFU-NO/nifutemplates/archive/refs/heads/main.zip", zip_path = tempfile(fileext = ".zip"), files = NULL, out_path, prompt = TRUE, overwrite = FALSE, open_project = FALSE, newSession = TRUE )
download_zip_to_folder( github_zip_url = "https://github.com/NIFU-NO/nifutemplates/archive/refs/heads/main.zip", zip_path = tempfile(fileext = ".zip"), files = NULL, out_path, prompt = TRUE, overwrite = FALSE, open_project = FALSE, newSession = TRUE )
github_zip_url |
URL to zip file, as string. |
zip_path |
String, where to store zip-file. Defaults to a temporary location. |
files |
Character vector of files in zip-file to include. See |
out_path |
String, directory to where to store the unzipped files. |
prompt |
Flag, whether to ask user if conflicting files should be overwritten, if any. Defaults to TRUE. |
overwrite |
Flag, whether to overwrite files in out_path. Defaults to FALSE. |
open_project |
Flag or string. If FALSE (default), does nothing. If TRUE (requires |
newSession |
Flag. Whether to open new project in a new RStudio session. Defaults to TRUE. |
Character vector of unzipped files.
download_zip_to_folder( github_zip_url = "https://github.com/NIFU-NO/nifutemplates/archive/refs/heads/main.zip", out_path = tempdir(), overwrite = TRUE )
download_zip_to_folder( github_zip_url = "https://github.com/NIFU-NO/nifutemplates/archive/refs/heads/main.zip", out_path = tempdir(), overwrite = TRUE )
The draft_report()
function takes a raw dataset (data
-argument) and the
output from the refine_chapter_overview()
-function as the
chapter_structure
-argument and outputs a set of pre-populated qmd-files in the
specified path
-folder. You can edit, render, and
ultimately publish these as usual with Quarto features in RStudio. See also
{saros.post}
-package for post-processing tools.
draft_report( data, chapter_structure, ..., path = tempdir(), title = "Report", authors = NULL, authors_col = "author", chapter_yaml_file = NULL, chapter_qmd_start_section_filepath = NULL, chapter_qmd_end_section_filepath = NULL, index_filename = "index", index_yaml_file = NULL, index_qmd_start_section_filepath = NULL, index_qmd_end_section_filepath = NULL, report_filename = "0_report", report_yaml_file = NULL, report_qmd_start_section_filepath = NULL, report_qmd_end_section_filepath = NULL, ignore_heading_for_group = c(".template_name", ".variable_type_dep", ".variable_type_indep", ".variable_group_dep", "chapter"), replace_heading_for_group = c(.variable_label_suffix_dep = ".variable_name_dep", .variable_label_suffix_indep = ".variable_name_indep"), prefix_heading_for_group = NULL, suffix_heading_for_group = NULL, require_common_categories = TRUE, combined_report = TRUE, attach_chapter_dataset = TRUE, auxiliary_variables = NULL, serialized_format = c("rds", "qs"), max_path_warning_threshold = 260, log_file = NULL )
draft_report( data, chapter_structure, ..., path = tempdir(), title = "Report", authors = NULL, authors_col = "author", chapter_yaml_file = NULL, chapter_qmd_start_section_filepath = NULL, chapter_qmd_end_section_filepath = NULL, index_filename = "index", index_yaml_file = NULL, index_qmd_start_section_filepath = NULL, index_qmd_end_section_filepath = NULL, report_filename = "0_report", report_yaml_file = NULL, report_qmd_start_section_filepath = NULL, report_qmd_end_section_filepath = NULL, ignore_heading_for_group = c(".template_name", ".variable_type_dep", ".variable_type_indep", ".variable_group_dep", "chapter"), replace_heading_for_group = c(.variable_label_suffix_dep = ".variable_name_dep", .variable_label_suffix_indep = ".variable_name_indep"), prefix_heading_for_group = NULL, suffix_heading_for_group = NULL, require_common_categories = TRUE, combined_report = TRUE, attach_chapter_dataset = TRUE, auxiliary_variables = NULL, serialized_format = c("rds", "qs"), max_path_warning_threshold = 260, log_file = NULL )
data |
Survey data
A data frame (or a srvyr-object) with the columns specified in the chapter_structure 'dep', etc columns. |
chapter_structure |
What goes into each chapter and sub-chapter
Data frame (or tibble, possibly grouped). One row per chapter. Should contain the columns 'chapter' and 'dep', Optionally 'indep' (independent variables) and other informative columns as needed. |
... |
Dynamic dots Arguments forwarded to the corresponding functions that create the elements. |
path |
Output path
Path to save all output. Defaults to a temporary directory. |
title |
Title of report
Added automatically to YAML-header of index.qmd and report.qmd-files. |
authors |
Authors of entire report
If NULL, infers from |
authors_col |
Column name for author
Only used if it exists. Multiple authors are separated by semicolon (and optionally with a subsequent space). |
chapter_yaml_file |
Path to YAML-file to insert into each chapter qmd-file
Path to file used to insert header YAML, in each chapter. |
chapter_qmd_start_section_filepath , chapter_qmd_end_section_filepath , index_qmd_start_section_filepath , index_qmd_end_section_filepath , report_qmd_start_section_filepath , report_qmd_end_section_filepath
|
Path to qmd-bit for start/end of each qmd
Path to qmd-snippet placed before/after body of all chapter/index/report qmd-files. |
index_filename |
Index filename
The name of the main index Quarto file used as landing page for each report. Will link to a PDF (report.qmd) which collects all chapters. |
index_yaml_file , report_yaml_file
|
Path to YAML-file to insert into index.qmd and 0_report.qmd respectively
Path to file used to insert header YAML, in index and report files. |
report_filename |
Report filename
The name of the main report QMD-file used when compiling a complete report
collecting all chapters in its folder (except itself).
If provided, will be linked to in the index.
If NULL, will generate a filename based on the report title, prefixed with "0_".
To turn off, set |
ignore_heading_for_group |
Ignore heading for group
Type of refined chapter_structure data for which to suppress the heading in the report output. Typically variable_name_dep, variable_name_indep, etc. |
replace_heading_for_group |
Replacing heading for group
Occasionally, one needs to replace the heading with another piece of information in the refined chapter_structure. For instance, one may want to organize output by variable_name_indep, but to display the variable_label_indep instead. Use the name for the replacement and the value for the original. |
prefix_heading_for_group , suffix_heading_for_group
|
Prefix and suffix headings
Names are heading_groups, values are the prefixes and suffixes. Note
that prefixes should end with a |
require_common_categories |
Check common categories
Whether to check if all items share common categories. |
combined_report |
Create a combined report?
Whether to create a qmd file that merges all chapters into a combined report. |
attach_chapter_dataset |
Toggle inclusion of chapter-specific datasets in qmd-files
Whether to save in each chapter folder an 'Rds'-file with the chapter-specific dataset, and load it at the top of each QMD-file. |
auxiliary_variables |
Auxiliary variables to be included in datasets
Column names in |
serialized_format |
Serialized format
Format for serialized data when storing chapter dataset.
One of |
max_path_warning_threshold |
Maximum number of characters in paths warning
Microsoft has set an absolute limit of 260 characters for its Sharepoint/OneDrive file paths. This will mean that files with cache (hash suffixes are added) will quickly breach this limit. When set, a warning will be returned if files are found to be longer than this threshold. Also note that spaces count as three characters due to its URL-conversion: %20. To avoid test, set to Inf |
log_file |
Path to log file
Path to log file. Set to NULL to disable logging. |
Note that saros treats data as they are stored: numeric, integer, factor, ordinal, character, and datetime. Currently, only factor/ordinal and character are implemented.
The path
-argument.
ex_survey_ch_structure <- refine_chapter_overview( chapter_overview = ex_survey_ch_overview, data = ex_survey ) index_filepath <- draft_report( chapter_structure = ex_survey_ch_structure, data = ex_survey, path = tempdir() )
ex_survey_ch_structure <- refine_chapter_overview( chapter_overview = ex_survey_ch_overview, data = ex_survey ) index_filepath <- draft_report( chapter_structure = ex_survey_ch_structure, data = ex_survey, path = tempdir() )
A dataset containing fake respondents' answers to survey questions. The first two, x_sex and x_human, are intended to be independent variables, whereas the remaining are dependent. The underscore _ in variable names separates item groups (prefix) from items (suffix) (i.e. a_1-a_9 => a + 1-9), whereas ' - ' separates the same for labels. The latter corresponds with the default in SurveyXact.
ex_survey
ex_survey
A data frame with 100 rows and 29 variables:
Gender
Is respondent human?
Where is the respondent born?
Do you consent to the following? - Agreement #1
Do you consent to the following? - Agreement #2
Do you consent to the following? - Agreement #3
Do you consent to the following? - Agreement #4
Do you consent to the following? - Agreement #5
Do you consent to the following? - Agreement #6
Do you consent to the following? - Agreement #7
Do you consent to the following? - Agreement #8
Do you consent to the following? - Agreement #9
How much do you like living in - Beijing
How much do you like living in - Brussels
How much do you like living in - Budapest
How many years of experience do you have in - Company A
How many years of experience do you have in - Company B
Rate your degree of confidence doing the following - Driving
Rate your degree of confidence doing the following - Drinking
Rate your degree of confidence doing the following - Driving
Rate your degree of confidence doing the following - Dancing
How often do you do the following? - Eat
How often do you do the following? - Eavesdrop
How often do you do the following? - Exercise
How often do you do the following? - Encourage someone whom you have only recently met and who struggles with simple tasks that they cannot achieve by themselves
To what extent do you agree or disagree to the following policies - Red Party
To what extent do you agree or disagree to the following policies - Green Party
To what extent do you agree or disagree to the following policies - Yellow Party
To what extent do you agree or disagree to the following policies - Blue Party
Which of the following universities would you prefer to study at?
Do you have any comments to the survey?
Response status
Note that only chapter and dep are compulsory.
ex_survey_ch_overview
ex_survey_ch_overview
A data frame with 5 rows (chapters) and 5 variables:
Manual entry chapter title
Single, or multiple authors separated by semicolon
Columns in ex_survey having the role of dependent variable
Columns in ex_survey having the role of independent variable
Just a column about something else to verify that the system works also with superfluous information.
File/folder name sanitizer replacing space and punctuation with underscore
filename_sanitizer( x, max_chars = NA_integer_, accept_hyphen = FALSE, sep = "_", valid_obj = FALSE, to_lower = FALSE, make_unique = TRUE )
filename_sanitizer( x, max_chars = NA_integer_, accept_hyphen = FALSE, sep = "_", valid_obj = FALSE, to_lower = FALSE, make_unique = TRUE )
x |
Character vector of file/folder names |
max_chars |
Maximum character length |
accept_hyphen |
Flag, whether a hyphen - is acceptable. |
sep |
String, replacement for illegal characters and spaces. |
valid_obj |
Flag, whether output should be valid as R object name. |
to_lower |
Flag, whether to force all characters to lower. |
make_unique |
Flag, whether all should be unique. |
Character vector of same length as x
filename_sanitizer(c("Too long a name", "with invalid *^/&#"))
filename_sanitizer(c("Too long a name", "with invalid *^/&#"))
Generate YAML File from Directory Structure
generate_yaml_from_directory( input_path = tempdir(), output_yaml_path = "_project_structure_en.yaml", remove_prefix_numbers = FALSE )
generate_yaml_from_directory( input_path = tempdir(), output_yaml_path = "_project_structure_en.yaml", remove_prefix_numbers = FALSE )
input_path |
String. The path to the directory whose structure needs to be captured. |
output_yaml_path |
String. The path where the YAML file will be saved. |
remove_prefix_numbers |
Boolean. Whether to remove numeric prefixes and any resulting leading non-alphanumeric characters from folder names. Defaults to FALSE. |
No return value, called for side effects
generate_yaml_from_directory( output_yaml_path = tempfile("_project_structure_en", fileext = ".yaml") )
generate_yaml_from_directory( output_yaml_path = tempfile("_project_structure_en", fileext = ".yaml") )
Get Global Options for Chunk Templates
get_chunk_template_defaults(variant = 1)
get_chunk_template_defaults(variant = 1)
variant |
Positive integer. |
List with options in R
get_chunk_template_defaults()
get_chunk_template_defaults()
Helper function to extract raw variable labels from the data
get_raw_labels(data, col_pos = NULL, return_as_list = FALSE)
get_raw_labels(data, col_pos = NULL, return_as_list = FALSE)
data |
Dataset |
col_pos |
Optional, character vector of column names or integer vector of positions |
return_as_list |
Flag, whether to return as list or character vector |
List or character vector
Can be used programatically from the console, or simply use the New Project Wizard.
initialize_saros_project( path, structure_path = NULL, numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, word_separator = NULL, numbering_name_separator = " ", replacement_list = NULL, numbering_parent_child_separator = word_separator, case = c("asis", "sentence", "title", "lower", "upper", "snake"), count_existing_folders = FALSE, r_files_out_path = NULL, r_files_source_path = system.file("templates", "r_files.csv", package = "saros.base"), r_optionals = TRUE, r_add_file_scope = TRUE, r_prefix_file_scope = "### ", r_add_folder_scope_as_README = FALSE, create = TRUE )
initialize_saros_project( path, structure_path = NULL, numbering_prefix = c("none", "max_local", "max_global"), numbering_inheritance = TRUE, word_separator = NULL, numbering_name_separator = " ", replacement_list = NULL, numbering_parent_child_separator = word_separator, case = c("asis", "sentence", "title", "lower", "upper", "snake"), count_existing_folders = FALSE, r_files_out_path = NULL, r_files_source_path = system.file("templates", "r_files.csv", package = "saros.base"), r_optionals = TRUE, r_add_file_scope = TRUE, r_prefix_file_scope = "### ", r_add_folder_scope_as_README = FALSE, create = TRUE )
path |
String, path to where to create the project files |
structure_path |
String. Path to the YAML file that defines the folder structure. Defaults to system.file("templates", "_project_structure_en.yaml"). |
numbering_prefix |
String. One of c("none", "max_local", "max_global"). |
numbering_inheritance |
Flag. Whether to inherit numbering from parent folder. |
word_separator |
String. Replace separators between words in folder names. Defaults to NULL. |
numbering_name_separator |
String. Separator between numbering part and name. |
replacement_list |
named character vector. Each name in this vector will be replaced with its |
numbering_parent_child_separator |
String. Defaults to word_separator. |
case |
String. One of c("asis", "sentence", "lower", "upper", "title", "snake"). |
count_existing_folders |
Boolean. Defaults to FALSE. |
r_files_out_path |
String, path to where to place R placeholder files. If NULL, will not create any. |
r_files_source_path |
String, path to where to find CSV-field containing the columns folder_name, folder_scope, file_name, file_scope. If NULL, defaults to system.file("templates", "r_files.csv")). |
r_optionals |
Flag. Whether to add files marked as 1 (or TRUE) in the optional column. Defaults to TRUE. |
r_add_file_scope |
Flag. Whether to add value from column 'file_scope' to beginning of each file. Default to TRUE. |
r_prefix_file_scope |
String to add before file_scope. Defaults to "### " |
r_add_folder_scope_as_README |
Flag. Whether to create README file in each folder with the folder_scope column cell in r_files_source_path. Defaults to FALSE. |
create |
Boolean. Defaults to TRUE in initialize_saros_project(), FALSE in create_directory_structure(). |
Returns invisibly path
initialize_saros_project(path = tempdir())
initialize_saros_project(path = tempdir())
Returns TRUE if object is a character of length 1.
is_string(x)
is_string(x)
x |
Object |
Bool
draft_report()
from YAML-fileRead Default Arguments for draft_report()
from YAML-file
read_default_draft_report_args(path)
read_default_draft_report_args(path)
path |
|
The defaults as a yaml
-object.
tmpfile <- tempfile(fileext = ".yaml") write_default_draft_report_args(path = tmpfile) read_default_draft_report_args(path = tmpfile)
tmpfile <- tempfile(fileext = ".yaml") write_default_draft_report_args(path = tmpfile) read_default_draft_report_args(path = tmpfile)
Processes A 'chapter_overview' Data Frame
refine_chapter_overview( chapter_overview = NULL, data = NULL, chunk_templates = NULL, label_separator = " - ", name_separator = NULL, single_y_bivariates_if_indep_cats_above = 3, single_y_bivariates_if_deps_above = 20, always_show_bi_for_indep = NULL, hide_bi_entry_if_sig_above = 1, hide_chunk_if_n_below = 10, hide_variable_if_all_na = TRUE, organize_by = c("chapter", ".variable_label_prefix_dep", ".variable_name_indep", ".template_name"), arrange_section_by = c(chapter = FALSE, .variable_name_dep = FALSE, .variable_name_indep = FALSE, .template_name = FALSE), na_first_in_section = TRUE, max_width_obj = 128, max_width_chunk = 128, max_width_file = 64, max_width_folder_name = 12, sep_obj = "_", sep_chunk = "-", sep_file = "-", ..., progress = TRUE, variable_group_dep = ".variable_group_dep", variable_group_prefix = NULL, n_range_glue_template_1 = "{n}", n_range_glue_template_2 = "[{n[1]}-{n[2]}]", log_file = NULL )
refine_chapter_overview( chapter_overview = NULL, data = NULL, chunk_templates = NULL, label_separator = " - ", name_separator = NULL, single_y_bivariates_if_indep_cats_above = 3, single_y_bivariates_if_deps_above = 20, always_show_bi_for_indep = NULL, hide_bi_entry_if_sig_above = 1, hide_chunk_if_n_below = 10, hide_variable_if_all_na = TRUE, organize_by = c("chapter", ".variable_label_prefix_dep", ".variable_name_indep", ".template_name"), arrange_section_by = c(chapter = FALSE, .variable_name_dep = FALSE, .variable_name_indep = FALSE, .template_name = FALSE), na_first_in_section = TRUE, max_width_obj = 128, max_width_chunk = 128, max_width_file = 64, max_width_folder_name = 12, sep_obj = "_", sep_chunk = "-", sep_file = "-", ..., progress = TRUE, variable_group_dep = ".variable_group_dep", variable_group_prefix = NULL, n_range_glue_template_1 = "{n}", n_range_glue_template_2 = "[{n[1]}-{n[2]}]", log_file = NULL )
chapter_overview |
What goes into each chapter and sub-chapter
Data frame (or tibble, possibly grouped). One row per chapter. Should contain the columns 'chapter' and 'dep', Optionally 'indep' (independent variables) and other informative columns as needed. |
data |
Survey data
A data frame (or a srvyr-object) with the columns specified in the chapter_structure 'dep', etc columns. |
chunk_templates |
Chunk templates
Must contain columns |
label_separator |
Variable label separator
String to split labels on main question and sub-items. |
name_separator |
Variable name separator
String to split column names in data between main question and sub-items |
single_y_bivariates_if_indep_cats_above |
Single y bivariates if indep-cats above ...
Figures and tables for bivariates can become very long if the independent variable has many categories. This argument specifies the number of indep categories above which only single y bivariates should be shown. |
single_y_bivariates_if_deps_above |
Single y bivariates if dep-vars above ...
Figures and tables for bivariates can become very long if there are many dependent variables in a battery/question matrix. This argument specifies the number of dep variables above which only single y bivariates should be shown. Set to 0 to always show single y bivariates. |
always_show_bi_for_indep |
Always show bivariate for indep-variable
Specific combinations with a by-variable where bivariates should always be shown. |
hide_bi_entry_if_sig_above |
p-value threshold for hiding bivariate entry
Whether to hide bivariate entry if significance is above this value. Defaults to showing all. |
hide_chunk_if_n_below |
Hide result if N below
Whether to hide result if N for a given dataset is below this value. NOTE: Exceptions will be made to chr_table and chr_plot as these are typically exempted in the first place. This might change in the future with a separate argument. |
hide_variable_if_all_na |
Hide variable from outputs if containing all NA
Whether to remove variables if all values are NA. |
organize_by |
Grouping columns
Column names used for identifying chapters and sections. |
arrange_section_by |
Grouping columns
Column names used for sorting section within each organize_by group. If character vector, will assume all are to be arranged in ascending order. If a named logical vector, FALSE will indicate ascending, TRUE descending. Defaults to sorting in ascending order (alphabetical) for commonly needed variable name/label info, and in descending order for chunk_templates as one typically wants univariates before bivariates. |
na_first_in_section |
Whether to place NAs first when sorting
Default ascending and descending sorting with |
max_width_obj , max_width_chunk , max_width_file
|
Maximum object width
Maximum width for names of objects (in R/Python environment),
chunks (#| label: ) and optional files. Note, will always replace variable
labels with variable names, to avoid very long file names.
Note for filenames: Due to OneDrive having a max path of about
400 characters, this can quickly be exceeded with a long path base path,
long file names if using labels as part of structure, and hashing with
Quarto's |
max_width_folder_name |
Maximum clean folder name length
Whereas |
sep_obj , sep_chunk , sep_file
|
Separator string
Separator to use between grouping variables. Defaults to underscore for object names and hyphen for chunk labels and file names. |
... |
Dynamic dots Arguments forwarded to the corresponding functions that create the elements. |
progress |
Whether to display progress message
Mostly useful when hide_bi_entry_if_sig_above < 1 |
variable_group_dep |
Name for the variable_group_dep column
This column is used to group variables that are part of the same bivariate analysis. |
variable_group_prefix |
Set a prefix to more easily find it in your labels
By default, the .variable_group column is just integers. If you wish to use this as part of your object/label/filename numbering scheme, a number by itself will not be very informative. Hence you could set a prefix such as "Group" to distinguish this column from other columns in the chapter_structure. |
n_range_glue_template_1 , n_range_glue_template_2
|
Glue templates for the n_range columns to be created. |
log_file |
Path to log file
Path to log file. Set to NULL to disable logging. |
Grouped tibble.
ref_df <- refine_chapter_overview(chapter_overview = ex_survey_ch_overview) ref_df2 <- refine_chapter_overview(chapter_overview = ex_survey_ch_overview, data = ex_survey, hide_bi_entry_if_sig_above=.05)
ref_df <- refine_chapter_overview(chapter_overview = ex_survey_ch_overview) ref_df2 <- refine_chapter_overview(chapter_overview = ex_survey_ch_overview, data = ex_survey, hide_bi_entry_if_sig_above=.05)
Create a _headers file for 'Netlify' publishing or a set of .htaccess and .htpasswd files (FTP) placed in the specific subfolders.
setup_access_restrictions( remote_basepath = "/home/", local_basepath, rel_path_base_to_parent_of_user_restricted_folder = file.path("Reports", "2022", "Mesos"), warn = TRUE, local_main_password_path = ".main_htpasswd_public", username_folder_matching_df = NULL, universal_usernames = c("admin"), log_rounds = 12, append_users = TRUE, password_input = "prompt", type = c("netlify", "apache") )
setup_access_restrictions( remote_basepath = "/home/", local_basepath, rel_path_base_to_parent_of_user_restricted_folder = file.path("Reports", "2022", "Mesos"), warn = TRUE, local_main_password_path = ".main_htpasswd_public", username_folder_matching_df = NULL, universal_usernames = c("admin"), log_rounds = 12, append_users = TRUE, password_input = "prompt", type = c("netlify", "apache") )
remote_basepath |
String. Folder where site will be located if using FTP-server. Needed for .htaccess-files. |
local_basepath |
String. Local folder for website, typically "_site". |
rel_path_base_to_parent_of_user_restricted_folder |
String, relative path from basepath to the folder where the restricted folders are located. (E.g. the "mesos"-folder) |
warn |
Flag. Whether to provide warning or error if paths do not exist. |
local_main_password_path |
String. Path to main file containing all usernames and passwords formatted with a colon between username and password. |
username_folder_matching_df |
Data frame. If NULL (default), will use folder names as usernames. Otherwise, a data frame with two columns: "folder" and "username" where "folder" is the name of the folder and "username" is the username for that folder. |
universal_usernames |
Character vector. Usernames in local_main_htpasswd_path which always have access to folder |
log_rounds |
Integer, number of rounds in the bcrypt algorithm. The higher the more time consuming and harder to brute-force. |
append_users |
Boolean, if TRUE (default) will create new users and add them to local_main_password_path. See also password_input. |
password_input |
String, either "prompt" which asks the user for input. Alternatively, a number stored as string for a generated random password of said length: "8", "10", "12", "16" |
type |
Character vector. "netlify" will create _headers file used for Netlify. "apache" will create .htaccess and .htpasswd files used for general FTP-servers. |
String, the path to the newly created _headers-file or .htaccess files.
draft_report()
to YAML-fileWrite Default Arguments for draft_report()
to YAML-file
write_default_draft_report_args( path, ignore_args = c("data", "...", "dep", "indep", "chapter_structure", "chapter_overview", "path") )
write_default_draft_report_args( path, ignore_args = c("data", "...", "dep", "indep", "chapter_structure", "chapter_overview", "path") )
path |
|
ignore_args |
A character vector of argument (names) not to be written to file. |
The defaults as a yaml
-object.
write_default_draft_report_args(path = tempfile(fileext = ".yaml"))
write_default_draft_report_args(path = tempfile(fileext = ".yaml"))