Skip to content

Commit

Permalink
Force argument before writing files
Browse files Browse the repository at this point in the history
This ensures the file is read before trying to write it, e.g. if you
call `write_file(read_file("foo"), "foo")` or similar with the lazy
pipe.

Fixes #1158
  • Loading branch information
jimhester committed Apr 26, 2021
1 parent b7b287f commit 3867004
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
These functions rely on the first edition parsing code and would be challenging to update to the new parser.
When the first edition parsing code is eventually removed from readr they will be split off into a new package.

* `write_file()` now forces its argument before opening the output file (#1158)

## Additional features and fixes

* `read_*()` functions gain a `show_col_types` argument, if set to `FALSE` this turns off showing the column types unconditionally.
Expand Down
2 changes: 2 additions & 0 deletions R/file.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ write_file <- function(x, file, append = FALSE, path = deprecated()) {
file <- path
}

force(x)

file <- standardise_path(file, input = FALSE)
if (!isOpen(file)) {
on.exit(close(file), add = TRUE)
Expand Down

0 comments on commit 3867004

Please sign in to comment.