Skip to content

Commit b25d48c

Browse files
committed
added rows condition
1 parent 1b6a501 commit b25d48c

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
106106
17. `t1 - t2`, where one is an `IDate` and the other is a `Date`, are now consistent with the case where both are `IDate` or both are `Date`, [#4749](https://github.com/Rdatatable/data.table/issues/4749). Thanks @George9000 for the report and @MichaelChirico for the fix.
107107
108-
18. `fwrite` now allows `dec` to be the same as `sep` when writing a single-column table, as `sep` is not used in this case. [#7227](https://github.com/Rdatatable/data.table/issues/7227). Thanks @MichaelChirico for the report and @venom1204 for the fix.
108+
18. `fwrite` now allows `dec` to be the same as `sep` when writing single-column or zero-row tables, as `sep` and/or `dec` are not used in these cases. [#7227](https://github.com/Rdatatable/data.table/issues/7227). Thanks @MichaelChirico for the report and @venom1204 for the fix.
109109
110110
### NOTES
111111

R/fwrite.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
4444
is.character(sep) && length(sep)==1L && (nchar(sep) == 1L || identical(sep, "")),
4545
is.character(sep2) && length(sep2)==3L && nchar(sep2[2L])==1L,
4646
is.character(dec) && length(dec)==1L && nchar(dec) == 1L,
47-
`dec and sep must be distinct for multi-column tables` = (ncol(x) <= 1L || dec != sep), # sep2!=dec and sep2!=sep checked at C level when we know if list columns are present
47+
`dec and sep must be distinct for multi-column tables with >0 rows` = (nrow(x) == 0L || ncol(x) <= 1L || dec != sep), # sep2!=dec and sep2!=sep checked at C level when we know if list columns are present
4848
is.character(eol) && length(eol)==1L,
4949
length(qmethod) == 1L && qmethod %chin% c("double", "escape"),
5050
length(compress) == 1L && compress %chin% c("auto", "none", "gzip"),

inst/tests/tests.Rraw

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21597,5 +21597,7 @@ test(2336.6, all.equal(t2 - as.Date(t1), t2 - t1))
2159721597
# fwrite: allow dec=',' with single column, #7227
2159821598
test(2337.1, fwrite(data.table(1), dec = ",", file = nullfile()), NULL)
2159921599
if (getRversion() >= "4.0.0") {
21600-
test(2337.2, fwrite(data.table(1, 2), dec = ",", sep = ","), error = "dec and sep must be distinct for multi-column tables")}
21600+
test(2337.2, fwrite(data.table(1, 2), dec = ",", sep = ","), error = "dec and sep must be distinct for multi-column tables with >0 rows")}
2160121601
test(2337.3, fwrite(data.table(c(0.1, 0.2)), dec = ",", sep = "\t", file = nullfile()), NULL)
21602+
test(2337.4, fwrite(data.table(a = numeric(), b = numeric()), dec = ",", sep = ","), NULL)
21603+
test(2337.5, fwrite(data.table(a = numeric()), dec = ",", sep = ","), NULL)

0 commit comments

Comments
 (0)