R/update_bib.R

#' Update bib File
#' 
#' Updates the report directory .bib file with a global/master .bib file.
#' 
#' @param report Path to the report project.
#' @param bib.loc Optional path to a .bib resource.
#' @return Updates bib from master/global .bib file.
#' @export
#' @importFrom tools file_ext
update_bib <-
function(report = getwd(), bib.loc = getOption("bib.loc")) {
    x <- file.path(report, "REPORT")
    z <- file.path(report, "PRESENTATION")
    y <- dir(z)
    current <- y[file_ext(y) == "bib"]
    if (is.null(bib.loc)) {
        stop("please supply the path to the .bib file")    
    }
    new <- basename(bib.loc)
    
    if (identical(current, character(0)) || current != new) {
        cat(paste0("Current .bib file does not match updated .bib.  Do you want to continue?\n\n"))
        ans <- menu(c("Yes", "No")) 
        if (ans == "2") {
            stop("update_bib aborted")
        }
    }
    suppressWarnings(try(file.copy(bib.loc, x, overwrite = TRUE)))
    invisible(file.copy(bib.loc, z, overwrite = TRUE))
    message("bib files updated!")
}
trinker/reports documentation built on May 31, 2019, 9:51 p.m.