Skip to content

[discussion]: Add filter parameter to list_sas_files()? #238

@signekb

Description

@signekb

Thinking of the use case of using list_sas_files() in convert_register(), this currently would require a folder with only files from one register. Since files from multiple registers are usually in the same folder, e.g., Grunddata/, it might make sense to add some kind of filter paramenter to list_sas_files(), something like:

list_sas_files <- function(path, filter = NULL) { # added filter here
  # Check input.
  checkmate::assert_directory(path)
  checkmate::assert_string(path)
  checkmate::assert_string(filter, null.ok = TRUE) # added

  # List all SAS files in the directory and its subdirectories.
  # (?i) makes the regex case-insensitive.
  filter_pattern <- if (is.null(filter)) "" else filter # added
  sas_files <- fs::dir_ls(
    path,
    regexp = glue::glue("(?i){filter_pattern}[^/]*\\.sas7bdat$"), # glue and `{filter_pattern}[^/]*` added
    recurse = TRUE
  ) |>
    sort()

  if (length(sas_files) == 0) {
    cli::cli_abort("No SAS files found in {.path {path}}.")
  }

  sas_files
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions