Skip to content

[BUG] is_*() return FALSE for nonexistent paths, but documentation says they should return NA #516

Description

@Yousa-Mirage

fs::is_*() appears to behave inconsistently with its documentation, including is_file(), is_dir(), is_link() and is_file_empty(). My fs is the newest 2.1.0.

The documentation for is_file() says:

A named logical vector, where the names give the paths. If the given object does not exist, `NA` is returned.

However, is_file() (and other funcs) returns FALSE for nonexistent paths instead of NA:

print(packageVersion("fs"))
#> [1] '2.1.0'

fs::is_file("unexisting_file.txt")
#> unexisting_file.txt 
#>               FALSE
fs::is_dir("unexisting_dir/")
#> unexisting_dir/ 
#>           FALSE
fs::is_link("unexisting_link")
#> unexisting_link 
#>           FALSE
fs::is_file_empty("unexisting_file.txt")
#> unexisting_file.txt 
#>               FALSE

There is the current R implementation code. Since !is.na(res$type) is used, nonexistent paths are converted to FALSE rather than propagating NA.

print(fs::is_file)
#> function (path, follow = TRUE) 
#> {
#>     res <- file_info(path, follow = follow)
#>     setNames(!is.na(res$type) & res$type == "file", path)
#> }
#> <bytecode: 0x59ab3f485828>
#> <environment: namespace:fs>

This creates a mismatch between documentation and implementation. I wonder which behavior is intended:

  • If FALSE is intended for nonexistent paths, the documentation should be updated.
  • If NA is intended for nonexistent paths, the implementation should be changed.

I'm glad to create a PR to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions