Skip to content

Commit

Permalink
now named convert_to_pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Jul 12, 2019
1 parent 0a69532 commit b1d7798
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
S3method(print,docx)
export("%>%")
export(assign_colnames)
export(convert_pptx_to_pdf)
export(convert_to_pdf)
export(docx_cmnt_count)
export(docx_describe_cmnts)
export(docx_describe_tbls)
Expand Down
14 changes: 8 additions & 6 deletions R/convert_pptx_to_pdf.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Convert a PowerPoint Document to a PDF
#' Convert a Document (usually PowerPoint) to a PDF
#'
#' @md
#' @param path path to the PowerPoint document
#' @param path path to the document, can be PowerPoint or DOCX
#' @param pdf_file output PDF file name. By default, creates a PDF in the
#' same directory as the `path` file.
#' This functionality requires the use of
Expand All @@ -11,10 +11,12 @@
#' @examples
#' \dontrun{
#' path = system.file("examples/ex.pptx", package="docxtractr")
#' pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' path = system.file("examples/data.docx", package="docxtractr")
#' pdf_doc <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' }
convert_pptx_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
stopifnot(is_pptx(path))
convert_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
stopifnot(is_pptx(path) | is_doc(path) | is_docx(path))

lo_assert()
lo_path <- getOption("path_to_libreoffice")
Expand All @@ -23,7 +25,7 @@ convert_pptx_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
# will make sub("[.]pptx", ".pdf", path) output
# and don't want to do that in case pdf_file in other location
cp_path = tempfile(fileext = ".pptx")
cp_pdf = sub("[.]pptx", ".pdf", cp_path)
cp_pdf = sub("[.](pptx|docx|doc)$", ".pdf", cp_path)
file.copy(path, cp_path)

if (Sys.info()["sysname"] == "Windows") {
Expand Down
16 changes: 9 additions & 7 deletions man/convert_pptx_to_pdf.Rd → man/convert_to_pdf.Rd

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

13 changes: 12 additions & 1 deletion tests/testthat/test-pptx-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ test_that("we can convert a PPTX if LibreOffice Installed", {
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/ex.pptx", package = "docxtractr")
pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})

test_that("we can convert a DOCX to PDF if LibreOffice Installed", {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/data.docx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})
Expand Down

0 comments on commit b1d7798

Please sign in to comment.