1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
readBib <- function(file, encoding){
bib <- tempfile(fileext = ".bib")
on.exit(unlink(bib))
if(encoding == "UTF-8")
encoding = "utf8"
be <- bibConvert(file, bib, "bibtex",
"bibentry", encoding = c(encoding, "utf8"), tex = "no_latex")
#browser()
be$bib
}
writeBib <- function(object, con = stdout(), append = FALSE){
if(!inherits(object, "bibentry"))
stop("'object' must inherit from class 'bibentry'.")
mode <- if(append) "a" else "w+"
if (is.character(con)) {
con <- file(con, open = mode)
on.exit(close(con))
}
lines <- toBibtex(object)
writeLines(lines, con)
invisible(object)
}
## readBib_legacy <- function(file, encoding){
## rds <- tempfile(fileext = ".rds")
## on.exit(unlink(rds))
##
## if(encoding == "UTF-8")
## encoding = "utf8"
##
## be <- bibConvert(file, rds, "bibtex",
## "bibentry", encoding = c(encoding, "utf8"), tex = "no_latex")
## res <- readRDS(rds)
##
## res
## }
|