r-lib / fs
Showing 1 of 4 files from the diff.
Newly tracked file
R/path_select.R created.
Other files ignored by Codecov

@@ -0,0 +1,46 @@
Loading
1 +
#' Select path elements by their position/index.
2 +
#'
3 +
#' `path_select()` allows to select individual elements from an `fs_path`
4 +
#'  object via their index.
5 +
#'
6 +
#' @param path A path of class `fs_path`.
7 +
#' @param index An integer vector of path positions. (A negative index will work
8 +
#'  according to R's usual subsetting rules.)
9 +
#' @param from A character of either `"start"` or `"end"` to choose if indexing
10 +
#'  should start from the first or last element of the `path`.
11 +
#'
12 +
#' @return An `fs_path` object, which is a character vector that also has class
13 +
#'  `fs_path`.
14 +
#'
15 +
#' @export
16 +
#' @examples
17 +
#' path <- fs::path("some", "simple", "path", "to", "a", "file.txt")
18 +
#'
19 +
#' path_select(path, 1:3)
20 +
#'
21 +
#' path_select(path, 1:3, "end")
22 +
#'
23 +
#' path_select(path, -1, "end")
24 +
#'
25 +
#' path_select(path, 6)
26 +
path_select <- function(path, index, from = c("start", "end")) {
27 +
28 +
  from <- match.arg(from)
29 +
30 +
  if (length(path) > 1) {stop("Please supply only one path.")}
31 +
32 +
  path <- unlist(fs::path_split(path))
33 +
  path_seq <- seq_along(path)
34 +
35 +
  if (max(abs(index)) > length(path)) {stop("`seq` contains a higher number than the path has elements.")}
36 +
37 +
  if (from == "start") {path <- path[index]}
38 +
  if (from == "end") {
39 +
    path_seq <- rev(rev(path_seq)[index])
40 +
    path <- path[path_seq]
41 +
  }
42 +
43 +
  path <- fs::path_join(path)
44 +
45 +
  return(path)
46 +
}
Files Coverage
R 89.54%
src 77.02%
Project Totals (34 files) 82.29%
Notifications are pending CI completion. Waiting for GitHub's status webhook to queue notifications. Push notifications now.
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading