Skip to content

Commit 4ab6e10

Browse files
committed
fix citation function
1 parent 4b52a65 commit 4ab6e10

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

R/cite.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,27 @@ spod_cite <- function(
5353
format <- setdiff(format, "all")
5454

5555
# 4. Get the citation object
56-
cit <- utils::citation("spanishoddata")
56+
cit <- tryCatch(
57+
{
58+
suppressWarnings(utils::citation("spanishoddata"))
59+
},
60+
error = function(e) {
61+
# Fallback for devtools::load_all() or test environments
62+
citation_file <- system.file("CITATION", package = "spanishoddata")
63+
if (citation_file == "") {
64+
stop("CITATION file not found.")
65+
}
66+
readCitationFile(citation_file, meta = list(Encoding = "UTF-8"))
67+
}
68+
)
5769

5870
# 5. Function to get citation by key
5971
get_citation_by_key <- function(key) {
60-
idx <- which(purrr::map_lgl(cit, ~ .x$key == key))
72+
idx <- which(purrr::map_lgl(cit, function(x) {
73+
# Try multiple ways to access the key
74+
entry_key <- x$key %||% attr(x, "key") %||% x[["key"]]
75+
isTRUE(entry_key == key)
76+
}))
6177
if (length(idx) > 0) {
6278
return(cit[idx])
6379
}

0 commit comments

Comments
 (0)