Skip to content

Commit

Permalink
Progress deprecation of logicalAsInt (#6646)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Schwendinger <[email protected]>
  • Loading branch information
MichaelChirico and ben-schwen authored Dec 30, 2024
1 parent 0578714 commit 42aeddf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ rowwiseDT(
9. `key<-`, marked as deprecated since 2012 and unusable since v1.15.0, has been fully removed.
10. Deprecation of `logicalAsInt` argument to `fwrite()` has been upgraded from a warning (since v1.15.0) to an error. It will be removed in the next release.
# data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024)
## BUG FIXES
Expand Down
12 changes: 4 additions & 8 deletions R/fwrite.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
sep2=c("","|",""), eol=if (.Platform$OS.type=="windows") "\r\n" else "\n",
na="", dec=".", row.names=FALSE, col.names=TRUE,
qmethod=c("double","escape"),
logical01=getOption("datatable.logical01", FALSE),
logicalAsInt=logical01,
logical01=getOption("datatable.logical01", FALSE), # due to change to TRUE; see NEWS
logicalAsInt=NULL,
scipen=getOption('scipen', 0L),
dateTimeAs = c("ISO","squash","epoch","write.csv"),
buffMB=8, nThread=getDTthreads(verbose),
Expand All @@ -24,12 +24,8 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
else if (length(dateTimeAs)>1L) stopf("dateTimeAs must be a single string")
dateTimeAs = chmatch(dateTimeAs, c("ISO","squash","epoch","write.csv"))-1L
if (is.na(dateTimeAs)) stopf("dateTimeAs must be 'ISO','squash','epoch' or 'write.csv'")
if (!missing(logical01) && !missing(logicalAsInt))
stopf("logicalAsInt has been renamed logical01. Use logical01 only, not both.")
if (!missing(logicalAsInt)) {
warningf("logicalAsInt has been renamed logical01 for consistency with fread. It works fine for now but please change to logical01 at your convenience so we can remove logicalAsInt in future.")
logical01 = logicalAsInt
logicalAsInt=NULL
if (!is.null(logicalAsInt)) {
stopf("logicalAsInt has been renamed logical01 for consistency with fread.")
}
scipen = if (is.numeric(scipen)) as.integer(scipen) else 0L
buffMB = as.integer(buffMB)
Expand Down
8 changes: 2 additions & 6 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -10933,10 +10933,7 @@ test(1736.03, fwrite(DT, sep2=c("",",","")), error="sep.*,.*sep2.*,.*must all be
test(1736.04, fwrite(DT, sep2=c("","||","")), error="nchar.*sep2.*2")
test(1736.05, capture.output(fwrite(DT, sep='|', sep2=c("c(",",",")"), logical01=FALSE)), c("A|B|C", "1|c(1,2,3,4,5,6,7,8,9,10)|c(s,t,u,v,w)",
"2|c(15,16,17,18)|c(1.2,2.3,3.4,3.14159265358979,-9)", "3|c(7)|c(foo,bar)", "4|c(9,10)|c(TRUE,TRUE,FALSE)"))
test(1736.06, capture.output(fwrite(DT, sep='|', sep2=c("{",",","}"), logicalAsInt=TRUE)),
c("A|B|C", "1|{1,2,3,4,5,6,7,8,9,10}|{s,t,u,v,w}",
"2|{15,16,17,18}|{1.2,2.3,3.4,3.14159265358979,-9}", "3|{7}|{foo,bar}", "4|{9,10}|{1,1,0}"),
warning="logicalAsInt has been renamed logical01")
test(1736.06, fwrite(DT, sep='|', sep2=c("{",",","}"), logicalAsInt=TRUE), error="logicalAsInt has been renamed logical01")
DT = data.table(A=c("foo","ba|r","baz"))
test(1736.07, capture.output(fwrite(DT,na="")), c("A","foo","ba|r","baz")) # no list column so no need to quote
test(1736.08, capture.output(fwrite(DT)), c("A","foo","ba|r","baz"))
Expand Down Expand Up @@ -15957,8 +15954,7 @@ DT[ , z := 0L]
test(2074.31, dcast(DT, V1 ~ z, fun.aggregate=eval(quote(length)), value.var='z'),
data.table(V1=c('a', 'b'), `0`=2:1,key='V1'))

# fwrite both logical args
test(2074.32, fwrite(DT, logical01=TRUE, logicalAsInt=TRUE), error="logicalAsInt has been renamed")
# 2074.32 tested that setting both logical01 and logicalAsInt errored; no longer relevant

# merge.data.table
test(2074.33, merge(DT, DT, by.x = 1i, by.y=1i), error="A non-empty vector of column names is required")
Expand Down
4 changes: 2 additions & 2 deletions man/fwrite.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fwrite(x, file = "", append = FALSE, quote = "auto",
eol = if (.Platform$OS.type=="windows") "\r\n" else "\n",
na = "", dec = ".", row.names = FALSE, col.names = TRUE,
qmethod = c("double","escape"),
logical01 = getOption("datatable.logical01", FALSE),
logicalAsInt = logical01, # deprecated
logical01 = getOption("datatable.logical01", FALSE), # due to change to TRUE; see NEWS
logicalAsInt = NULL, # deprecated
scipen = getOption('scipen', 0L),
dateTimeAs = c("ISO","squash","epoch","write.csv"),
buffMB = 8L, nThread = getDTthreads(verbose),
Expand Down

0 comments on commit 42aeddf

Please sign in to comment.