Skip to content

Conversation

@jdblischak
Copy link
Collaborator

I introduced {data.table} in PR #295 to increase the computational efficiency. Both {data.table} and {rlang} define the operator :=, which complicates the package NAMESPACE. Motivated by @nanxstats comment in #295 (review), I was able to simplify the NAMESPACE by removing the few uses of {rlang}

ab <- left_join(astring, table_b, by = byvar) %>%
select(-one_of(!!byvar)) %>%
dplyr::rename(!!aname := !!"_alab")

I didn't need to add any new tests because the output table returned by this function is already well-tested:

test_that("test table_ab", {
a <- data.frame(Index = 1:2, a1 = c(1.1234, 5.6789), a2 = c("text 1", "text 2"))
b <- data.frame(
Index = 1:2,
b1 = c("apple", "penny"),
b2 = 1:2,
b3 = 3:4
)
tbl <- table_ab(a, b, byvar = "Index", decimals = c(0, 2, 0), aname = "Index")
expect_equal(tbl$Index, c(
paste0("Index: 1 a1: ", round(1.1234, 2), " a2: text 1"),
paste0("Index: 2 a1: ", round(5.6789, 2), " a2: text 2")
))
expect_equal(tbl$b1, b$b1)
expect_equal(tbl$b2, b$b2)
expect_equal(tbl$b3, b$b3)
})

Also note that this function is not exported, and its documentation file is suppressed with @noRd

@jdblischak jdblischak requested review from keaven and nanxstats January 8, 2024 20:49
@jdblischak jdblischak self-assigned this Jan 8, 2024
Copy link
Collaborator

@nanxstats nanxstats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this update.

I'm so happy to see the single update made the dependency graph lighter, and I think the updated logic is much easier to read - I often feel that I start to lose my mind after reading a dozen !!, !!!, and := operators... 😂

@nanxstats nanxstats merged commit e7cef1f into Merck:main Jan 9, 2024
@jdblischak
Copy link
Collaborator Author

I often feel that I start to lose my mind after reading a dozen !!, !!!, and := operators...

I feel the same! I was actually surprised with how simple the replacement code was. I thought all the !! were doing something more complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants