Skip to content

Commit 1ca9cf6

Browse files
Support for fread() of file:// URI with spaces (#7551)
* skip file:// when checking if the file exists * regression test * storage type match on round trip * NEWS entry * test number
1 parent 9f6db00 commit 1ca9cf6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
2. `set()` now automatically pre-allocates new column slots if needed, similar to what `:=` already does, [#1831](https://github.com/Rdatatable/data.table/issues/1831) [#4100](https://github.com/Rdatatable/data.table/issues/4100). Thanks to @zachokeeffe and @tyner for the report and @ben-schwen for the fix.
3232

33+
3. `fread("file://...")` works for file URIs with spaces, [#7550](https://github.com/Rdatatable/data.table/issues/7550). Thanks @aitap for the report and @MichaelChirico for the PR.
34+
3335
## data.table [v1.18.0](https://github.com/Rdatatable/data.table/milestone/37?closed=1) 23 December 2025
3436

3537
### BREAKING CHANGE

R/fread.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC")
6363
# input is data itself containing at least one \n or \r
6464
} else if (startsWith(input, " ")) {
6565
stopf("input= contains no \\n or \\r, but starts with a space. Please remove the leading space, or use text=, file= or cmd=")
66-
} else if (length(grep(' ', input, fixed=TRUE)) && !file.exists(input)) { # file name or path containing spaces is not a command
66+
} else if (length(grep(' ', input, fixed=TRUE)) && !file.exists(gsub("^file://", "", input))) { # file name or path containing spaces is not a command. file.exists() doesn't understand file:// (#7550)
6767
cmd = input
6868
if (input_has_vars && getOption("datatable.fread.input.cmd.message", TRUE)) {
6969
messagef("Taking input= as a system command because it contains a space ('%s'). If it's a filename please remove the space, or use file= explicitly. A variable is being passed to input= and when this is taken as a system command there is a security concern if you are creating an app, the app could have a malicious user, and the app is not running in a secure environment; e.g. the app is running as root. Please read item 5 in the NEWS file for v1.11.6 for more information and for the option to suppress this message.", cmd)

inst/tests/tests.Rraw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21968,3 +21968,13 @@ test(2356.2, options=c(datatable.alloccol=1L), set(DT, j="c", value=3), data.tab
2196821968
# ensure := and set are consistent if they need to overallocate
2196921969
DT = data.table(); DT2 = data.table()
2197021970
test(2356.3, options=c(datatable.alloccol=1L), {for (i in seq(10L)) set(DT, j = sprintf("V%d",i), value = i); DT}, {for (i in seq(10)) DT2[, sprintf("V%d",i) := i]; DT2})
21971+
21972+
# fread works on file:// URIs with spaces, #7550
21973+
local({
21974+
f = tempfile("with spaces"); on.exit(unlink(f))
21975+
DT = data.table(a = 1L, b = 2L)
21976+
fwrite(DT, f)
21977+
21978+
test(2357.1, fread(f), DT)
21979+
test(2357.2, fread(paste0("file://", f)), DT)
21980+
})

0 commit comments

Comments
 (0)