Skip to content

Commit 1fb7294

Browse files
added logic to handle select argumnt using .shallow()
1 parent 66cb6d2 commit 1fb7294

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

R/fwrite.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
1313
yaml = FALSE,
1414
bom = FALSE,
1515
verbose=getOption("datatable.verbose", FALSE),
16-
encoding = "") {
16+
encoding = "",
17+
select) {
1718
na = as.character(na[1L]) # fix for #1725
1819
if (length(encoding) != 1L || !encoding %chin% c("", "UTF-8", "native")) {
1920
stopf("Argument 'encoding' must be '', 'UTF-8' or 'native'.")
@@ -26,6 +27,16 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
2627
buffMB = as.integer(buffMB)
2728
nThread = as.integer(nThread)
2829
compressLevel = as.integer(compressLevel)
30+
31+
# Handle select argument using .shallow()
32+
if (!missing(select)) {
33+
if (is.data.table(x)) {
34+
cols = colnamesInt(x, select)
35+
shallow_x = .shallow(x, cols)
36+
} else {
37+
shallow_x = x[select]
38+
}
39+
}
2940
# write.csv default is 'double' so fwrite follows suit. write.table's default is 'escape'
3041
# validate arguments
3142
if (is.matrix(x)) { # coerce to data.table if input object is matrix

0 commit comments

Comments
 (0)