Skip to content

Commit

Permalink
sep="." now works, closes #502
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Nov 12, 2014
1 parent 70df217 commit 0afc547
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
}
}
if (Sys.localeconv()["decimal_point"] != dec)
stop(if(verbose)'' else 'Run again with verbose=TRUE to inspect... ','Unable to change to a locale which provides the desired dec. You will need to add a valid locale name to getOption("datatable.fread.dec.locale"). See ?fread and ?Sys.setlocale.')
(if (sep==".") warning else stop)(if(verbose)'' else 'Run again with verbose=TRUE to inspect... ','Unable to change to a locale which provides the desired dec. You will need to add a valid locale name to getOption("datatable.fread.dec.locale"). See the long paragraph in ?fread.')
# the warning/stop switch is for #502
if (verbose) cat("This R session's locale is now '",tt,"' which provides the desired decimal point for reading numerics in the file - success! The locale will be restored to what it was ('",oldlocale,") even if the function fails for other reasons.\n")
}
if (!is.character(input) || length(input)!=1) {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* 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
* sep="." now works when dec!=".", [#502](https://github.com/Rdatatable/data.table/issues/502). Thanks to Ananda Mahto for reporting.

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
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5568,6 +5568,14 @@ test(1451.8, shallow(DT, character(0)), null.data.table()) # length-0 input wor

test(1452, fread("notexist.csv"), error="File 'notexist.csv' does not exist. Include one or more spaces to consider the input a system command.")

# sep=".", issue #502
input = paste( paste("192.168.1.", 1:10, sep=""), collapse="\n")
test(1453.1, fread(input, sep="."), error="The two arguments to fread 'dec' and 'sep' are equal")
test(1453.2, fread(input, sep=".", dec="*"), ans<-data.table(V1=192L,V2=168L,V3=1L,V4=1:10), warning="Unable to change to a locale which provides the desired dec")
test(1453.3, fread(paste(paste("192. 168. 1. ", 1:10, sep = ""), collapse="\n"), sep=".", dec="*"), ans, warning="Unable")
test(1453.4, fread(paste(paste("Hz.BB.GHG.", 1:10, sep = ""), collapse="\n"), sep=".", dec="*"), data.table(V1="Hz",V2="BB",V3="GHG",V4=1:10), warning="Unable")



##########################

Expand Down

0 comments on commit 0afc547

Please sign in to comment.