Skip to content

Commit

Permalink
fread clearer 'file doesn't exist' message. Closes #486.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Nov 12, 2014
1 parent d93fe09 commit 70df217
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
# In text mode on Windows-only, R doubles up \r to make \r\r\n line endings. mode="wb" avoids that. See ?connections:"CRLF"
input = tt
} else if (input == "" || length(grep('\\n|\\r', input)) > 0) {
# if text input
# text input
} else if (!file.exists(input)) {
if (length(grep(' ', input)) == 0) stop("File '",input,"' does not exist. Include one or more spaces to consider the input a system command.")
tt = tempfile()
on.exit(unlink(tt), add = TRUE)
if (.Platform$OS.type == "unix") {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* doubled quotes ("") inside quoted fields including if immediately followed by an embedded newline. Thanks to James Sams for reporting, [#489](https://github.com/Rdatatable/data.table/issues/489).
* quoted fields with embedded newlines in the lines used to detect types, [#810](https://github.com/Rdatatable/data.table/issues/810). Thanks to Vladimir Sitnikov for the scrambled data file which is now included in the test suite.
* when detecting types in the middle and end of the file, if the jump lands inside a quoted field with (possibly many) embedded newlines, this is now detected.
* if the file doesn't exist the error message is clearer ([#486](https://github.com/Rdatatable/data.table/issues/486))
* system commands are now checked to contain at least one space

6. `as.data.table.list` with list input having 0-length items, e.g. `x = list(a=integer(0), b=3:4)`. `as.data.table(x)` recycles item `a` with `NA`s to fit the length of the longer column `b` (length=2), as before now, but with an additional warning message that the item has been recycled with `NA`. Closes [#847](https://github.com/Rdatatable/data.table/issues/847). Thanks to @tvinodr for the report. This was a regression from 1.9.2.

Expand Down
5 changes: 1 addition & 4 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5566,10 +5566,7 @@ test(1451.6, ans1[c(3,3)], fans2(DT, c("V3", "V3"))) # using duplicate co
test(1451.7, shallow(DT, integer(0)), null.data.table()) # length-0 input work as intended as well.
test(1451.8, shallow(DT, character(0)), null.data.table()) # length-0 input work as intended as well.


# > fread("notexist.csv")
# sh: 1: nonfile.csv: not found
# Error in fread("nonfile.csv") : File is empty: /dev/shm/file54e46ccdb63
test(1452, fread("notexist.csv"), error="File 'notexist.csv' does not exist. Include one or more spaces to consider the input a system command.")


##########################
Expand Down

0 comments on commit 70df217

Please sign in to comment.