-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from NIFU-NO/minor_fixes_for_cran_release
Minor fixes for cran release
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#' Create QMD-files for the mesos groups in a mesos variable | ||
#' | ||
#' @param dir_path String, path to folder where the reference qmd-files are stored | ||
#' (and where in which the new mesos folders will be created) | ||
#' @param mesos_var String, inserted into qmd-files as `params$mesos_var` | ||
#' @param mesos_groups Character vector of mesos groups. | ||
#' | ||
#' @return Data frame with with names. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' writeLines(c(""), con = fs::path(tempdir(), "index.qmd")) | ||
#' create_mesos_qmd_files(dir_path=tempdir(), | ||
#' mesos_var = "f_uni", mesos_groups = paste0("Uni of ", LETTERS[1:5])) | ||
create_mesos_qmd_files <- function( | ||
dir_path, | ||
mesos_var, | ||
mesos_groups) { | ||
|
||
new_qmd_files <- | ||
fs::dir_ls(path = dir_path, regexp = "\\.qmd", recurse = FALSE) | ||
if(length(new_qmd_files)==0) { | ||
cli::cli_abort("No files found.") | ||
} | ||
new_qmd_files <- | ||
new_qmd_files |> | ||
stringi::stri_replace_last_fixed(pattern = ".qmd", replacement = "") |> | ||
basename() |> | ||
tidyr::expand_grid(main_file = _, mesos_group = mesos_groups) |> | ||
dplyr::mutate(main_file_no_ = stringi::stri_replace_first_regex(.data$main_file, pattern="^_", replacement = ""), | ||
new_file_path = fs::path(.env$dir_path, .data$mesos_group, paste0(.data$main_file_no_, ".qmd")), | ||
) |> | ||
dplyr::rowwise() |> | ||
dplyr::mutate(contents = { | ||
yaml <- list(params = list(mesos_var = .env$mesos_var, | ||
mesos_group = .data$mesos_group)) | ||
if(.data$main_file_no_ %in% c("index", "0_report")) yaml$title <- paste0(.data$mesos_group) | ||
yaml <- yaml::as.yaml(x = yaml) | ||
paste0("---\n", yaml, "---\n", | ||
paste0("\n{{< include ../", .data$main_file, ".qmd >}}\n"), | ||
sep="\n") | ||
}) | ||
|
||
fs::dir_create(path = dirname(new_qmd_files$new_file_path)) | ||
|
||
for(i in seq_len(nrow(new_qmd_files))) { | ||
cat(new_qmd_files[i, "contents", drop=TRUE], | ||
file = new_qmd_files[i, "new_file_path", drop=TRUE]) | ||
} | ||
new_qmd_files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Remove Reports from Sidebars | ||
#' | ||
#' Finds HTML-files recursively in a path, and removes all entries in the sidebar | ||
#' to certain filenames, such as "0_report.pdf" | ||
#' | ||
#' | ||
#' @param path Folder path as string. | ||
#' @param filename_as_regex Character vector of regex filenames to look for (i.e., | ||
#' the dot separating file extension must be escaped as \\.). | ||
#' | ||
#' @return List of files processed. | ||
#' @export | ||
#' | ||
#' @examples remove_reports_from_sidebars(path = tempdir()) | ||
remove_reports_from_sidebars <- function(path = "_site", | ||
filename_as_regex = c("0_report\\.pdf", "0_report\\.docx")) { | ||
fs::dir_ls(path = path, | ||
all = FALSE, recurse = TRUE, type = "file", regexp = "\\.html") |> | ||
lapply(FUN = function(.x) { | ||
readLines(.x) |> | ||
paste0(collapse="\n") |> | ||
stringi::stri_replace_all_regex( | ||
pattern = paste0("<li class=\"sidebar-item\">\\s*<div class=\"sidebar-item-container\">\\s*<a href=\"[^\"]*", filename_as_regex, "\"[^>]*>\\s*<span class=\"menu-text\">[^<]*</span></a>\\s*</div>\\s*</li>"), | ||
replacement = "") |> | ||
stringi::stri_split_lines() |> | ||
writeLines(con = .x) | ||
.x | ||
}) |> | ||
unlist() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.