-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40002b6
commit 2d6b569
Showing
56 changed files
with
856 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
#' | ||
#' @name cff_git_hook | ||
#' | ||
#' @family Git helpers | ||
#' @family git | ||
#' | ||
#' @export | ||
#' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#' Create a [`cff`][cff-class] object from BibTeX lines | ||
#' | ||
#' @description | ||
#' Convert a [`character`][character()] representing a BibTeX entry to a | ||
#' [`cff`][cff-class] object. | ||
#' | ||
#' @family bibtex | ||
#' @family reading | ||
#' @seealso | ||
#' [cff_read_bib()] for reading `*.bib` files. | ||
#' | ||
#' @export | ||
#' | ||
#' @param x A vector of characters with the full BibTeX string. | ||
#' @param encoding Encoding to be assumed for `x`, see [readLines()]. | ||
#' @param ... Arguments passed on to [cff_read_bib()]. | ||
#' @inheritDotParams cff_read_bib -path | ||
#' | ||
#' @return | ||
#' | ||
#' ```{r child = "man/chunks/value.Rmd"} | ||
#' ``` | ||
#' | ||
#' @details | ||
#' This is a helper function that writes `x` to a `*.bib` file and reads it with | ||
#' [cff_read_bib()]. | ||
#' | ||
#' This function requires \CRANpkg{bibtex} (>= 0.5.0) and uses | ||
#' [bibtex::read.bib()]. | ||
#' | ||
#' @examples | ||
#' if (requireNamespace("bibtex", quietly = TRUE)) { | ||
#' x <- c( | ||
#' "@book{einstein1921, | ||
#' title = {Relativity: The Special and the General Theory}, | ||
#' author = {Einstein, Albert}, | ||
#' year = 1920, | ||
#' publisher = {Henry Holt and Company}, | ||
#' address = {London, United Kingdom}, | ||
#' isbn = 9781587340925 | ||
#' }", | ||
#' "@misc{misc-full, | ||
#' title = {Handing out random pamphlets in airports}, | ||
#' author = {Joe-Bob Missilany}, | ||
#' year = 1984, | ||
#' month = oct, | ||
#' note = {This is a full MISC entry}, | ||
#' howpublished = {Handed out at O'Hare} | ||
#' }" | ||
#' ) | ||
#' | ||
#' | ||
#' cff_read_biblines(x) | ||
#' } | ||
cff_read_biblines <- function(x, encoding = "UTF-8", ...) { | ||
# Validations | ||
if (!inherits(x, "character")) { | ||
cli::cli_abort( | ||
paste0( | ||
"{.arg x} should be a {.cls character}, not a ", | ||
"{.cls {class(x)}}." | ||
) | ||
) | ||
} | ||
|
||
if (any(grepl("\\.bib$", x, ignore.case = TRUE))) { | ||
cli::cli_alert_warning( | ||
paste0("{.arg x} seems to be a {.val .bib} file, not a BibTeX entry.") | ||
) | ||
cli::cli_alert_info("Reading {.arg x} with {.fn cffr:cff_read_bib}") | ||
the_cff <- cff_read_bib(x, encoding = encoding, ...) | ||
return(the_cff) | ||
} | ||
|
||
if (!any(grepl("^@", x))) { | ||
cli::cli_alert_warning( | ||
paste0("{.arg x} doesn't look as a BibTeX entry. Check the results.") | ||
) | ||
} | ||
# Write x to a tempfile | ||
file <- tempfile(fileext = ".bib") | ||
writeLines(x, file) | ||
|
||
the_cff <- cff_read_bib(file, encoding = encoding, ...) | ||
the_cff | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.