Skip to content

chore: improve errors in iterators.R - #2006

Open
maelle wants to merge 10 commits into
mainfrom
stoop2
Open

chore: improve errors in iterators.R#2006
maelle wants to merge 10 commits into
mainfrom
stoop2

Conversation

@maelle

@maelle maelle commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Fix #1891
Part of #731

@maelle
maelle requested a review from schochastics July 22, 2025 14:50
Comment thread R/iterators.R
Comment thread R/iterators.R Outdated
}
if (is.null(get_es_graph(x))) {
stop("Graph is unknown.")
cli::cli_abort("Can't find graph.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we could improve this.

@krlmlr

krlmlr commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Let's split this PR, the "Graph is unknown" thing is special and might become unnecessary with the new attribute handling, I hope.

@maelle

maelle commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

Sorry, but split into what? One PR with all error messages minus the one I commented on?

@maelle

maelle commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

#2006 (comment)

@krlmlr

krlmlr commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Let's find or generate extensive tests for the intended behavior of this code. The RHS for these assignments is an object with name and value attributes, I'd like to understand actual usage examples.

Resolve the R/iterators.R conflicts by keeping main's newer error
conventions (anyNA(), !all(), .internal = TRUE for the
graph-unknown aborts) while preserving this branch's message
improvements that its merged test snapshots assert -- notably the
"Can't find \"name\" for attribute." check in `[[<-.igraph.es`,
now consistent with the vs method.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016M32izVHZPfxAqemAe4BrX
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 2be846a is merged into main:

  • ❗🐌as_adjacency_matrix: 744ms -> 765ms [+2.04%, +3.58%]
  • ✔️as_biadjacency_matrix: 743ms -> 741ms [-0.83%, +0.27%]
  • 🚀as_data_frame_both: 1.64ms -> 1.55ms [-8%, -2.78%]
  • 🚀as_long_data_frame: 4.02ms -> 3.91ms [-3.83%, -1.55%]
  • ✔️es_attr_filter: 2.68ms -> 2.73ms [-0.34%, +3.55%]
  • ✔️graph_from_adjacency_matrix: 118ms -> 118ms [-1.11%, +1.38%]
  • 🚀graph_from_data_frame: 3.73ms -> 3.46ms [-8.76%, -5.96%]
  • ✔️vs_attr_filter: 1.54ms -> 1.52ms [-3.75%, +1.33%]
  • ✔️vs_by_name: 980µs -> 979µs [-1.71%, +1.57%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@krlmlr

krlmlr commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

I wonder if we should just make <- NULL work idiomatically -- drop attribute. We could assess the revdep impact.

@maelle

maelle commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

I had added the hackathon label to #1891 😸

@krlmlr

krlmlr commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Can we solve #1891 as part of this PR?

Comment thread R/iterators.R
#' @name igraph-vs-attributes
#' @export
`[[<-.igraph.vs` <- function(x, i, value) {
if (!rlang::has_name(attributes(value), "attr_name")) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked Claude to rename name and value to attr_name and attr_value in this context because I think the double "value" added to my confusion when I first looked at this code.

@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if f46e70f is merged into main:

  • ❗🐌as_adjacency_matrix: 872ms -> 926ms [+3.3%, +9.23%]
  • ✔️as_biadjacency_matrix: 871ms -> 861ms [-2.93%, +0.56%]
  • 🚀as_data_frame_both: 1.85ms -> 1.74ms [-8.96%, -2.95%]
  • ✔️as_long_data_frame: 4.41ms -> 4.37ms [-5.35%, +3.31%]
  • ✔️es_attr_filter: 3.35ms -> 3.35ms [-2.81%, +2.45%]
  • ✔️graph_from_adjacency_matrix: 141ms -> 143ms [-1.92%, +4.74%]
  • 🚀graph_from_data_frame: 4.06ms -> 3.82ms [-9.25%, -2.43%]
  • ✔️vs_attr_filter: 1.85ms -> 1.86ms [-1.87%, +3.09%]
  • ✔️vs_by_name: 1.23ms -> 1.21ms [-4.3%, +1.14%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting an attribute to NULL fails

4 participants