diff --git a/NEWS.md b/NEWS.md index ef2148e099..23e8d5c873 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,8 @@ 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. +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. + ## data.table [v1.18.0](https://github.com/Rdatatable/data.table/milestone/37?closed=1) 23 December 2025 ### BREAKING CHANGE diff --git a/R/fread.R b/R/fread.R index 16a72ed24d..87a544ad74 100644 --- a/R/fread.R +++ b/R/fread.R @@ -63,7 +63,7 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC") # input is data itself containing at least one \n or \r } else if (startsWith(input, " ")) { stopf("input= contains no \\n or \\r, but starts with a space. Please remove the leading space, or use text=, file= or cmd=") - } else if (length(grep(' ', input, fixed=TRUE)) && !file.exists(input)) { # file name or path containing spaces is not a command + } 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) cmd = input if (input_has_vars && getOption("datatable.fread.input.cmd.message", TRUE)) { 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) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 8cad916e3b..fcf78e9f36 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21968,3 +21968,13 @@ test(2356.2, options=c(datatable.alloccol=1L), set(DT, j="c", value=3), data.tab # ensure := and set are consistent if they need to overallocate DT = data.table(); DT2 = data.table() 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}) + +# fread works on file:// URIs with spaces, #7550 +local({ + f = tempfile("with spaces"); on.exit(unlink(f)) + DT = data.table(a = 1L, b = 2L) + fwrite(DT, f) + + test(2357.1, fread(f), DT) + test(2357.2, fread(paste0("file://", f)), DT) +})