Skip to content

Commit

Permalink
add wrapper function cite_packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakillo committed Aug 9, 2017
1 parent 681e703 commit bce67e1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(cite_packages)
export(create_rmd)
export(get_citations)
export(get_csl)
Expand Down
28 changes: 28 additions & 0 deletions R/cite_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Cite R packages used in a project
#'
#' This is a wrapper function.
#'
#' @param all.pkg Logical. Include all packages used in scripts within the project/folder (the default), or only packages used in the current session? If TRUE, uses \code{\link[checkpoint]{scanForPackages}}, otherwise uses \code{\link[utils]{sessionInfo}}.
#' @param include.rmd Logical. Include packages used in Rmarkdown documents? (default is TRUE, requires \code{knitr} package).
#' @param style Optional. Citation style to format references. See \url{http://citationstyles.org/styles/}.
#' @param out.format Output format, either "word", "pdf", "html", or "md" (markdown).
#' @param ... Other parameters passed to \code{\link[checkpoint]{scanForPackages}}.
#'
#' @return A document with rendered citations in the desired format, plus a file ("pkg-refs.bib") containing references in BibTeX format.
#' @export
#'
#' @examples
#' library(grateful)
#' cite_packages()
#'
cite_packages <- function(all.pkg = TRUE, include.rmd = TRUE, style = NULL,
out.format = "html", ...) {

pkgs <- scan_packages(all.pkgs = all.pkg, include.Rmd = include.rmd, ...)
cites <- get_citations(pkgs) # produces "pkg-refs.bib" file
rmd <- create_rmd(cites, csl = style) # produces "refs.Rmd"
render_citations(rmd, output = out.format)

file.remove(rmd)

}
31 changes: 31 additions & 0 deletions man/cite_packages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bce67e1

Please sign in to comment.