Skip to content

Commit ff7f5d9

Browse files
added tests
1 parent 9826966 commit ff7f5d9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

R/fread.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC")
7272
if (!is.null(cmd)) {
7373
tmpFile = tempfile(tmpdir=tmpdir)
7474
on.exit(unlink(tmpFile), add=TRUE)
75-
status = suppressWarnings((if (.Platform$OS.type == "unix") system else shell)(paste0('(', cmd, ') > ', tmpFile)))
75+
status = (if (.Platform$OS.type == "unix") system else shell)(paste0('(', cmd, ') > ', tmpFile))
7676
if (status != 0) {
7777
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)
7878
}
@@ -123,11 +123,11 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC")
123123
decompFile = tempfile(tmpdir=tmpdir)
124124
on.exit(unlink(decompFile), add=TRUE)
125125
tryCatch({
126-
R.utils::decompressFile(file, decompFile, ext=NULL, FUN=FUN, remove=FALSE)
126+
R.utils::decompressFile(file, decompFile, ext=NULL, FUN=FUN, remove=FALSE) # ext is not used by decompressFile when destname is supplied, but isn't optional
127127
}, error = function(e) {
128-
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)
128+
stopf("R.utils::decompressFile failed to decompress file '%s':\n %s\n. This can happen when the disk is full in the temporary directory ('%s'). See ?fread for the tmpdir argument.", file, conditionMessage(e), tmpdir)
129129
})
130-
file = decompFile
130+
file = decompFile # don't use 'tmpFile' symbol again, as tmpFile might be the http://domain.org/file.csv.gz download
131131
}
132132
file = enc2native(file) # CfreadR cannot handle UTF-8 if that is not the native encoding, see #3078.
133133

inst/tests/tests.Rraw

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21183,3 +21183,11 @@ test(2317.6, DT1[DF1, on='a', .(d = x.a + i.d)]$d, 5)
2118321183
test(2317.7, DT1[DF2, on='a', e := i.e]$e, 5)
2118421184
test(2317.8, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)
2118521185
test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)
21186+
21187+
# Improved fread error handling for cmd exe and decompression #5415
21188+
test(2318.1, fread(cmd="false"), error="External command failed") # external command execution error handling
21189+
if (test_R.utils) {
21190+
writeBin(c(0x1F, 0x8B, 0xFF, 0xFF), f<-tempfile(fileext=".csv.gz"))
21191+
test(2318.2, fread(f), error="Failed to decompress") # Compressed file decompression error handling
21192+
unlink(f)
21193+
}

0 commit comments

Comments
 (0)