-
Notifications
You must be signed in to change notification settings - Fork 78
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
suggestion: overload /
for pathlib-like path construction
#110
Comments
You can actually just define the #' @export
`/.fs_path` <- function(e1, e2) {
path(e1, e2)
} I guess this also begs the question if we should define path_home() / letters[1:3] / "baz" + ".txt"
#> /Users/jhester/a/baz.txt /Users/jhester/b/baz.txt /Users/jhester/c/baz.txt My main reservation with this in general is traditionally R string based objects do not overload mathematical operators in this way, however I do agree the resulting syntax is nice. |
ha so I struggled a bit trying to get something like `/`.fs_path <- function and figured the problem was using a base operator; didn't think to try moving the backtick way over there! Definitely much simpler. I also see now why you'd use Would the `+.fs_path` <- function(e1, e2) {
paste0(e1, e2)
} I understand your reservation but also love that clean syntax. Aside from breaking with tradition, since it's an Let me know which of these two (if any) you'd like to see, and I can take a stab at a PR. |
Ok I have added this. I am still somewhat unsure if there are unforeseen consequences, so it is somewhat experimental for now and won't be widely advertised in examples until we are more confident about it. |
Excellent, thanks Jim! Hope they work smoothly; I've already started using them, but not for anything remotely complex. |
I've been using python a lot lately and have come to love the intuitiveness of the division operator in
pathlib
:I think
fs
is the closest analog topathlib
, and similar overloading could be implemented like this:(I suspect
NextMethod
should be something else to more exactly preserve the base error message, but I'm not sure what; my OO-foo is weak. I just know something needs to be there to preventNULL
s being returned for each unhandled generic.)Is this worthy of inclusion in
fs
? If so I'd gladly submit a PR with tests and such.The text was updated successfully, but these errors were encountered: