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

Fix recursive gc error that could occur with POSIXct columns #390

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vroom (development version)

* Fix recursive gc error that could occur during `vroom_write()` when `output_column()` generates an ALTREP vector (#389).

# vroom 1.5.7

* Jenny Bryan is now the official maintainer.
Expand Down
23 changes: 14 additions & 9 deletions R/vroom_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ vroom_write <- function(x, file, delim = '\t', eol = "\n", na = "NA", col_names
)
}

input <- x

quote <- match.arg(quote)
escape <- match.arg(escape)
Expand All @@ -60,28 +61,32 @@ vroom_write <- function(x, file, delim = '\t', eol = "\n", na = "NA", col_names
if (!inherits(file, "connection")) {
file.create(file)
}
return(invisible(x))
return(invisible(input))
}

# We need to convert any altrep vectors to normal vectors otherwise we can't fill the
# write buffers from other threads.
xx <- vroom_convert(x)
xx[] <- lapply(xx, output_column)

# This seems to work ok in practice
buf_lines <- max(as.integer(Sys.getenv("VROOM_WRITE_BUFFER_LINES", nrow(x) / 100 / num_threads)), 1)

# Run `output_column()` before `vroom_convert()` to ensure that any ALTREP
# vectors created by `output_column()` will be fully materialized (#389)
x[] <- lapply(x, output_column)

# We need to convert any altrep vectors to normal vectors otherwise we can't fill the
# write buffers from other threads. This should be the last manipulation done
# to `x` before writing to ensure that no new altrep vectors are created.
x <- vroom_convert(x)

if (inherits(file, "connection")) {
vroom_write_connection_(xx, file, delim, eol, na_str = na, col_names = col_names,
vroom_write_connection_(x, file, delim, eol, na_str = na, col_names = col_names,
options = opts, num_threads = num_threads, progress = progress, buf_lines = buf_lines,
is_stdout = file == stdout(), append = append)
} else {
vroom_write_(xx, file, delim, eol, na_str = na, col_names = col_names,
vroom_write_(x, file, delim, eol, na_str = na, col_names = col_names,
append = append, options = opts,
num_threads = num_threads, progress = progress, buf_lines = buf_lines)
}

invisible(x)
invisible(input)
}


Expand Down