[statnet_help] Issue with delete.vertices and
network.extract.with.lasttoggle
Steven M. Goodreau via statnet_help
statnet_help at u.washington.edu
Mon Sep 15 16:26:00 PDT 2025
Hi Lin,
A few of us have taken a look at this and still don't have a clear
answer on the behavior or your potential fix. Carter seems confident
it's not an issue in network but something upstream that calls it. I'm
not able to reproduce it.
Are you able to create a minimum reproducible example? Then we can dive
in a lot more deeply.
Thanks,
Steve
On 8/25/2025 3:05 PM, Zhu, Lin via statnet_help wrote:
>
> 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
>
>
> _______________________________________________
> statnet_help mailing list
> statnet_help at u.washington.edu
> http://mailman23.u.washington.edu/mailman/listinfo/statnet_help
--
******************************************************************************************************
Steven M. Goodreau / Professor, Dept. of Anthropology / Adjunct Prof., Dept. of Epidemiology
(STEE-vun GOOD-roe) / he-him /https://faculty.washington.edu/goodreau
Physical address: Denny Hall M236; Mailing address: Campus Box 353100 / 4216 Memorial Way NE
University of Washington / Seattle WA 98195 / dzidzəlalič, x̌ʷəlč
******************************************************************************************************
For there is always light, if only we’re brave enough to see it. If only we’re brave enough to be it.
- Amanda Gorman, The Hill We Climb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250915/d45765a1/attachment.html>
More information about the statnet_help
mailing list