Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All functions in question appropriately fail or warn when file is missing #455

Closed
wants to merge 6 commits into from
Closed

All functions in question appropriately fail or warn when file is missing #455

wants to merge 6 commits into from

Conversation

IndrajeetPatil
Copy link
Contributor

Reprex

Closes #334

  • file_info()
library(fs)

try(file_info("this-file-does-not-exist", fail = TRUE))
#> Error : [ENOENT] Failed to stat 'this-file-does-not-exist': no such file or directory

file_info("this-file-does-not-exist", fail = FALSE)
#> Warning: [ENOENT] Failed to stat 'this-file-does-not-exist': no such file or
#> directory
#> # A tibble: 1 × 18
#>   path         type   size permissions modification_time user  group device_id
#>   <fs::path>   <fct> <fs:> <fs::perms> <dttm>            <chr> <chr>     <dbl>
#> 1 …s-not-exist <NA>     NA ---------   NA                <NA>  <NA>         NA
#> # ℹ 10 more variables: hard_links <dbl>, special_device_id <dbl>, inode <dbl>,
#> #   block_size <dbl>, blocks <dbl>, flags <int>, generation <dbl>,
#> #   access_time <dttm>, change_time <dttm>, birth_time <dttm>

Created on 2024-05-12 with reprex v2.1.0

  • file_size()
library(fs)

try(file_size("this-file-does-not-exist", fail = TRUE))
#> Error : [ENOENT] Failed to stat 'this-file-does-not-exist': no such file or directory

file_size("this-file-does-not-exist", fail = FALSE)
#> Warning: [ENOENT] Failed to stat 'this-file-does-not-exist': no such file or
#> directory
#> NA

Created on 2024-05-12 with reprex v2.1.0

Concerns

@gaborcsardi Although this produces the desired behaviour, I think this is a massive change.

It is probably going to lead to breakages for packages that have been relying on the incorrect behaviour thus far: although the default for {fs} functions in question has always been fail = TRUE, these functions never failed, and they are now going to start to fail. I can already tell that {devtools} is going to break with this change.

To avoid this, should all defaults actually be changed from fail = TRUE to fail = FALSE to keep this change backward-compatible?

expect_s3_class(x, c("tbl", "tbl_df", "data.frame"))
expect_length(x, 18)
expect_equal(nrow(x), 1)
expect_equal(as.character(x$path), "missing")
expect_equal(sum(is.na(x)), 17)
})
it("produces error if a file does not exist and fail is set to TRUE", {
expect_error(file_info("missing", fail = TRUE))
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key test for the new behaviour.

@@ -42,7 +42,7 @@
#' file_delete("mtcars.csv")
#' \dontshow{setwd(.old_wd)}
#' @export
file_info <- function(path, fail = TRUE, follow = FALSE) {
file_info <- function(path, fail = FALSE, follow = FALSE) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as fail = TRUE breaks {devtools}, and for the sake of doing local development in RStudio, I changed this default, but this is something that needs to be discussed further.

@IndrajeetPatil IndrajeetPatil changed the title All respective function appropriately fail or warn when file is missing All functions in question appropriately fail or warn when file is missing May 12, 2024
@IndrajeetPatil IndrajeetPatil deleted the file-info-fail-bug branch June 3, 2024 13:21
@IndrajeetPatil
Copy link
Contributor Author

This is too big of a change to be making at this point, at least for a contributor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

file_info does not fail or warn when file is missing
1 participant