Skip to content
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

od_oneway() replaces the variable names by "o" and "d" #53

Closed
temospena opened this issue Sep 8, 2024 · 2 comments · Fixed by #54
Closed

od_oneway() replaces the variable names by "o" and "d" #53

temospena opened this issue Sep 8, 2024 · 2 comments · Fixed by #54

Comments

@temospena
Copy link
Collaborator

I am moving from stplanr to od simply to create desire lines.

Is there any (good) reason that the od::od_oneway() replaces the origin and destination variable names by o and d, instead keeping them, as it happens in stplanr::od_oneway() ?

library(od)
od_min = od_data_df[c(1, 2, 1), 1:4]
names(od_min)
#> [1] "geo_code1" "geo_code2" "all"       "train"


### od_oneway with stplar
od_oneway_stplanr = stplanr::od_oneway(od_min)
names(od_oneway_stplanr)
#> [1] "geo_code1" "geo_code2" "all"       "train"


### od_oneway with od
od_oneway_od = od::od_oneway(od_min)
names(od_oneway_od)
#> [1] "o"     "d"     "all"   "train"

Created on 2024-09-08 with reprex v2.1.1

@Robinlovelace
Copy link
Member

Is there any (good) reason that the od::od_oneway() replaces the origin and destination variable names by o and d, instead keeping them, as it happens in stplanr::od_oneway() ?

No good reason, this is a bug I think @temospena, thanks for reporting.

I suspect it's a quick fix, if so, PR would be very welcome. If not, happy to take a look.

@temospena
Copy link
Collaborator Author

Ok, I just PR!

I added this:

od_oneway = function(x,
                     attrib = names(x[-c(1:2)])[vapply(x[-c(1:2)], is.numeric, TRUE)],
                     FUN = sum,
                     ...,
                     id1 = names(x)[1],
                     id2 = names(x)[2],
                     oneway_key = NULL) {
...
  names(x_oneway)[c(1,2)] = c(id1, id2) # rename columns with original names
...
  return(x_oneway)
}

It doesn't seem to break up other functions, but please double check.

Now it returns the expected output:

library(od)
od_min = od_data_df[c(1, 2, 1), 1:4]
names(od_min)
#> [1] "geo_code1" "geo_code2" "all"       "train"

### od_oneway with stplar
od_oneway_stplanr = stplanr::od_oneway(od_min)
names(od_oneway_stplanr)
#> [1] "geo_code1" "geo_code2" "all"       "train"

### od_oneway with od
od_oneway_od = od::od_oneway(od_min)
names(od_oneway_od)
#> [1] "geo_code1" "geo_code2" "all"       "train"

Created on 2024-10-07 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants