Skip to content

Commit

Permalink
GiottoUtils v0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Jul 26, 2024
2 parents c5b8000 + 4ff88f3 commit a4532dc
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GiottoUtils
Title: Giotto Suite Utilities
Version: 0.1.9
Version: 0.1.10
Authors@R: c(
person("Ruben", "Dries", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export(deprecate_warn)
export(deprecated)
export(depth)
export(determine_cores)
export(dir_manifest)
export(dt_dcast_string)
export(dt_remove_na)
export(dt_set_row_order)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@


# GiottoUtils 0.1.10

## New
- `dir_manifest()` for creating a named `list` of files within a directory. Mostly wraps `list.files()`


# GiottoUtils 0.1.9 (2024/07/12)

## New
Expand Down
54 changes: 54 additions & 0 deletions R/file_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,60 @@ file_extension <- function(file) {
}


#' @title Generate file manifest list from a directory
#' @name dir_manifest
#' @description Create a `list` of full filepaths (character) that are named
#' by with the respective `[basename()]`. Allows easy `$` exploration and
#' indexing of items.\cr
#' All params are directly passed to `[list.files()]` except
#' for `full.names`. `[list.files()]` also normally returns both actual files
#' and directories when `recursive = FALSE`, but this function specifically
#' tests if items are existing files and not directories with
#' `utils::file_test(op = -f)` and fully obeys that flag in all cases.
#' @param path a character vector of full path names; the default corresponds
#' to the working directory, `[getwd()]`. Tilde expansion (see [path.expand])
#' and [`normalizePath()`] are performed. Missing values will be ignored.
#' Elements with a marked encoding will be converted to the native encoding
#' (and if that fails, considered non-existent).
#' @param pattern an optional regular expression. Only file names which match
#' the regular expression will be returned.
#' @param all.files a logical value. If `FALSE`, only the names of visible
#' files are returned (following Unix-style visibility, that is files whose
#' name does not start with a dot). If `TRUE`, all file names will be returned.
#' @param recursive logical. Should the listing recurse into directories?
#' @param ignore.case logical. Should pattern-matching be case-insensitive?
#' @param include.dirs logical. Should subdirectory names be included in
#' recursive listings?
#' @param no.. logical. Should both `"."` and `".."` be excluded also from
#' non-recursive listings?
#' @param as.list logical. Should output be a list or a named character vector
#' @examples
#' dir_manifest()
#' @returns full and normalized filepaths named by the file basename as either
#' a list (default) or if `as.list = FALSE`, a character vector.
#' @export
dir_manifest <- function(
path = ".", pattern = NULL, all.files = FALSE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE,
as.list = TRUE
) {
a <- get_args_list(keep = c(
"path", "pattern", "all.files", "recursive", "ignore.case",
"include.dirs", "no.."
))
a$full.names = TRUE
fullpaths <- do.call("list.files", args = a)
fullpaths <- normalizePath(fullpaths)
if (include.dirs == FALSE) {
is_file <- utils::file_test(op = "-f", x = fullpaths)
fullpaths <- fullpaths[is_file]
}
names(fullpaths) <- basename(fullpaths)
if (as.list) fullpaths <- as.list(fullpaths)
return(fullpaths)
}


#' @title Fread specific rows based on column matches
#' @name fread_colmatch
#' @param file path to file to load
Expand Down
60 changes: 60 additions & 0 deletions man/dir_manifest.Rd

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

0 comments on commit a4532dc

Please sign in to comment.