From 8a55490f455dbfe8c59ab3427e0a30af2c74b7f6 Mon Sep 17 00:00:00 2001 From: Mike Du <58779940+ilovemane@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:53:31 +0100 Subject: [PATCH] fixes --- R/attr.R | 10 ++++++---- tests/testthat/test-attr.R | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/attr.R b/R/attr.R index 658b03925..d605ed754 100644 --- a/R/attr.R +++ b/R/attr.R @@ -110,13 +110,15 @@ detect_void_name <- function(x) { is_dictionaryish <- function(x) { # 2022-01: Used in many packages. Don't deprecate without a # replacement. - if (!length(x)) { - return(!is.null(x)) - } - if (is.null(names(x))) { + if (is.null(x)) { TRUE } else { + if (!length(x)) { + return(!is.null(x)) + } + is_named(x) && !any(duplicated(names(x))) + } } diff --git a/tests/testthat/test-attr.R b/tests/testthat/test-attr.R index 48a318abd..cd5496e31 100644 --- a/tests/testthat/test-attr.R +++ b/tests/testthat/test-attr.R @@ -187,7 +187,7 @@ test_that("zap_srcref() works on calls", { expect_true("srcref" %in% names(attributes(call))) }) -test_that("is_dictionaryish return true if names(x) is NULL", { - x <- "x" - expect_true(is_dictionaryish(x)) +test_that("is_dictionaryish return true if is NULL", { + + expect_true(is_dictionaryish(NULL)) })