Skip to content

Commit

Permalink
removing check_list arg
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeya committed Sep 21, 2023
1 parent 35933a9 commit 94a40af
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 67 deletions.
36 changes: 1 addition & 35 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,40 +231,6 @@ padding_lst <- function(ft, indents) {
}, seq_len(length(indents)), ft)
}

#' Split a text block into smaller blocks with a specified number of lines.
#'
#' This function takes a block of text and divides it into smaller blocks, each containing
#' a specified number of lines.
#'
#' @param block_text A character vector containing the input block of text.
#' @param n The number of lines per block.
#'
#' @return A list of character vectors, where each element is a smaller block of text
#' containing 'n' lines. If the input block of text has fewer lines than 'n', the
#' entire block is returned as a single element list.
#'
#' @keywords internal
split_text_into_blocks <- function(block_text, n) {
lines <- strsplit(block_text, "\n")[[1]]
num_lines <- length(lines)

if (num_lines <= n) {
return(list(block_text))
}

num_blocks <- ceiling(num_lines / n)
blocks <- vector("list", length = num_blocks)

for (i in 1:num_blocks) {
start <- (i - 1) * n + 1
end <- min(i * n, num_lines)
block <- paste(lines[start:end], collapse = "\n")
blocks[[i]] <- block
}

return(blocks)
}

#' Split a text block into smaller blocks with a specified number of lines.
#'
#' Divide text block into smaller blocks.
Expand All @@ -290,7 +256,7 @@ split_text_block <- function(x, n) {
}

nblocks <- ceiling(length(lines) / n)
ind <- rep(1:nblocks, each = n)[1:length(lines)]
ind <- rep(1:nblocks, each = n)[seq_along(lines)]
unname(tapply(lines, ind, paste, collapse = "\n"))
}

Expand Down
14 changes: 6 additions & 8 deletions R/yaml_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,17 @@ print.rmd_yaml_header <- function(x, ...) {
#' it returns the extracted field.
#'
#' @keywords internal
reverse_yaml_field <- function(yaml_text, field_name, check_list = TRUE) {
reverse_yaml_field <- function(yaml_text, field_name) {
checkmate::assert_multi_class(yaml_text, c("rmd_yaml_header", "character"))
checkmate::assert_string(field_name)
checkmate::assert_logical(check_list)
# Parse the YAML text
yaml_obj <- yaml::yaml.load(yaml_text)

# Extract the specified field
yaml_obj <- yaml::yaml.load(yaml_text)
result <- NULL
if (field_name %in% names(yaml_obj)) {
result <- yaml_obj[[field_name]]
if (check_list && is.list(result)) {
return(names(result))
if (is.list(result)) {
result <- names(result)
}
return(result)
}
result
}
2 changes: 1 addition & 1 deletion man/reverse_yaml_field.Rd

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

23 changes: 0 additions & 23 deletions man/split_text_into_blocks.Rd

This file was deleted.

0 comments on commit 94a40af

Please sign in to comment.