# Abort R session when calculating betweenness/closeness centrality

**URL:** <https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695>\
**Category:** Usage\
**Tags:** R\
**Created:** [30 March 2021 09:21 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695 "2021-03-30T09:21:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morgan\_Jontel](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/morgan_jontel/32/470_2.png) [@Morgan\_Jontel](https://igraph.discourse.group/u/Morgan_Jontel)\
**Post date:** [30 March 2021 09:21 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/1 "2021-03-30T09:21:34Z")

</div>

Hi, when I try to run the code to calculate betweenness centrality for a directed, weighted network (see below), my R session aborts with the error message “at 0x000000000 referenced memory at 0x00000000 the memory could not be written…” I think this is a glitch with igraph, not a code error, but not sure. Thank you for the help!

```auto
b1<-read.csv("AsMatrix_SP20.csv", header=TRUE, row.names=1)
mb1<-as.matrix(b1)
netas <- graph.adjacency(mb1, mode="directed", weighted=TRUE, diag=FALSE)
inds<-igraph::betweenness(netas, directed = TRUE, normalized = FALSE)

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [30 March 2021 09:53 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/2 "2021-03-30T09:53:31Z")

</div>

Please show a complete reproducible example (including the offending data file).

If there are `NA` or `NaN` values in your data, be sure to get rid of them. igraph cannot usually handle them.

---

<div class="post-metadata">

**Author:** ![Morgan\_Jontel](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/morgan_jontel/32/470_2.png) [@Morgan\_Jontel](https://igraph.discourse.group/u/Morgan_Jontel)\
**Post date:** [30 March 2021 12:39 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/3 "2021-03-30T12:39:58Z")

</div>

I have attached the corresponding data file. Thank you for your help!

[AsMatrix\_SP20.csv](https://igraph.discourse.group/uploads/short-url/dMSllYub5nAhrccfEK8E9ckU13H.csv) (10.2 KB)

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [30 March 2021 14:37 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/4 "2021-03-30T14:37:22Z")

</div>

Your data indeed includes an `NA` as @szhorvat already indicated. Please remove the edge with the `NA` weight, or assign it an explicit weight, whatever would make most sense for your application.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [31 March 2021 07:24 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/5 "2021-03-31T07:24:20Z")

</div>

It may be a bit confusing if you look at the CSV with a text editor, as the “NA” is a literally a missing item. It is at position SEL, CLI.

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [31 March 2021 08:01 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/6 "2021-03-31T08:01:03Z")

</div>

Perhaps in addition, `igraph` should never crash your R session, and we are fixing this bug, but it is not yet available in the `igraph` R package.

---

<div class="post-metadata">

**Author:** ![econstatmath](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/econstatmath/32/490_2.png) [@econstatmath](https://igraph.discourse.group/u/econstatmath)\
**Post date:** [2 May 2021 12:19 UTC](https://igraph.discourse.group/t/abort-r-session-when-calculating-betweenness-closeness-centrality/695/7 "2021-05-02T12:19:06Z")

</div>

Thank you so much! Now I can understand the reason behind the “fatal error” for computing the weighted edge betweenness. After cleaning the weighted edge list, now I can run the function of “edge betweenness” without any error. This help means a lot! All the best!
