-
Notifications
You must be signed in to change notification settings - Fork 968
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
fwrite()
should (possibly invisibly) return the file path
#5706
Comments
why the file path as opposed to the latter behavior would be more like |
I guess because then you can work with the results of the write in the pipeline. It would be analogous to DT[, fwrite(.SD, group), by = group] Will create a bunch of files, but you don't have access to them (the result is an empty data.table). If files <- DT[, fwrite(.SD, group), by = group] and then use |
Not really, because the "main argument" of
Not necessarily, e.g. Your code can be done currently like: files <- DT[, fwrite(.SD, .BY$group), by = group]$group More generally, I think it's just a difference between code like: DT[, by = group, {
...
fwrite(.SD, file, ...)
.SD
}] and DT[, by = group, {
...
fwrite(.SD, file, ...)
file
}] So I'm still not sure why to prioritize one over the other. One way to approach this empirically would be to find out which object is used more: https://github.com/search?q=lang%3AR+%22fwrite%28%22+%22.SD%22+%22%7B%22&type=code |
Oh, sorry, I meant One issue with your examples is that you only grab the file name and not the full path. For DT2 <- DT |>
_[...] |>
fwrite("file.csv") |>
_[...] But the |
fwrite()
should (possibly invidibly) return the file path fwrite()
should (possibly invisibly) return the file path
@eliocamp I think that adding a write step between several modification steps would affect code readability. It will take more time to a new user to understand when we are saving the data in the script |
I agree. That's why I think that |
Got it. It will prevent me from writing a for loop to achieve that task. I wouldn't have written the next code as it is really clever.
It can become much harder if we want to save the files in a folder, so returning the file's path seems to be a good a idea.
|
Hi i want to work on this issue , @MichaelChirico I wanna know what you think should be returned |
AFAIU there is no decision made yet what should be returned by |
I would say if they return NULL then it is not very useful follow them. TRUE is already better result then NULL... |
what do you think should be returned? |
File name or path, depends what was provided |
Now
fwrite()
returnsinvisible()
, but I think it might be more useful if it returned the path to the created file. It's a trivial change and I don't think it would create issues with backward compatibility, since it's probably not likely that any code relies onfwrite()
not returning anything (although a similar change toggsave()
did break a few scripts 🤣).The text was updated successfully, but these errors were encountered: