fs icon indicating copy to clipboard operation
fs copied to clipboard

Inconsistent treatment of non-character path inputs

Open raymondben opened this issue 3 years ago • 2 comments

Some functions (e.g. path_tidy) call enc2utf8(as.character(path)), but others do not coerce to character first (e.g. path_expand just calls enc2utf8(path)). This leads to inconsistent treatment of non-character path inputs between different functions:

> fs::path_tidy(NA)
NA
> fs::path_expand(NA)
Error in enc2utf8(path) : argument is not a character vector

and also logically-inconsistent behaviour in some cases:

> fs::file_exists(NA_character_)
 <NA> 
FALSE 

but

> fs::file_exists(NA)
Error in enc2utf8(path) : argument is not a character vector

If this isn't intentional, would it be unreasonable to apply an as.character coercion to all calls to enc2utf8 to avoid these errors?

raymondben avatar Feb 22 '22 23:02 raymondben

I think it would make sense to try to convert to characters, would you like to submit a PR?

gaborcsardi avatar Feb 23 '22 08:02 gaborcsardi

OK, will do.

raymondben avatar Feb 23 '22 09:02 raymondben