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

Use vec_interleave() #45

Closed
Robinlovelace opened this issue Sep 30, 2023 · 8 comments · Fixed by #46
Closed

Use vec_interleave() #45

Robinlovelace opened this issue Sep 30, 2023 · 8 comments · Fixed by #46

Comments

@Robinlovelace
Copy link
Member

See ropensci/stplanr#544

@JosiahParry
Copy link

I think using vctrs::vec_interleave() as you demonstrated will help speed this up quite a bit

@Robinlovelace
Copy link
Member Author

Weird thing: I'm hitting an error message after switching to it, will double check...

@JosiahParry
Copy link

I think od returns a dataframe. Maybe you need to use vec_interleave() + as.data.frame()

@Robinlovelace
Copy link
Member Author

That's what I've got:

od_coordinates_ids = function(odc) {
  res = vctrs::vec_interleave(odc[, 1:2], odc[, 3:4])
  res = data.frame(id = rep(1:nrow(odc), each = 2), x = res[, 1], y = res[, 2])
  res
}

@Robinlovelace
Copy link
Member Author

It's something about NA values.

@Robinlovelace
Copy link
Member Author

Previous one for reference:

od_coordinates_ids = function(odc) {
  res = data.frame(id = rep(1:nrow(odc), each = 2), x = NA, y = NA)
  ids_odd = seq(1, nrow(res), by = 2)
  ids_even = ids_odd + 1
  res[ids_odd, c("x", "y")] = odc[, 1:2]
  res[ids_even, c("x", "y")] = odc[, 3:4]
  res
}

@Robinlovelace Robinlovelace linked a pull request Sep 30, 2023 that will close this issue
@Robinlovelace
Copy link
Member Author

Error:

   --- re-building ‘od.Rmd’ using rmarkdown
   
   Quitting from lines 326-327 [unnamed-chunk-20] (od.Rmd)
   Error: processing vignette 'od.Rmd' failed with diagnostics:
   NA value(s) in bounding box. Trying to plot empty geometries?

@Robinlovelace
Copy link
Member Author

OK problem found: as you say, vctrs expects a matrix.

Robinlovelace added a commit that referenced this issue Sep 30, 2023
* Use vctrs::vec_interleave(), close #45

* Another attempt..#

* Fix new od_coordinates_ids() implementation

* Increment version number to 0.4.1

* Add news
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