thomasp85 / tidygraph

A tidy API for graph manipulation
https://tidygraph.data-imaginist.com
Other
547 stars 62 forks source link

Invalid (non-finite or NaN) vertex #164

Open nick-youngblut opened 2 years ago

nick-youngblut commented 2 years ago

Reprex of error:

Use the email_nodes.csv and email_edges.csv tables from https://michaelgastner.com/DAVisR2021/chap-tidygraph.html. If running the code shown in the ebook:

email_directed_netw <-
  tbl_graph(nodes = email_nodes, edges = email_edges)

...then the command run successfully.

However, if one uses:

email_directed_netw <-
  tbl_graph(nodes = head(email_nodes), edges = head(email_edges))

...then the error is:

Error in (function (edges, n = max(edges), directed = TRUE)  : 
  At core/constructors/basic_constructors.c:72 : Invalid (non-finite or NaN) vertex index when creating graph. Invalid value

If using head() results in an incomplete network, and that is the issue, then a better error message pointing to the problem would be very helpful.

sessionInfo

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] networkD3_0.4     tidygraph_1.2.2   tidytable_0.9.0   data.table_1.14.2
[5] RPostgres_1.4.4   DBI_1.1.3        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9        pillar_1.8.1      compiler_4.2.1    tools_4.2.1      
 [5] digest_0.6.29     bit_4.0.4         lubridate_1.8.0   jsonlite_1.8.2   
 [9] lifecycle_1.0.3   tibble_3.1.8      pkgconfig_2.0.3   rlang_1.0.6      
[13] igraph_1.3.5      cli_3.4.1         yaml_2.3.5        fastmap_1.1.0    
[17] withr_2.5.0       dplyr_1.0.10      generics_0.1.3    vctrs_0.4.2      
[21] htmlwidgets_1.5.4 hms_1.1.2         bit64_4.0.5       tidyselect_1.2.0 
[25] glue_1.6.2        R6_2.5.1          fansi_1.0.3       tidyr_1.2.1      
[29] purrr_0.3.5       blob_1.2.3        magrittr_2.0.3    ellipsis_0.3.2   
[33] htmltools_0.5.3   renv_0.15.5       utf8_1.2.2 
thomasp85 commented 1 year ago

I know this is late I'm coming to this issue. The link above no longer works. If you are interested can you reproduce the issue with available data?

I'm quite sure the issue is that you are creating an invalid graph representation by just taking the top rows of the two tables but I agree a better error would be beneficial