-
-
Notifications
You must be signed in to change notification settings - Fork 206
chore: improve errors in iterators.R #2006
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
Open
maelle
wants to merge
1
commit into
main
Choose a base branch
from
stoop2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1079,7 +1079,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
} | ||
if (is.logical(ii) && (length(ii) != length(x) && length(ii) != 1)) { | ||
cli::cli_abort( | ||
"Error: Logical index length does not match the number of edges. Recycling is not allowed." | ||
"Logical index length does not match the number of edges. Recycling is not allowed." | ||
) | ||
} | ||
|
||
|
@@ -1144,14 +1144,11 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @name igraph-vs-attributes | ||
#' @export | ||
`[[<-.igraph.vs` <- function(x, i, value) { | ||
if ( | ||
!"name" %in% names(attributes(value)) || | ||
!"value" %in% names(attributes(value)) | ||
) { | ||
cli::cli_abort("Invalid indexing.") | ||
if (!rlang::has_name(attributes(value), "name")) { | ||
cli::cli_abort("Can't find {.val name} for attribute.") | ||
} | ||
if (is.null(get_vs_graph(x))) { | ||
stop("Graph is unknown.") | ||
cli::cli_abort("Can't find graph.") | ||
} | ||
value | ||
} | ||
|
@@ -1166,14 +1163,11 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @name igraph-es-attributes | ||
#' @export | ||
`[[<-.igraph.es` <- function(x, i, value) { | ||
if ( | ||
!"name" %in% names(attributes(value)) || | ||
!"value" %in% names(attributes(value)) | ||
) { | ||
stop("Invalid indexing.") | ||
if (!rlang::has_name(attributes(value), "name")) { | ||
cli::cli_abort("Can't find {.val name} for attribute.") | ||
} | ||
if (is.null(get_es_graph(x))) { | ||
stop("Graph is unknown.") | ||
cli::cli_abort("Can't find graph.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether we could improve this. |
||
} | ||
value | ||
} | ||
|
@@ -1239,7 +1233,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
`$.igraph.vs` <- function(x, name) { | ||
graph <- get_vs_graph(x) | ||
if (is.null(graph)) { | ||
cli::cli_abort("Graph is unknown") | ||
cli::cli_abort("Can't find graph.") | ||
} | ||
res <- vertex_attr(graph, name, x) | ||
if (is_single_index(x)) { | ||
|
@@ -1292,7 +1286,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
`$.igraph.es` <- function(x, name) { | ||
graph <- get_es_graph(x) | ||
if (is.null(graph)) { | ||
cli::cli_abort("Graph is unknown") | ||
cli::cli_abort("Can't find graph.") | ||
} | ||
res <- edge_attr(graph, name, x) | ||
if (is_single_index(x)) { | ||
|
@@ -1310,7 +1304,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @export | ||
`$<-.igraph.vs` <- function(x, name, value) { | ||
if (is.null(get_vs_graph(x))) { | ||
cli::cli_abort("Graph is unknown") | ||
cli::cli_abort("Can't find graph.") | ||
} | ||
attr(x, "name") <- name | ||
attr(x, "value") <- value | ||
|
@@ -1325,7 +1319,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @family vertex and edge sequences | ||
`$<-.igraph.es` <- function(x, name, value) { | ||
if (is.null(get_es_graph(x))) { | ||
cli::cli_abort("Graph is unknown") | ||
cli::cli_abort("Can't find graph.") | ||
} | ||
attr(x, "name") <- name | ||
attr(x, "value") <- value | ||
|
@@ -1336,11 +1330,8 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @export | ||
`V<-` <- function(x, value) { | ||
ensure_igraph(x) | ||
if ( | ||
!"name" %in% names(attributes(value)) || | ||
!"value" %in% names(attributes(value)) | ||
) { | ||
cli::cli_abort("invalid indexing") | ||
if (!rlang::has_name(attributes(value), "name")) { | ||
cli::cli_abort("Can't find {.val name} for vertex attribute.") | ||
} | ||
i_set_vertex_attr( | ||
x, | ||
|
@@ -1360,11 +1351,8 @@ simple_es_index <- function(x, i, na_ok = FALSE) { | |
#' @export | ||
`E<-` <- function(x, path = NULL, P = NULL, directed = NULL, value) { | ||
ensure_igraph(x) | ||
if ( | ||
!"name" %in% names(attributes(value)) || | ||
!"value" %in% names(attributes(value)) | ||
) { | ||
cli::cli_abort("invalid indexing") | ||
if (!rlang::has_name(attributes(value), "name")) { | ||
cli::cli_abort("Can't find {.val name} for edge attribute.") | ||
} | ||
i_set_edge_attr( | ||
x, | ||
|
@@ -1563,7 +1551,7 @@ as_igraph_vs <- function(graph, v, na.ok = FALSE) { | |
if (is.character(v) && "name" %in% vertex_attr_names(graph)) { | ||
v <- as.numeric(match(v, V(graph)$name)) | ||
if (!na.ok && any(is.na(v))) { | ||
cli::cli_abort("Invalid vertex names") | ||
cli::cli_abort("Invalid vertex names {.arg v}.") | ||
} | ||
v | ||
} else { | ||
|
@@ -1575,7 +1563,7 @@ as_igraph_vs <- function(graph, v, na.ok = FALSE) { | |
res <- as.numeric(v) | ||
} | ||
if (!na.ok && any(is.na(res))) { | ||
cli::cli_abort("Invalid vertex name(s)") | ||
cli::cli_abort("Invalid vertex name(s) {.arg v}.") | ||
} | ||
res | ||
} | ||
|
@@ -1618,7 +1606,7 @@ as_igraph_es <- function(graph, e) { | |
res <- as.numeric(e) | ||
} | ||
if (any(is.na(res))) { | ||
cli::cli_abort("Invalid edge names") | ||
cli::cli_abort("Invalid edge names {.arg e}.") | ||
} | ||
res | ||
} | ||
|
@@ -1638,7 +1626,7 @@ parse_op_args <- function(..., what, is_fun, as_fun, check_graph = TRUE) { | |
args <- list(...) | ||
|
||
if (any(!sapply(args, is_fun))) { | ||
cli::cli_abort("Not {what} sequence") | ||
cli::cli_abort("Not {what} sequence.") | ||
} | ||
|
||
## get the ids of all graphs | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how value could be missing. I've added tests for when name is missing, but value missing would mean nothing on the right side of the arrow?! Am I missing something obvious?
In any case we need to improve the mysterious "Invalid indexing" error.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With main:
With stoop2 branch
Created on 2025-07-23 with reprex v2.1.1
Not sure this helps with your question because this function confuses me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you were able to get this error, no name, but no value makes 0 sense to me. I find the message "invalid indexing" extremely confusing.