Skip to content

Commit

Permalink
Rename the ergm_Init_*() calls using rlang names to their base names,…
Browse files Browse the repository at this point in the history
… and remove redundant paste() and paste0() calls.
  • Loading branch information
krivit committed Oct 7, 2024
1 parent ba19c6c commit 9312e2f
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 98 deletions.
6 changes: 3 additions & 3 deletions R/InitErgmConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ InitErgmConstraint.bd<-function(nw, arglist, ...){
defaultvalues = list(NULL, NA_integer_, NA_integer_, NA_integer_, NA_integer_),
required = c(FALSE, FALSE, FALSE, FALSE, FALSE))

if(!is.directed(nw) && (!all(is.na(a$minin)) || !all(is.na(a$maxin)))) ergm_Init_abort(sQuote("minin"), " and ", sQuote("maxin"), " cannot be used with undirected networks.")
if(!is.directed(nw) && (!all(is.na(a$minin)) || !all(is.na(a$maxin)))) ergm_Init_stop(sQuote("minin"), " and ", sQuote("maxin"), " cannot be used with undirected networks.")

if(all(is.na(a$minout)) && all(is.na(a$minin))) {
constrain <- c("bd","bdmax")
Expand Down Expand Up @@ -614,12 +614,12 @@ InitErgmConstraint.Dyads<-function(nw, arglist, ...){
fix <- a$fix; vary <- a$vary

if(is.null(fix) & is.null(vary))
ergm_Init_abort(paste("Dyads constraint takes at least one argument, either",sQuote("fix"),"or",sQuote("vary"),"or both."))
ergm_Init_stop("Dyads constraint takes at least one argument, either ",sQuote("fix")," or ",sQuote("vary")," or both.")

for(f in c(fix, vary)){
f[[3]] <- f[[2]]
f[[2]] <- nw
if(!is.dyad.independent(f)) ergm_Init_abort(paste("Terms passed to the Dyads constraint must be dyad-independent."))
if(!is.dyad.independent(f)) ergm_Init_stop("Terms passed to the Dyads constraint must be dyad-independent.")
}

list(
Expand Down
2 changes: 1 addition & 1 deletion R/InitErgmConstraint.hints.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ InitErgmConstraint.strat <- function(nw, arglist, ...) {
pmat <- NVL(pmat, matrix(1, nrow = length(strat_row_levels), ncol = length(strat_col_levels)))

if(NROW(pmat) != length(strat_row_levels) || NCOL(pmat) != length(strat_col_levels)) {
ergm_Init_abort(sQuote("pmat"), " does not have the correct dimensions for ", sQuote("attr"), ".")
ergm_Init_stop(sQuote("pmat"), " does not have the correct dimensions for ", sQuote("attr"), ".")
}

if(!is.bipartite(nw) && !is.directed(nw)) {
Expand Down
14 changes: 7 additions & 7 deletions R/InitErgmProposal.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ NULL
InitErgmProposal.CondOutDegree <- function(arguments, nw) {
proposal <- list(name = "CondOutDegree", inputs=NULL)
if (!is.directed(nw)) # Really, this should never trigger, since the InitErgmConstraint function should check.
ergm_Init_abort("The CondOutDegree proposal function does not work with an",
ergm_Init_stop("The CondOutDegree proposal function does not work with an",
"undirected network.")
proposal
}
Expand All @@ -247,7 +247,7 @@ NULL
InitErgmProposal.CondInDegree <- function(arguments, nw) {
proposal <- list(name = "CondInDegree", inputs=NULL)
if (!is.directed(nw)) # Really, this should never trigger, since the InitErgmConstraint function should check.
ergm_Init_abort("The CondInDegree proposal function does not work with an",
ergm_Init_stop("The CondInDegree proposal function does not work with an",
"undirected network.")
proposal
}
Expand All @@ -263,7 +263,7 @@ NULL
InitErgmProposal.CondB1Degree <- function(arguments, nw) {
proposal <- list(name = "CondB1Degree", inputs=NULL)
if (!is.bipartite(nw)) # Really, this should never trigger, since the InitErgmConstraint function should check.
ergm_Init_abort("The CondB1Degree proposal function does not work with a non-bipartite network.")
ergm_Init_stop("The CondB1Degree proposal function does not work with a non-bipartite network.")

proposal
}
Expand All @@ -279,7 +279,7 @@ NULL
InitErgmProposal.CondB2Degree <- function(arguments, nw) {
proposal <- list(name = "CondB2Degree", inputs=NULL)
if (!is.bipartite(nw)) # Really, this should never trigger, since the InitErgmConstraint function should check.
ergm_Init_abort("The CondB2Degree proposal function does not work with a non-bipartite network.")
ergm_Init_stop("The CondB2Degree proposal function does not work with a non-bipartite network.")
proposal
}

Expand All @@ -294,7 +294,7 @@ NULL
InitErgmProposal.CondDegreeDist <- function(arguments, nw) {
proposal <- list(name = "CondDegreeDist", inputs=NULL)
if (is.directed(nw)) {
ergm_Init_warn("Using the 'degreedist' constraint with a directed network ",
ergm_Init_warning("Using the 'degreedist' constraint with a directed network ",
"is currently perilous. We recommend that you use 'outdegree' or ",
"'idegrees' instead.")
}
Expand All @@ -314,7 +314,7 @@ NULL
InitErgmProposal.CondInDegreeDist <- function(arguments, nw) {
proposal <- list(name = "CondInDegreeDist", inputs=NULL)
if (!is.directed(nw)) {
ergm_Init_warn("Using the 'idegreedist' constraint with an undirected network ",
ergm_Init_warning("Using the 'idegreedist' constraint with an undirected network ",
"is currently perilous. We recommend that you use 'degreedist' ",
" instead.")
}
Expand All @@ -334,7 +334,7 @@ NULL
InitErgmProposal.CondOutDegreeDist <- function(arguments, nw) {
proposal <- list(name = "CondOutDegreeDist", inputs=NULL)
if (!is.directed(nw)) {
ergm_Init_warn("Using the 'odegreedist' constraint with an undirected network n",
ergm_Init_warning("Using the 'odegreedist' constraint with an undirected network n",
"is currently perilous. We recommend that you use 'degreedist' ",
" instead.")
}
Expand Down
2 changes: 1 addition & 1 deletion R/InitErgmReference.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ InitErgmReference.DiscUnif <- function(nw, arglist, a, b, ...){
vartypes = c("numeric", "numeric"),
defaultvalues = list(NULL, NULL),
required = c(TRUE, TRUE))
if(a$a!=round(a$a) || a$b != round(a$b)) ergm_Init_abort(paste("arguments ", sQuote("a"), "and", sQuote("b"), "must be integers"))
if(a$a!=round(a$a) || a$b != round(a$b)) ergm_Init_stop("arguments ", sQuote("a"), " and ", sQuote("b"), "must be integers")
list(name="DiscUnif", arguments=list(a=a$a, b=a$b), init_methods=c("CD","zeros"))
}
58 changes: 29 additions & 29 deletions R/InitErgmTerm.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ ergm_edgecov_args <- function(name, nw, a){
# Process the arguments
if(is.network(a$x)){
if(!is.null(a$attrname) && !a$attrname %in% list.edge.attributes(a$x))
ergm_Init_abort("Specified network ", sQuote(deparse1(attr(a,"exprs")$x)), " does not have an edge attribute ", sQuote(a$attrname), ".")
ergm_Init_stop("Specified network ", sQuote(deparse1(attr(a,"exprs")$x)), " does not have an edge attribute ", sQuote(a$attrname), ".")
xm <- as.matrix(a$x, matrix.type="adjacency", a$attrname)
}else if(is.character(a$x)){
xm <- get.network.attribute(nw, a$x)
if(is.null(xm) || !(is.matrix(xm) || is.network(xm))) ergm_Init_abort("There is no network attribute named ", sQuote(a$x), " or it is not a matrix or a network.")
if(is.null(xm) || !(is.matrix(xm) || is.network(xm))) ergm_Init_stop("There is no network attribute named ", sQuote(a$x), " or it is not a matrix or a network.")
if(is.network(xm)){
if(!is.null(a$attrname) && !a$attrname %in% list.edge.attributes(xm)) ergm_Init_abort("Network at attribute named ", sQuote(a$x), " does not have an edge attribute ", sQuote(a$attrname), ".")
if(!is.null(a$attrname) && !a$attrname %in% list.edge.attributes(xm)) ergm_Init_stop("Network at attribute named ", sQuote(a$x), " does not have an edge attribute ", sQuote(a$attrname), ".")
xm <- as.matrix(xm, matrix.type="adjacency", attrname=a$attrname)
name <- paste(name, a$x, sep=".")
}
Expand Down Expand Up @@ -232,15 +232,15 @@ LEVELS_BASE1 <- NULL

decay_vs_fixed <- function(a, name, no_curved_attrarg=TRUE){
if(!is.null(a$alpha)){
ergm_Init_abort("For consistency with ", sQuote("gw*degree"), " terms, in all ", sQuote("gw*sp"), " and ", sQuote("dgw*sp"), " terms the argument ", sQuote("alpha"), " has been renamed to " ,sQuote("decay"), ".")
ergm_Init_stop("For consistency with ", sQuote("gw*degree"), " terms, in all ", sQuote("gw*sp"), " and ", sQuote("dgw*sp"), " terms the argument ", sQuote("alpha"), " has been renamed to " ,sQuote("decay"), ".")
}

if(a$fixed){
if(!attr(a, "missing")["cutoff"]) ergm_Init_warn("When ", sQuote('fixed=TRUE'), " parameter ", sQuote('cutoff'), " has no effect.")
if(is.null(a$decay)) ergm_Init_abort("Using ", sQuote('fixed=TRUE'), " requires a decay parameter ", sQuote('decay'), ".")
if(!attr(a, "missing")["cutoff"]) ergm_Init_warning("When ", sQuote('fixed=TRUE'), " parameter ", sQuote('cutoff'), " has no effect.")
if(is.null(a$decay)) ergm_Init_stop("Using ", sQuote('fixed=TRUE'), " requires a decay parameter ", sQuote('decay'), ".")
}else{
if(!is.null(a$decay)) ergm_Init_warn("When ", sQuote('fixed=FALSE'), " parameter ", sQuote('decay')," has no effect. To specify an initial value for ", sQuote('decay'),", use the ", sQuote('control.ergm()'), " parameter ", sQuote('init='), ".")
if(no_curved_attrarg && !is.null(NVL(a$attrname,a$attr))) ergm_Init_abort("Using ", sQuote('fixed=FALSE'), " with an attribute is not implemented at this time. Use ", sQuote('fixed=TRUE'), ".")
if(!is.null(a$decay)) ergm_Init_warning("When ", sQuote('fixed=FALSE'), " parameter ", sQuote('decay')," has no effect. To specify an initial value for ", sQuote('decay'),", use the ", sQuote('control.ergm()'), " parameter ", sQuote('init='), ".")
if(no_curved_attrarg && !is.null(NVL(a$attrname,a$attr))) ergm_Init_stop("Using ", sQuote('fixed=FALSE'), " with an attribute is not implemented at this time. Use ", sQuote('fixed=TRUE'), ".")
}
}

Expand All @@ -267,10 +267,10 @@ decay_vs_fixed <- function(a, name, no_curved_attrarg=TRUE){

if(length(to)==1 && length(from)>1) to <- rep(to, length(from))
else if(length(from)==1 && length(to)>1) from <- rep(from, length(to))
else if(length(from)!=length(to)) ergm_Init_abort("The arguments of term ", sQuote(termname), " must have arguments either of the same length, or one of them must have length 1.")
else if(length(from)!=length(to)) ergm_Init_stop("The arguments of term ", sQuote(termname), " must have arguments either of the same length, or one of them must have length 1.")

to <- ifelse(to==Inf, pmax(from, network.size(nw)) + 1, to)
if(any(from>=to)) ergm_Init_abort("Term ", sQuote(termname), " must have ", sQuote("from"), "<", sQuote("to"), ".")
if(any(from>=to)) ergm_Init_stop("Term ", sQuote(termname), " must have ", sQuote("from"), "<", sQuote("to"), ".")

emptynwstats<-NULL
if(!is.null(byarg)) {
Expand Down Expand Up @@ -771,7 +771,7 @@ InitErgmTerm.attrcov <- function (nw, arglist, ..., version=packageVersion("ergm
nodecov <- c(match(b1nodecov, b1levels), match(b2nodecov, b2levels))

if(NROW(a$mat) != length(b1levels) || NCOL(a$mat) != length(b2levels)) {
ergm_Init_abort("mat has wrong dimensions for attr")
ergm_Init_stop("mat has wrong dimensions for attr")
}
} else {
nodecov <- ergm_get_vattr(a$attr, nw)
Expand All @@ -781,7 +781,7 @@ InitErgmTerm.attrcov <- function (nw, arglist, ..., version=packageVersion("ergm
nodecov <- match(nodecov, levels)

if(NROW(a$mat) != length(levels) || NCOL(a$mat) != length(levels)) {
ergm_Init_abort("mat has wrong dimensions for attr")
ergm_Init_stop("mat has wrong dimensions for attr")
}
}

Expand Down Expand Up @@ -1266,7 +1266,7 @@ InitErgmTerm.b1starmix <- function(nw, arglist, ..., version=packageVersion("erg
# Recode to numeric
nodecov <- match(nodecov,u,nomatch=length(u)+1)
if (length(a$k) > 1)
{ ergm_Init_abort("Only a single scalar k may be used with each b1starmix term") }
{ ergm_Init_stop("Only a single scalar k may be used with each b1starmix term") }
b1namescov <- sort(unique(nodecov[1:nb1]))
b2namescov <- sort(unique(nodecov[(1+nb1):network.size(nw)]))
b1nodecov <- match(nodecov[1:nb1],b1namescov)
Expand Down Expand Up @@ -1845,7 +1845,7 @@ InitErgmTerm.b2starmix <- function(nw, arglist, ..., version=packageVersion("erg
# Recode to numeric
nodecov <- match(nodecov,u,nomatch=length(u)+1)
if (length(a$k) > 1)
{ ergm_Init_abort("Only a single scalar k may be used with each b2starmix term") }
{ ergm_Init_stop("Only a single scalar k may be used with each b2starmix term") }
b1namescov <- sort(unique(nodecov[1:nb1]))
b2namescov <- sort(unique(nodecov[(1+nb1):network.size(nw)]))
b1nodecov <- match(nodecov[1:nb1],b1namescov)
Expand Down Expand Up @@ -2176,22 +2176,22 @@ InitErgmTerm.cycle <- function(nw, arglist, ...) {
required = c(TRUE,FALSE))
### Process the arguments
if(any(a$k > network.size(nw))) {
ergm_Init_warn("cycles of length greater than the network size cannot exist and their statistics will be omitted")
ergm_Init_warning("cycles of length greater than the network size cannot exist and their statistics will be omitted")
a$k <- a$k[a$k <= network.size(nw)]
}

if(!is.directed(nw) && any(a$k < 3)) {
ergm_Init_warn("cycles of length less than 3 cannot exist in an undirected network and their statistics will be omitted")
ergm_Init_warning("cycles of length less than 3 cannot exist in an undirected network and their statistics will be omitted")
a$k <- a$k[a$k >= 3]
}

if(any(a$k < 2)) {
ergm_Init_warn("cycles of length less than 2 cannot exist and their statistics will be omitted")
ergm_Init_warning("cycles of length less than 2 cannot exist and their statistics will be omitted")
a$k <- a$k[a$k >= 2]
}

if(is.directed(nw) && a$semi && any(a$k == 2)) {
ergm_Init_warn("semicycles of length 2 are not currently supported and their statistics will be omitted")
ergm_Init_warning("semicycles of length 2 are not currently supported and their statistics will be omitted")
a$k <- a$k[a$k >= 3]
}

Expand Down Expand Up @@ -2487,10 +2487,10 @@ InitErgmTerm.diff <- function(nw, arglist, ..., version=packageVersion("ergm"))
sign.action <- match.arg(tolower(a$sign.action), SIGN.ACTIONS)
sign.code <- match(sign.action, SIGN.ACTIONS)

if(sign.action!="abs" && !is.directed(nw) && !is.bipartite(nw)) ergm_Init_inform(paste("Note that behavior of term diff() on unipartite, undirected networks may be unexpected. See", sQuote("ergmTerm?diff"),"for more information."))
if(sign.action!="abs" && !is.directed(nw) && !is.bipartite(nw)) ergm_Init_message("Note that behavior of term ", sQuote("diff()"), " on unipartite, undirected networks may be unexpected. See", sQuote("ergmTerm?diff"),"for more information.")

# 1 and 4 are sign codes that allow negative differences.
if(sign.code %in% c(1, 4) && a$pow!=round(a$pow)) ergm_Init_abort("In term diff(attr, pow, sign=",a$sign,"), pow must be an integer.")
if(sign.code %in% c(1, 4) && a$pow!=round(a$pow)) ergm_Init_stop("In term diff(attr, pow, sign=",a$sign,"), pow must be an integer.")

### Construct the list to return
list(name="diff", #name: required
Expand Down Expand Up @@ -2542,7 +2542,7 @@ InitErgmTerm.dyadcov<-function (nw, arglist, ...) {
# DH: Since nw is directed, why are we testing for symmetry here?
if (any(xm[upper.tri(xm)]!=t(xm)[upper.tri(xm)])){
xm[lower.tri(xm)]<-t(xm)[lower.tri(xm)]
ergm_Init_warn("asymmetric covariate in dyadcov; using upper triangle only")
ergm_Init_warning("asymmetric covariate in dyadcov; using upper triangle only")
}
coef.names <- paste(cn, c("mutual","utri","ltri"),sep=".")
}else{
Expand Down Expand Up @@ -2932,7 +2932,7 @@ InitErgmTerm.hamming<-function (nw, arglist, ...) {
covm<-as.matrix(a$cov)
}
if (is.null(covm) || !is.matrix(covm) || NCOL(covm)!=3){
ergm_Init_abort("Improper dyadic covariate passed to hamming()")
ergm_Init_stop("Improper dyadic covariate passed to hamming()")
}
emptynwstats <- sum(apply(xm, 1, function(a,b) sum(b[(a[1]==b[,1] & a[2]==b[,2]),3]), covm))
if (is.null(a$defaultweight))
Expand Down Expand Up @@ -2990,7 +2990,7 @@ InitErgmTerm.hammingmix<-function (nw, arglist, ..., version=packageVersion("erg
x<-a$x

if (a$contrast) {
ergm_Init_abort("The 'contrast' argument of the hammingmix term is deprecated. Use 'levels2' instead")
ergm_Init_stop("The 'contrast' argument of the hammingmix term is deprecated. Use 'levels2' instead")
}
if(is.network(x)){
xm<-as.edgelist(x)
Expand All @@ -3003,7 +3003,7 @@ InitErgmTerm.hammingmix<-function (nw, arglist, ..., version=packageVersion("erg
x<-paste(quote(x))
}
if (is.null(xm) || ncol(xm)!=2){
ergm_Init_abort("hammingmix() requires an edgelist")
ergm_Init_stop("hammingmix() requires an edgelist")
}

nodecov <- ergm_get_vattr(attrarg, nw)
Expand Down Expand Up @@ -3435,7 +3435,7 @@ InitErgmTerm.localtriangle<-function (nw, arglist, ...) {
else
xm<-as.matrix(x)
if(!isSymmetric(xm)){
ergm_Init_warn("localtriangle requires an undirected neighborhood. Using only mutual ties.")
ergm_Init_warning("localtriangle requires an undirected neighborhood. Using only mutual ties.")
xm <- pmin(xm[],(t(xm))[])
}
if(!is.null(attrname))
Expand Down Expand Up @@ -3722,7 +3722,7 @@ InitErgmTerm.mutual<-function (nw, arglist, ..., version=packageVersion("ergm"))
if (!is.null(a$same)) {
attrarg <- a$same
if (!is.null(a$by))
ergm_Init_warn("Ignoring 'by' argument to mutual because 'same' exists")
ergm_Init_warning("Ignoring 'by' argument to mutual because 'same' exists")
}else{
attrarg <- a$by
}
Expand Down Expand Up @@ -4219,7 +4219,7 @@ InitErgmTerm.nodemix<-function (nw, arglist, ..., version=packageVersion("ergm")

### Process the arguments
if (is.bipartite(nw) && is.directed(nw)) {
ergm_Init_abort("Directed bipartite networks are not currently possible")
ergm_Init_stop("Directed bipartite networks are not currently possible")
}

nodecov <- ergm_get_vattr(attrarg, nw)
Expand Down Expand Up @@ -4911,7 +4911,7 @@ InitErgmTerm.smalldiff<-function (nw, arglist, ..., version=packageVersion("ergm

cutoff <- a$cutoff
if (length(cutoff)>1)
ergm_Init_abort("cutoff for smalldiff() must be a scalar.")
ergm_Init_stop("cutoff for smalldiff() must be a scalar.")

nodecov <- ergm_get_vattr(attrarg, nw, accept="numeric")
attrname <- attr(nodecov, "name")
Expand Down Expand Up @@ -5086,7 +5086,7 @@ InitErgmTerm.threetrail <- function(nw, arglist, ..., version=packageVersion("er
#' @usage
#' # binary: threepath(keep=NULL, levels=NULL)
InitErgmTerm.threepath <- function(nw, arglist, ..., version=packageVersion("ergm")) {
ergm_Init_warn(paste("This term is inaccurately named and actually refers to a '3-trail' in that it counts repeated vertices: i-j-k-i is a 3-trail but not a 3-path. See", sQuote("ergmTerm?treepath"), "help for more information. This name has been deprecated and will be removed in a future version: if a 3-trail is what you want, use the term 'threetrail'."))
ergm_Init_warning("This term is inaccurately named and actually refers to a '3-trail' in that it counts repeated vertices: i-j-k-i is a 3-trail but not a 3-path. See ", sQuote("ergmTerm?treepath"), " help for more information. This name has been deprecated and will be removed in a future version: if a 3-trail is what you want, use the term ", sQuote("threetrail"), ".")

f <- InitErgmTerm.threetrail
f(nw, arglist, ..., version=version)
Expand Down
Loading

0 comments on commit 9312e2f

Please sign in to comment.