Skip to content

Commit

Permalink
Add text argument to write_rds
Browse files Browse the repository at this point in the history
This analogous to the `ascii` argument to `saveRDS`.
We used `text` rather than `ascii` as it avoids users needing to know
what ASCII character encoding is.

Fixes #1270
  • Loading branch information
jimhester committed Aug 16, 2021
1 parent 939ee6b commit 866deca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# readr 2.0.1

* `write_rds()` gains a `text=` argument, to control using a text based object representation, like the `ascii=` argument in `saveRDS()` (#1270)

* `options(readr.show_col_types = FALSE)` now works as intended (#1250)

* `read_delim_chunked()` now again correctly respects the `chunk_size` parameter (#1248)
Expand Down
5 changes: 3 additions & 2 deletions R/rds.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ read_rds <- function(file, refhook = NULL) {
#' the space-time trade-off of different compression methods with
#' `compression`. See [connections()] for more details.
#' @param path \Sexpr[results=rd, stage=render]{lifecycle::badge("deprecated")}, use the `file` argument instead.
#' @param text If `TRUE` a text representation is used, otherwise a binary representation is used.
#' @return `write_rds()` returns `x`, invisibly.
#' @rdname read_rds
#' @export
write_rds <- function(x, file, compress = c("none", "gz", "bz2", "xz"),
version = 2, refhook = NULL, path = deprecated(), ...) {
version = 2, refhook = NULL, text = FALSE, path = deprecated(), ...) {
if (is_present(path)) {
deprecate_warn("1.4.0", "write_rds(path = )", "write_rds(file = )")
file <- path
Expand All @@ -49,7 +50,7 @@ write_rds <- function(x, file, compress = c("none", "gz", "bz2", "xz"),
xz = xzfile(file, ...)
)
on.exit(close(con), add = TRUE)
saveRDS(x, con, version = version, refhook = refhook)
saveRDS(x, con, version = version, refhook = refhook, ascii = text)

invisible(x)
}
3 changes: 3 additions & 0 deletions man/read_rds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 866deca

Please sign in to comment.