Skip to content

ext argument of fs::path is not vectorized #496

@DarwinAwardWinner

Description

@DarwinAwardWinner

I was surprised to find that the ext argument of fs::path is not vectorized, as demonstrated in the below example:

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

Created on 2025-07-20 with reprex v2.1.1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions