Skip to content

Commit 327a052

Browse files
committed
Add whichExecutables()
1 parent a1aa129 commit 327a052

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.utils
22
Title: General Utility Functions Developed at KWB
3-
Version: 0.15.0
3+
Version: 0.15.0.9000
44
Authors@R:
55
c(person(given = "Hauke",
66
family = "Sonnenberg",
@@ -32,4 +32,4 @@ Suggests:
3232
VignetteBuilder:
3333
knitr
3434
Encoding: UTF-8
35-
RoxygenNote: 7.3.1
35+
RoxygenNote: 7.3.2

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Latest Changes
2+
3+
- add whichExecutables()
4+
15
# [kwb.utils 0.15.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.15.0) <small>2024-03-28</small>
26

37
- add loadFunctions() with private function

R/whichExecutables.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#' Find Executable Files in Directories given in PATH Environment Variable
2+
#'
3+
#' @param pattern if not NULL, the result list is filtered for file names
4+
#' matching the pattern
5+
#' @param full.names if TRUE, the list items are the full paths, otherwise the
6+
#' file names only
7+
#' @return list with one entry per directory from the PATH variable
8+
whichExecutables <- function(pattern = NULL, full.names = FALSE)
9+
{
10+
paths <- kwb.utils::rStylePath(strsplit(Sys.getenv("PATH"), ";")[[1]])
11+
extensions <- strsplit(Sys.getenv("PATHEXT"), ";")[[1L]]
12+
ext_patterns <- gsub("\\.", "\\\\.", extensions)
13+
ext_pattern <- sprintf("(%s)$", paste(ext_patterns, collapse = "|"))
14+
exe_files <- lapply(
15+
stats::setNames(nm = paths),
16+
FUN = dir,
17+
pattern = ext_pattern,
18+
ignore.case = TRUE
19+
)
20+
if (!is.null(pattern)) {
21+
exe_files <- lapply(exe_files, grep, pattern = pattern, value = TRUE)
22+
exe_files <- exe_files[lengths(exe_files) > 0L]
23+
}
24+
if (full.names) {
25+
exe_files <- lapply(stats::setNames(nm = names(exe_files)), function(path) {
26+
file.path(path, exe_files[[path]])
27+
})
28+
}
29+
exe_files
30+
}

man/whichExecutables.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)