File: path.R

package info (click to toggle)
r-cran-rprojroot 2.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: sh: 12; makefile: 7
file content (26 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Modeled after fs::path()
path <- function(...) {
  dots <- list(...)

  if (!is.null(names(dots)) && any(names(dots) != "")) {
    warning("Arguments must be unnamed", call. = FALSE)
  }

  # Different recycling rules for zero-length vectors
  lengths <- lengths(dots)
  if (any(lengths == 0) && all(lengths %in% 0:1)) {
    return(character())
  }

  # Side effect: check recycling rules
  component_df <- as.data.frame(dots, stringsAsFactors = FALSE)

  missing <- apply(is.na(component_df), 1, any)

  components <- lapply(component_df, function(x) enc2utf8(as.character(x)))

  out <- do.call(file.path, components)
  out[missing] <- NA_character_
  Encoding(out) <- "UTF-8"
  out
}