Use `vctrs` for vector recycling
Replaces manual vector recycling using rep(x, length.out = n) with vctrs::vec_recycle(x, n) for better error messages and consistency.
Changes
-
R/plot.R: Use
vctrs::vec_size_common()to determine common size inigraph.Arrows(), then recycle all parameters to that size -
R/games.R, R/centrality.R, R/epi.R: Replace
rep(..., length.out = )withvctrs::vec_recycle() - R/plot.shapes.R, R/plot.common.R, R/tkplot.R, R/sparsedf.R: Same pattern throughout plotting and utility functions
Example
Before:
recycle <- function(x) rep(x, length.out = n)
x1 <- recycle(x1)
y1 <- recycle(y1)
After:
n <- vctrs::vec_size_common(x1, y1, x2, y2)
x1 <- vctrs::vec_recycle(x1, n)
y1 <- vctrs::vec_recycle(y1, n)
This provides clearer error messages when inputs have incompatible sizes and centralizes recycling logic through a well-tested dependency already in use.
Original prompt
This section details on the original issue you should resolve
<issue_title>use vctrs in more places</issue_title> <issue_description>when there is recycling
e.g. use
vctrs::vec_size_common()</issue_description>Comments on the Issue (you are @copilot in this section)
- Fixes igraph/rigraph#1249
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
@krlmlr for such patterns do we also want to add some linting to prevent future drift?