@@ -349,6 +349,9 @@ graph.attributes <- function(graph) {
349
349
" graph.attributes<-" <- function (graph , value ) {
350
350
ensure_igraph(graph )
351
351
assert_named_list(value )
352
+ if (inherits(value , " data.frame" )) {
353
+ value <- as.list(value )
354
+ }
352
355
353
356
.Call(R_igraph_mybracket2_set , graph , igraph_t_idx_attr , igraph_attr_idx_graph , value )
354
357
}
@@ -487,12 +490,8 @@ i_set_vertex_attr <- function(graph, name, index = V(graph), value, check = TRUE
487
490
} else if (length(value ) == length(index )) {
488
491
value_in <- unname(value )
489
492
} else {
490
- stop(
491
- " Length of new attribute value must be " ,
492
- if (length(index ) != 1 ) " 1 or " ,
493
- length(index ),
494
- " , the number of target vertices, not " ,
495
- length(value )
493
+ cli :: cli_abort(
494
+ " Length of new attribute value must be {if (length(index) != 1) '1 or '}{length(index)}, the number of target vertices, not {length(value)}."
496
495
)
497
496
}
498
497
@@ -541,16 +540,19 @@ set_value_at <- function(value, idx, length_out) {
541
540
ensure_igraph(graph )
542
541
543
542
assert_named_list(value )
543
+ if (inherits(value , " data.frame" )) {
544
+ value <- as.list(value )
545
+ }
544
546
545
547
if (! all(lengths(value ) == length(index ))) {
546
- stop (" Invalid attribute value length, must match number of vertices" )
548
+ cli :: cli_abort (" Invalid attribute value length, must match number of vertices. " )
547
549
}
548
550
549
551
if (! missing(index )) {
550
552
index <- as_igraph_vs(graph , index )
551
553
552
554
if (anyDuplicated(index ) || anyNA(index )) {
553
- stop( " Invalid vertices in index " )
555
+ cli :: cli_abort( " {.arg index} contains duplicated vertices or NAs. " )
554
556
}
555
557
}
556
558
@@ -698,12 +700,8 @@ i_set_edge_attr <- function(graph, name, index = E(graph), value, check = TRUE)
698
700
} else if (length(value ) == length(index )) {
699
701
value_in <- unname(value )
700
702
} else {
701
- stop(
702
- " Length of new attribute value must be " ,
703
- if (length(index ) != 1 ) " 1 or " ,
704
- length(index ),
705
- " , the number of target edges, not " ,
706
- length(value )
703
+ cli :: cli_abort(
704
+ " Length of new attribute value must be {if (length(index) != 1) '1 or '}{length(index)}, the number of target edges, not {length(value)}."
707
705
)
708
706
}
709
707
@@ -741,15 +739,18 @@ edge.attributes <- function(graph, index = E(graph)) {
741
739
ensure_igraph(graph )
742
740
743
741
assert_named_list(value )
742
+ if (inherits(value , " data.frame" )) {
743
+ value <- as.list(value )
744
+ }
744
745
745
746
if (any(sapply(value , length ) != length(index ))) {
746
- stop (" Invalid attribute value length, must match number of edges" )
747
+ cli :: cli_abort (" Invalid attribute value length, must match number of edges" )
747
748
}
748
749
749
750
if (! missing(index )) {
750
751
index <- as_igraph_es(graph , index )
751
752
if (any(duplicated(index )) || any(is.na(index ))) {
752
- stop( " Invalid edges in index " )
753
+ cli :: cli_abort( " {.arg index} contains duplicated edges or NAs. " )
753
754
}
754
755
}
755
756
@@ -855,7 +856,7 @@ delete_graph_attr <- function(graph, name) {
855
856
856
857
name <- as.character(name )
857
858
if (! name %in% graph_attr_names(graph )) {
858
- stop (" No such graph attribute: " , name )
859
+ cli :: cli_abort (" No graph attribute {.arg { name}} found. " )
859
860
}
860
861
861
862
gattr <- .Call(R_igraph_mybracket2 , graph , igraph_t_idx_attr , igraph_attr_idx_graph )
@@ -884,7 +885,7 @@ delete_vertex_attr <- function(graph, name) {
884
885
885
886
name <- as.character(name )
886
887
if (! name %in% vertex_attr_names(graph )) {
887
- stop (" No such vertex attribute: " , name )
888
+ cli :: cli_abort (" No vertex attribute {.arg { name}} found. " )
888
889
}
889
890
890
891
vattr <- .Call(R_igraph_mybracket2 , graph , igraph_t_idx_attr , igraph_attr_idx_vertex )
@@ -913,7 +914,7 @@ delete_edge_attr <- function(graph, name) {
913
914
914
915
name <- as.character(name )
915
916
if (! name %in% edge_attr_names(graph )) {
916
- stop (" No such edge attribute: " , name )
917
+ cli :: cli_abort (" No edge attribute {.arg { name}} found. " )
917
918
}
918
919
919
920
eattr <- .Call(R_igraph_mybracket2 , graph , igraph_t_idx_attr , igraph_attr_idx_edge )
@@ -1020,7 +1021,7 @@ igraph.i.attribute.combination <- function(comb) {
1020
1021
if (any(! sapply(comb , function (x ) {
1021
1022
is.function(x ) || (is.character(x ) && length(x ) == 1 )
1022
1023
}))) {
1023
- stop (" Attribute combination element must be a function or character scalar" )
1024
+ cli :: cli_abort (" Attribute combination element must be a function or character scalar. " )
1024
1025
}
1025
1026
if (is.null(names(comb ))) {
1026
1027
names(comb ) <- rep(" " , length(comb ))
@@ -1041,7 +1042,7 @@ igraph.i.attribute.combination <- function(comb) {
1041
1042
)
1042
1043
x <- pmatch(tolower(x ), known [, 1 ])
1043
1044
if (is.na(x )) {
1044
- stop (" Unknown/unambigous attribute combination specification" )
1045
+ cli :: cli_abort (" Unknown/unambigous attribute combination specification. " )
1045
1046
}
1046
1047
known [, 2 ][x ]
1047
1048
}
@@ -1185,17 +1186,15 @@ NULL
1185
1186
}
1186
1187
1187
1188
assert_named_list <- function (value ) {
1188
- error_msg <- " {.arg value} must be a named list with unique names"
1189
-
1190
1189
if (! is.list(value )) {
1191
- rlang :: abort( error_msg )
1190
+ cli :: cli_abort( " {.arg value} must be a named list with unique names " )
1192
1191
}
1193
1192
1194
1193
if (length(value ) == 0 ) {
1195
1194
return ()
1196
1195
}
1197
1196
1198
1197
if (! rlang :: is_named(value ) || anyDuplicated(names(value )) > 0 ) {
1199
- rlang :: abort( error_msg )
1198
+ cli :: cli_abort( " {.arg value} must be a named list with unique names " )
1200
1199
}
1201
1200
}
0 commit comments