Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
^\.github$
^LICENSE\.md$
^\.claude$
^AGENTS\.md$
^CLAUDE\.md$
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@../claude-config/AGENTS.md
@../claude-config/CLAUDE.md
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: xlamisc
Title: Helper Functions for the XLA Ecosystem
Version: 0.1.0.9000
Version: 0.2.0
Authors@R: c(
person("Sebastian", "Fischer", , "seb.fischer@tutamail.com", role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0002-9609-3197")),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# xlamisc (development version)
# xlamisc 0.2.0

* Added `shapevec_repr()` and `shapevec_reprs()` for formatting shape vectors.
* Added `without()` for removing elements from a vector.
* Added `format_bib()` for formatting bibliography entries.

# xlamisc 0.1.0

Expand Down
30 changes: 21 additions & 9 deletions R/format_bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,43 @@
#' bibentries = list(R = citation())
#' format_bib("R")
#' cite_bib("R")
format_bib = function(..., bibentries = NULL) { # nolint
format_bib = function(..., bibentries = NULL) {
# nolint
if (is.null(bibentries)) {
bibentries = get("bibentries", envir = parent.frame())
}
checkmate::assert_list(bibentries, "bibentry", names = "unique")
keys = list(...)
str = vapply(keys, function(entry) tools::toRd(bibentries[[entry]]), character(1))
str = vapply(
keys,
function(entry) tools::toRd(bibentries[[entry]]),
character(1)
)
paste0(str, collapse = "\n\n")
}

#' @rdname format_bib
#' @export
cite_bib = function(..., bibentries = NULL) { # nolint
cite_bib = function(..., bibentries = NULL) {
# nolint
if (is.null(bibentries)) {
bibentries = get("bibentries", envir = parent.frame())
}
checkmate::assert_list(bibentries, "bibentry", names = "unique")

keys = list(...)
str = vapply(keys, function(entry) {
x = bibentries[[entry]]
family = x$author[[1L]]$family
if (is.null(family)) family = x$author[[1L]]
sprintf("%s (%s)", family, x$year)
}, character(1))
str = vapply(
keys,
function(entry) {
x = bibentries[[entry]]
family = x$author[[1L]]$family
if (is.null(family)) {
family = x$author[[1L]]
}
sprintf("%s (%s)", family, x$year)
},
character(1)
)

if (length(str) >= 3L) {
str = c(toString(utils::head(str, -1L)), utils::tail(str, 1L))
Expand Down
1 change: 0 additions & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ library(testthat)
library(xlamisc)

test_check("xlamisc")

1 change: 0 additions & 1 deletion tests/testthat/test-shapevec_repr.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ test_that("shapevec_repr formats shapes correctly", {
})

test_that("shapevec_repr handles NA as ?", {

expect_equal(shapevec_repr(c(2, NA, 4)), "(2,?,4)")
expect_equal(shapevec_repr(c(NA, NA)), "(?,?)")
})
Expand Down
Loading