Skip to content
19 changes: 14 additions & 5 deletions R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@
}
}
if (!is.null(cmd)) {
(if (.Platform$OS.type == "unix") system else shell)(paste0('(', cmd, ') > ', tmpFile<-tempfile(tmpdir=tmpdir)))
tmpFile = tempfile(tmpdir=tmpdir)
on.exit(unlink(tmpFile), add=TRUE)

Check warning on line 74 in R/fread.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/fread.R,line=74,col=39,[trailing_whitespace_linter] Remove trailing whitespace.
Comment thread
MichaelChirico marked this conversation as resolved.
Outdated
status = suppressWarnings((if (.Platform$OS.type == "unix") system else shell)(paste0('(', cmd, ') > ', tmpFile)))
Comment thread
MichaelChirico marked this conversation as resolved.
Outdated
if (status != 0) {
stopf("External command failed with exit code %d. This can happen when the disk is full in the temporary directory ('%s'). See ?fread for the tmpdir argument.", status, tmpdir)

Check warning on line 77 in R/fread.R

View check run for this annotation

Codecov / codecov/patch

R/fread.R#L77

Added line #L77 was not covered by tests
Comment thread
MichaelChirico marked this conversation as resolved.
}
file = tmpFile
on.exit(unlink(tmpFile), add=TRUE)
}
if (!is.null(file)) {
if (!is.character(file) || length(file)!=1L)
Expand Down Expand Up @@ -116,9 +120,14 @@
if (!requireNamespace("R.utils", quietly = TRUE))
stopf("To read %s files directly, fread() requires 'R.utils' package which cannot be found. Please install 'R.utils' using 'install.packages('R.utils')'.", if (w<=2L || gzsig) "gz" else "bz2") # nocov
FUN = if (w<=2L || gzsig) gzfile else bzfile
R.utils::decompressFile(file, decompFile<-tempfile(tmpdir=tmpdir), ext=NULL, FUN=FUN, remove=FALSE) # ext is not used by decompressFile when destname is supplied, but isn't optional
file = decompFile # don't use 'tmpFile' symbol again, as tmpFile might be the http://domain.org/file.csv.gz download
Comment thread
MichaelChirico marked this conversation as resolved.
on.exit(unlink(decompFile), add=TRUE)
decompFile = tempfile(tmpdir=tmpdir)
on.exit(unlink(decompFile), add=TRUE)

Check warning on line 124 in R/fread.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/fread.R,line=124,col=44,[trailing_whitespace_linter] Remove trailing whitespace.
Comment thread
MichaelChirico marked this conversation as resolved.
Outdated
tryCatch({
R.utils::decompressFile(file, decompFile, ext=NULL, FUN=FUN, remove=FALSE)
}, error = function(e) {
stopf("Failed to decompress file '%s'. This can happen when the disk is full in the temporary directory ('%s'). See ?fread for the tmpdir argument.", file, tmpdir)

Check warning on line 128 in R/fread.R

View check run for this annotation

Codecov / codecov/patch

R/fread.R#L128

Added line #L128 was not covered by tests
Comment thread
MichaelChirico marked this conversation as resolved.
Outdated
})
file = decompFile
}
file = enc2native(file) # CfreadR cannot handle UTF-8 if that is not the native encoding, see #3078.

Expand Down
Loading