Skip to content

printNestedList uses inconsistent indentation #43

@stolarczyk

Description

@stolarczyk

pepr/R/utils.R

Lines 273 to 308 in c334466

#' Print a nested list
#'
#' Prints a nested list in a way that looks nice
#'
#' Useful for displaying the config of a PEP
#'
#' @param lst list object to print
#' @param level the indentation level
#'
#' @examples
#' projectConfig = system.file("extdata",
#' "example_peps-master",
#' "example_basic",
#' "project_config.yaml",
#' package = "pepr")
#' p = Project(file = projectConfig)
#' .printNestedList(config(p),level=2)
#' @export
.printNestedList = function(lst, level = 0) {
if (!is.list(lst))
stop("The input is not a list, cannot be displayed.")
ns = names(lst)
for (i in seq_along(lst)) {
item = lst[[i]]
itemName = ns[i]
if (class(item) == "list") {
if(!is.null(itemName))
cat(rep(" ", level), paste0(itemName, ":"), fill = T)
.printNestedList(item, level + 2)
} else {
if (is.null(item))
item = "null"
cat(rep(" ", level), paste0(itemName, ":"), item, fill = T)
}
}
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions