Skip to content

Commit f210a33

Browse files
committed
updated
1 parent 799d0b3 commit f210a33

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

vignettes/datatable-fread-and-fwrite.Rmd

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,19 @@ From v1.10.6, `fread` resolves ambiguities more reliably across the entire file
216216

217217
When data is written as strings (either inherently, like character columns, or by choice, like `dateTimeAs="ISO"`), `quote="auto"` (default) intelligently quotes fields:
218218

219-
**Contextual Quoting**: Only quotes fields if they contain the delimiter (`sep`), a double quote, or a newline. This ensures clean, RFC 4180-compliant CSVs.
219+
**Contextual Quoting**:Fields are quoted only when necessary. This happens if they contain the delimiter `(sep)`, a double quote `(")`, a newline `(\n)`, a carriage return `(\r)`, or if the field is an empty string `("")`. Quoting the empty string is done to distinguish it from an NA value when the file is read.
220220

221-
**Bypassed for Direct Numeric Output**: If specific columns are written as their underlying numeric types (e.g., via `dateTimeAs="epoch"` for POSIXct, or if a user pre-converts Date to integer), then quoting logic is naturally bypassed for those numeric fields, contributing to efficiency.
221+
**Bypassed for Direct Numeric Output**: If specific columns are written as their underlying numeric types (e.g., via `dateTimeAs="epoch"` for `POSIXct`, or if a user pre-converts Date to integer), then quoting logic is naturally bypassed for those numeric fields, contributing to efficiency.
222222

223223
```{r}
224224
dt_quoting_scenario = data.table(
225-
text_field = c("Contains,a,comma", "Contains \"a quote\"", "Contains\na newline", "Clean_text"),
226-
epoch_time = as.numeric(as.POSIXct("2023-10-26 14:35:00", tz = "GMT") + 1:4), # Already numeric
227-
numeric_field = 1:4
225+
text_field = c("Contains,a,comma", "Contains \"a quote\"", "Clean_text", "", NA),
226+
numeric_field = 1:5
228227
)
229-
temp_quote_adv = tempfile(fileext = ".csv")
228+
temp_quote_adv <- tempfile(fileext = ".csv")
230229
231-
# Quoting applies to text_field, but not to epoch_time or numeric_field
232230
fwrite(dt_quoting_scenario, temp_quote_adv)
231+
# Note the output: the empty string is quoted (""), but the NA is not.
233232
cat(readLines(temp_quote_adv), sep = "\n")
234233
```
235234

0 commit comments

Comments
 (0)