-
Notifications
You must be signed in to change notification settings - Fork 979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return File Path after Writing in fwrite
#6181
Open
Nj221102
wants to merge
8
commits into
master
Choose a base branch
from
fwrite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f308596
returning filepath from fwrite
470b276
updated tests
10fcde8
updated tests
94c0730
updated news
7257b5a
Update NEWS.md
Nj221102 68a7b1f
updated tests
9e13703
updated tests
f0e5510
updated tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9977,7 +9977,7 @@ test(1658.31, fwrite(ok_dt, qmethod=c("double", "double")), error="length(qmetho | |
test(1658.32, fwrite(ok_dt, col.names="foobar"), error="isTRUEorFALSE(col.names)") | ||
|
||
# null data table (no columns) | ||
test(1658.33, fwrite(data.table(NULL)), NULL, warning="Nothing to write") | ||
test(1658.33, fwrite(data.table(NULL)), "", warning="Nothing to write") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, wonder how useful this case is too -- when |
||
|
||
test(1658.34, fwrite(data.table(id=c("A","B","C"), v=c(1.1,0.0,9.9))), output="id,v\nA,1.1\nB,0\nC,9.9") | ||
|
||
|
@@ -10009,9 +10009,9 @@ if (!haszlib()) { | |
} else { | ||
test(1658.41, fwrite(data.table(a=c(1:3), b=c(1:3)), compress="gzip"), output='a,b\n1,1\n2,2\n3,3') # compress ignored on console | ||
DT = data.table(a=rep(1:2,each=100), b=rep(1:4,each=25)) | ||
test(1658.421, fwrite(DT, file=f1<-tempfile(fileext=".gz"), verbose=TRUE), NULL, | ||
test(1658.421, fwrite(DT, file=f1<-tempfile(fileext=".gz"), verbose=TRUE), f1, | ||
Nj221102 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
output="args.nrow=200 args.ncol=2.*maxLineLen=5[12].*Writing 200 rows in 1 batches of 200 rows.*nth=1") # [12] for Windows where eolLen==2 | ||
test(1658.422, fwrite(DT, file=f2<-tempfile()), NULL) | ||
test(1658.422, fwrite(DT, file=f2<-tempfile()), f2) | ||
test(1658.423, file.info(f1)$size < file.info(f2)$size) # 74 < 804 (file.size() isn't available in R 3.1.0) | ||
if (test_R.utils) test(1658.43, fread(f1), DT) # use fread to decompress gz (works cross-platform) | ||
fwrite(DT, file=f3<-tempfile(), compress="gzip") # compress to filename not ending .gz | ||
|
@@ -10046,7 +10046,7 @@ unlink(c(f1, f2)) | |
# compression error -5 due to only 3 bytes (bom) in first block; #3599 | ||
if (haszlib()) { | ||
DT = data.table(l=letters, n=1:26) | ||
test(1658.53, fwrite(DT, file=f<-tempfile(fileext=".gz"), bom=TRUE, col.names=FALSE), NULL) | ||
test(1658.53, fwrite(DT, file=f<-tempfile(fileext=".gz"), bom=TRUE, col.names=FALSE), f) | ||
if (test_R.utils) test(1658.54, fread(f), setnames(DT,c("V1","V2"))) | ||
unlink(f) | ||
} | ||
|
@@ -10059,7 +10059,7 @@ test(1658.56, fwrite(data.table(exp(1) - pi*1i)), output='2.718[0-9]*-3.141[0-9] | |
DT = data.table(a=1:3, b=list(1:4, c(3.14, 100e10), c(3i,4i,5i))) | ||
test(1658.57, fwrite(DT), output='0+3i|0+4i|0+5i') | ||
DT[ , b := c(1i, -1-1i, NA_complex_)] | ||
test(1658.58, fwrite(DT), output='a,b\n1,0\\+1i\n2,-1-1i\n3,$') | ||
test(1658.58, invisible(fwrite(DT)), output='a,b\n1,0+1i\n2,-1-1i\n3,\n') | ||
Nj221102 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# more coverage | ||
test(1658.59, fwrite(data.table(a=list('a')), verbose=TRUE), | ||
|
@@ -10809,7 +10809,7 @@ if (test_bit64) { | |
test(1731.1, class(DT[[1L]]), "integer64") | ||
test(1731.2, fwrite(DT,na="__NA__"), output=ans) | ||
f = tempfile() | ||
test(1731.3, fwrite(DT, f, na="__NA__"), NULL) | ||
test(1731.3, fwrite(DT, f, na="__NA__"), f) | ||
Nj221102 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test(1731.4, readLines(f), ans) | ||
unlink(f) | ||
ans[1] = "V1" # the field is unquoted under `quote=FALSE` | ||
|
@@ -10910,7 +10910,7 @@ test(1736.09, capture.output(fwrite(DT)), c("A,B", "foo,1|2|3", "\"ba|r\",1|2|3| | |
test(1736.10, capture.output(fwrite(DT,quote=TRUE)), c("\"A\",\"B\"", "\"foo\",1|2|3", "\"ba|r\",1|2|3|4", "\"baz\",\"fo|o\"|\"ba,r\"|\"baz\"")) | ||
|
||
# any list of same length vector input | ||
test(1737.1, fwrite(list()), NULL, warning="fwrite was passed an empty list of no columns") | ||
test(1737.1, fwrite(list()), "", warning="fwrite was passed an empty list of no columns") | ||
test(1737.2, fwrite(list(1.2)), output="1.2") | ||
test(1737.3, fwrite(list(1.2,B="foo")), output=",B\n1.2,foo") | ||
test(1737.4, fwrite(list("A,Name"=1.2,B="fo,o")), output="\"A,Name\",B\n1.2,\"fo,o\"") | ||
|
@@ -13089,11 +13089,11 @@ unlink(f) | |
#fwrite creates a file or does nothing, as appropriate, also #2898 | ||
DT = data.table(NULL) | ||
f = tempfile() | ||
test(1922.7, fwrite(DT, f), NULL, warning = 'no columns; creating an empty file') | ||
test(1922.7, fwrite(DT, f), f, warning = 'no columns; creating an empty file') | ||
## above test created a file; now test behavior when file exists | ||
test(1922.8, fwrite(DT, f), NULL, warning = 'no columns; doing nothing.*file.remove') | ||
test(1922.8, fwrite(DT, f), f, warning = 'no columns; doing nothing.*file.remove') | ||
## slightly different behavior if append = TRUE | ||
test(1922.9, fwrite(DT, f, append = TRUE), NULL, warning = 'doing nothing.$') | ||
test(1922.9, fwrite(DT, f, append = TRUE), f, warning = 'doing nothing.$') | ||
|
||
# create index even if key present by setting attribute, #2883 | ||
DT = data.table(1:5, 1:5) | ||
|
@@ -13141,8 +13141,8 @@ test(1937.1, DT[A %between% c(B,B+1)], error='RHS has length().*Perhaps you mean | |
test(1937.2, DT[A %between% B], error='length 2. The first') | ||
|
||
# that fwrite'ing a list to a file works (it broke in dev 1.11.5 and was caught before release), PR#3017 | ||
test(1938.1, fwrite(list(1:3)), NULL, output="1\n2\n3") # never broke | ||
test(1938.2, fwrite(list(1:3), file=f<-tempfile()), NULL) # just adding file= was what broke in dev just when x is list and not data.table|frame | ||
test(1938.1, fwrite(list(1:3)), "", output="1\n2\n3") # never broke | ||
test(1938.2, fwrite(list(1:3), file=f<-tempfile()), f) # just adding file= was what broke in dev just when x is list and not data.table|frame | ||
test(1939.3, readLines(f), as.character(1:3)) | ||
unlink(f) | ||
|
||
|
@@ -13775,9 +13775,9 @@ if (.Platform$OS.type=="windows") { | |
test(1966.4, list.files(path = pth, pattern = "\\.csv$"), f) | ||
unlink(c(fp, file.path(pth, "\u00c3\u00b6.csv"))) | ||
p = file.path(pth, "\u00fc"); dir.create(p); f = tempfile(tmpdir = p) | ||
test(1966.5, fwrite(DT, enc2native(f)), NULL) | ||
test(1966.5, fwrite(DT,filepath<-enc2native(f)), filepath) | ||
Nj221102 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unlink(f) | ||
test(1966.6, fwrite(DT, enc2utf8(f)), NULL) | ||
test(1966.6, fwrite(DT, filepath<-enc2native(f)), filepath) | ||
unlink(p, recursive = TRUE) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here
NULL
should be returned, since the actualfile
is not affected at all byfwrite()
? WDYT @eliocampThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a though one. Honestly this behaviour is kind of unexpected to me. I would've expected
fwrite
to either write an empty file or to throw an error.With
append == TRUE
, the file is left untouched, which would be the expected behaviour when writing an empty data.table, so returning the file would make sense, though.