[statnet_help] Issue with delete.vertices and network.extract.with.lasttoggle

Zhu, Lin via statnet_help statnet_help at u.washington.edu
Mon Aug 25 15:05:40 PDT 2025


Dear Statnet community,

Hope everyone is doing great!

I’ve been using Statnet for a few years, and I’m looking to see if anyone had this same error and if it can be fixed. So in a summary I have had this error <simpleError in lttails[w2] <- ltheads[w2]: NAs are not allowed in subscripted assignments> from the network.extract.with.lasttoggle function since I updated ERGM from 3.11 to 4.9.0, and TERGM from 3.7.0 to 4.2.2.

I then found that it’s associated with delete.vertices, which I use to remove nodes when they die. So only after using this function, simulating nwd again (S3 used is simulate.networkDynamic) will throw the error. What happened is that, after deleting the nodes, the ties attached to them became NULL in mel. And the network.extract.with.lasttoggle function has the following code to record edge heads and tails which are further processed to construct lttails and ltheads (mentioned in the error message):
valid_eids <- valid.eids(nwd)
tails <- unlist(lapply(nwd$mel, "[[", "outl"))[valid_eids]
heads <- unlist(lapply(nwd$mel, "[[", "inl"))[valid_eids]
The issue is, lapply(nwd$mel, "[[", "outl") outputs all vids from mel, including the NULLs. Then unlist(lapply(nwd$mel, "[[", "outl")) automatically removes the NULLs and ends up with a shorter vector, making the edges and indices not matching anymore. Then having the indices [valid_eids] after and outside of unlist will create NAs at the end of tails, with the number of NAs equal to the number of edges that were attached to the removed nodes (the NULL edges).

A simple fix I think is
tails <- unlist(lapply(nwd$mel, "[[", "outl")[valid_eids])
heads <- unlist(lapply(nwd$mel, "[[", "inl") [valid_eids])

However I tried different methods to replace the code, but it either doesn’t use my updated code, or R crashes if I edit the tergm namespace or Rprofile. Since this function is wrapped many layers under simulate, I didn’t find a better way to replace it.

So has anyone had the same issue? Does my debugging make sense? If it’s a common issue, would it be possible to update the function in the package from the statnet side so it won’t crash? Please feel free to reach out if you have any questions. Thank you so much for your help!

(A bit more context of the package updates: I used to use renv to lock the package versions (thanks to Steve’s suggestion) and had no issues. Recently I got a new Mac, which cannot install older R versions written with Rosetta, and renv failed to install the older packages because the newer R defaults to clang instead of gcc in many places, which caused a lot of installation errors. I tried to manually install the packages with no luck. I hence decided to update my statnet to the new versions.)

Best,
Lin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250825/26eccd0c/attachment.html>


More information about the statnet_help mailing list