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.
fs::is_*()appears to behave inconsistently with its documentation, includingis_file(),is_dir(),is_link()andis_file_empty(). Myfsis the newest2.1.0.The documentation for
is_file()says:However,
is_file()(and other funcs) returnsFALSEfor nonexistent paths instead ofNA:There is the current R implementation code. Since
!is.na(res$type)is used, nonexistent paths are converted toFALSErather than propagatingNA.This creates a mismatch between documentation and implementation. I wonder which behavior is intended:
FALSEis intended for nonexistent paths, the documentation should be updated.NAis intended for nonexistent paths, the implementation should be changed.I'm glad to create a PR to fix this.