Skip to content

Commit a08a1f0

Browse files
authored
Lean more into vroom_tempfile() (#598)
* We should use vroom_tempfile() here too * Make vroom_tempfile() a bit more featureful * vroom_tempfile() feels like a path utility to me * Use `pattern` Might be helpful if we ever find out we're not cleaning up when we mean to
1 parent 9a2908b commit a08a1f0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

R/path.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
vroom_tempfile <- function(fileext = "", pattern = "vroom-") {
2+
dir <- Sys.getenv("VROOM_TEMP_PATH")
3+
if (!nzchar(dir)) {
4+
dir <- tempdir()
5+
}
6+
tempfile(pattern = pattern, tmpdir = dir, fileext = fileext)
7+
}
8+
19
is_ascii_compatible <- function(encoding) {
210
identical(
311
iconv(list(charToRaw("\n")), from = "ASCII", to = encoding, toRaw = TRUE)[[
@@ -24,7 +32,7 @@ reencode_file <- function(file, encoding, call = caller_env()) {
2432
} else {
2533
in_con <- file(file[[1]])
2634
}
27-
out_file <- tempfile()
35+
out_file <- vroom_tempfile(pattern = "vroom-reencode-file-")
2836
out_con <- file(out_file)
2937
convert_connection(in_con, out_con, encoding, "UTF-8")
3038
withr::defer(unlink(out_file), envir = parent.frame())
@@ -349,7 +357,7 @@ zipfile <- function(path, open = "r") {
349357
utils::globalVariables("con")
350358

351359
chr_to_file <- function(x, envir = parent.frame()) {
352-
out <- tempfile()
360+
out <- vroom_tempfile(pattern = "vroom-chr-to-file-")
353361
con <- file(out, "wb")
354362
writeLines(sub("\n$", "", x), con, useBytes = TRUE)
355363
close(con)

R/vroom.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,6 @@ vroom_threads <- function() {
464464
res
465465
}
466466

467-
vroom_tempfile <- function() {
468-
dir <- Sys.getenv("VROOM_TEMP_PATH")
469-
if (!nzchar(dir)) {
470-
dir <- tempdir()
471-
}
472-
tempfile(pattern = "vroom-", tmpdir = dir)
473-
}
474-
475467
#' Show which column types are using Altrep
476468
#'
477469
#' `vroom_altrep()` can be used directly as input to the `altrep`

0 commit comments

Comments
 (0)