Skip to content

Commit 340471b

Browse files
committed
Implemented a function hasAttr() analogous to hasName(); bumped the version to 4.14.
1 parent 7d4852c commit 340471b

5 files changed

Lines changed: 64 additions & 14 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: statnet.common
2-
Version: 4.13.0-509
3-
Date: 2025-12-16
2+
Version: 4.14.0-512
3+
Date: 2026-02-11
44
Title: Common R Scripts and Utilities Used by the Statnet Project Software
55
Authors@R: c(
66
person(c("Pavel", "N."), "Krivitsky", role=c("aut","cre"), email="pavel@statnet.org", comment=c(ORCID="0000-0002-9101-3362", affiliation="University of New South Wales")),
@@ -14,7 +14,7 @@ BugReports: https://github.com/statnet/statnet.common/issues
1414
License: GPL-3 + file LICENSE
1515
URL: https://statnet.org
1616
Roxygen: list(markdown = TRUE)
17-
RoxygenNote: 7.3.2.9000
17+
RoxygenNote: 7.3.3.9000
1818
Encoding: UTF-8
1919
Suggests: covr,
2020
roxygen2,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export(fixed.pval)
103103
export(forkTimeout)
104104
export(ginv_eigen)
105105
export(handle.controls)
106+
export(hasAttr)
106107
export(is.SPD)
107108
export(is.linwmatrix)
108109
export(is.logwmatrix)

R/misc.utilities.R

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,12 @@ simplify_simple <- function(x, toNA = c("null","empty","keep"), empty = c("keep"
10711071
else x
10721072
}
10731073

1074-
#' A wrapper for base::attr which defaults to exact matching.
1074+
#' A wrapper for [base::attr()] which defaults to exact matching.
10751075
#'
1076-
#' @param x,which,exact as in \code{base::attr}, but with \code{exact}
1077-
#' defaulting to \code{TRUE} in this implementation
1076+
#' @param x,which,exact as in [base::attr()], but with `exact`
1077+
#' defaulting to `TRUE` in this implementation
10781078
#'
1079-
#' @return as in \code{base::attr}
1079+
#' @return As [base::attr()].
10801080
#' @examples
10811081
#'
10821082
#' x <- list()
@@ -1088,9 +1088,28 @@ simplify_simple <- function(x, toNA = c("null","empty","keep"), empty = c("keep"
10881088
#'
10891089
#' base::attr(x, "n", exact = TRUE)
10901090
#' @export
1091-
attr <- function(x, which, exact = TRUE) {
1092-
base::attr(x, which, exact)
1093-
}
1091+
attr <- function(x, which, exact = TRUE) base::attr(x, which, exact)
1092+
1093+
#' Check if an object has an attribute with a specified name.
1094+
#'
1095+
#' Analogous function to [utils::hasName()] but for [attr()]
1096+
#' attributes.
1097+
#'
1098+
#' @param x Any object.
1099+
#'
1100+
#' @param name One or more character values to look for.
1101+
#'
1102+
#' @return A logical vector of the same length as `name`, containing
1103+
#' `TRUE` if `attr(x, name, exact = TRUE)` is not `NULL`.
1104+
#'
1105+
#' @seealso [hasName()]
1106+
#' @examples
1107+
#' x <- structure(list(), name = 10)
1108+
#'
1109+
#' stopifnot(hasAttr(x, c("n", "name")) == c(FALSE, TRUE))
1110+
#'
1111+
#' @export
1112+
hasAttr <- function(x, name) vapply(name, function(nm) !is.null(attr(x, nm)), FALSE)
10941113

10951114
#' An error handler for [rlang::check_dots_used()] that issues a
10961115
#' warning that only lists argument names.

man/attr.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hasAttr.Rd

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)