ITADN
r-lib/fs/Issues

ext argument of fs::path is not vectorized

#496OpenDarwinAwardWinner 创建于 2025-07-20
I was surprised to find that the `ext` argument of `fs::path` is not vectorized, as demonstrated in the below example: ``` r library(fs) library(assertthat) bad_paths <- path("foo", letters[1:3], ext = c("txt1", "txt2", "txt3")) correct_paths <- paste0("foo/", letters[1:3], ".txt", 1:3) assert_that(all(bad_paths == correct_paths)) #> Error: Elements 2, 3 of bad_paths == correct_paths are not true ``` <sup>Created on 2025-07-20 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup> The function silently takes the first element of `ext` and uses it for all elements, which leads to unexpected behavior. Either the argument should be modified to accept a vector rather than a scalar, or if not being vectorized is intentional, then it should at least throw an error when passed a vector with length != 1, and this fact should be documented in the help text.
0 条评论