Skip to content

Commit

Permalink
fix dataset references
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiWaldrant committed Nov 20, 2024
1 parent 334c72d commit 1980287
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions results/_include/_dataset_descriptions.qmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
```{r dataset_description}
#| echo: false
lines <- pmap_chr(dataset_info, function(dataset_name, dataset_summary, dataset_description, data_reference, ...) {
ref <- split_cite_fun(data_reference)
bibs <- convert_to_bibtex(data_reference)
# Write new entries to library.bib
write_library(bibs)
ref <- get_bibtex_entries(bibs)
rest <- list(...)
source_dataset_id <- if ("source_dataset_id" %in% names(rest)) rest$source_dataset_id else NULL
dataset_link <- if (!is.null(source_dataset_id) && dir.exists(paste0("../../datasets/", source_dataset_id))) {
Expand All @@ -19,7 +22,7 @@ lines <- pmap_chr(dataset_info, function(dataset_name, dataset_summary, dataset_
strip_margin(glue::glue("
|### {dataset_link}
|
|{summ}{ref}.
|{summ} {ref}.
|
|{dataset_description %|% ''}
|"))
Expand Down
26 changes: 26 additions & 0 deletions results/_include/_load_data.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```{r setup}
#| include: false
#| error: true
#| echo: true
library(tidyverse)
library(funkyheatmap)
Expand Down Expand Up @@ -52,6 +53,31 @@ split_cite_fun <- function(keys) {
paste0("[@", paste(refs, collapse = "; @"), "]")
}
convert_to_bibtex <- function(refs) {
bibtexhandle <- curl::new_handle()
curl::handle_setheaders(bibtexhandle, "accept" = "application/x-bibtex")
bibs <- map(refs, function(ref) {
if (grepl("^@", ref)) {
# text is already a bibtex, update citation key
ref
} else {
url <- paste0("https://doi.org/", ref)
res <- curl::curl_fetch_memory(url, handle = bibtexhandle)
if (res$status_code != 200) {
cli::cli_alert_warning(paste0("Error processing doi '", ref, "'"))
""
} else {
rawToChar(res$content)
}
}
})
return(unlist(bibs))
}
get_bibtex_from_doi <- function(dois) {
if (is.null(dois)) return("")
Expand Down
2 changes: 1 addition & 1 deletion results/_include/_results_table.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mean_na_zero <- function(x) {
}
res_tib1 <- res_tib0 %>%
group_by(method_id, method_name, paper_reference, code_url) %>%
group_by(method_id, method_name, code_url) %>%
summarise_if(is.numeric, mean_na_zero) %>%
ungroup() %>%
mutate(
Expand Down

0 comments on commit 1980287

Please sign in to comment.