Fix MCMC.maxchanges = Inf integer coercion warning in tergm#956
Merged
Fix MCMC.maxchanges = Inf integer coercion warning in tergm#956
Conversation
Replace MCMC.maxchanges = Inf with .Machine$integer.max in netdx(),
control.net(), and netest() defaults.
When Inf is passed as MCMC.maxchanges, it flows to
tergm::tergm_MCMC_slave() which calls as.integer(maxchanges) before
the .Call to MCMCDyn_wrapper. as.integer(Inf) produces NA with a
warning: "NAs introduced by coercion to integer range".
Note that tergm wraps the analogous MCMC.maxedges parameter with
deInf(maxedges, "maxint") before as.integer(), which correctly
converts Inf to .Machine$integer.max. The same deInf() wrapper is
missing for MCMC.maxchanges in tergm_MCMC_slave(). This is arguably
a bug in tergm -- see the relevant code:
tergm::tergm_MCMC_slave:
maxedges <- NVL(control$MCMC.maxedges, Inf)
maxchanges <- control$MCMC.maxchanges
z <- .Call("MCMCDyn_wrapper", ...,
as.integer(deInf(maxedges, "maxint")), # <- wrapped
as.integer(maxchanges), # <- NOT wrapped
...)
This warning surfaced after ergm 4.12.0 (2026-02-17) triggered a
recompilation of the tergm binary, likely changing how the C code
uses the maxchanges argument.
Using .Machine$integer.max (2,147,483,647) is functionally equivalent
to Inf for this purpose -- it effectively removes the limit on MCMC
changes per step -- while avoiding the integer coercion warning.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
@AdrienLeGuillou : could you review this before I merge it in? Although you made the Inf change way back in 2024, I think some new warnings were triggered by recent updates to |
AdrienLeGuillou
approved these changes
Feb 28, 2026
Member
AdrienLeGuillou
left a comment
There was a problem hiding this comment.
I agree with your assessment.
I will check next week with HIV-p if things need to be updated as well there for this and the deprecated ERGM term (similar to #953)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace MCMC.maxchanges = Inf with .Machine$integer.max in netdx(), control.net(), and netest() defaults.
When Inf is passed as MCMC.maxchanges, it flows to tergm::tergm_MCMC_slave() which calls as.integer(maxchanges) before the .Call to MCMCDyn_wrapper. as.integer(Inf) produces NA with a warning: "NAs introduced by coercion to integer range".
Note that tergm wraps the analogous MCMC.maxedges parameter with deInf(maxedges, "maxint") before as.integer(), which correctly converts Inf to .Machine$integer.max. The same deInf() wrapper is missing for MCMC.maxchanges in tergm_MCMC_slave(). This is arguably a bug in tergm -- see the relevant code:
tergm::tergm_MCMC_slave:
maxedges <- NVL(control$MCMC.maxedges, Inf)
maxchanges <- control$MCMC.maxchanges
z <- .Call("MCMCDyn_wrapper", ...,
as.integer(deInf(maxedges, "maxint")), # <- wrapped
as.integer(maxchanges), # <- NOT wrapped
...)
This warning surfaced after ergm 4.12.0 (2026-02-17) triggered a recompilation of the tergm binary, likely changing how the C code uses the maxchanges argument.
Using .Machine$integer.max (2,147,483,647) is functionally equivalent to Inf for this purpose -- it effectively removes the limit on MCMC changes per step -- while avoiding the integer coercion warning.