Skip to content

Commit bb8320d

Browse files
moved select logic to address matrix inputs also
1 parent d0956f3 commit bb8320d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

R/fwrite.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
2727
buffMB = as.integer(buffMB)
2828
nThread = as.integer(nThread)
2929
compressLevel = as.integer(compressLevel)
30-
31-
# Handle select argument using .shallow()
32-
if (!null(select)) {
33-
if (is.data.table(x)) {
34-
cols = colnamesInt(x, select)
35-
x = .shallow(x, cols)
36-
} else {
37-
x = x[select]
38-
}
39-
}
30+
4031
# write.csv default is 'double' so fwrite follows suit. write.table's default is 'escape'
4132
# validate arguments
4233
if (is.matrix(x)) { # coerce to data.table if input object is matrix
@@ -49,6 +40,16 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
4940
x = as.data.table(x)
5041
}
5142
}
43+
# Handle select argument using .shallow()
44+
if (!null(select)) {
45+
cols = colnamesInt(x, select)
46+
if (is.data.table(x)) {
47+
x = .shallow(x, cols)
48+
} else {
49+
x = x[select]
50+
}
51+
}
52+
5253
stopifnot(
5354
is.list(x),
5455
identical(quote,"auto") || isTRUEorFALSE(quote),

0 commit comments

Comments
 (0)