Skip to content

Commit

Permalink
Force argument dir to be supplied to install_otp()
Browse files Browse the repository at this point in the history
  • Loading branch information
paulnorthrop committed Apr 27, 2024
1 parent aaeb9ec commit 9d7f352
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
20 changes: 12 additions & 8 deletions R/install_otp.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#' \url{https://github.com/cognidox/OfficeToPDF/releases} and copies it to
#' a suitable location, by default `system.file(package = "accessr")`.
#'
#' @param dir Directory into which to download the \code{OfficeToPDF.exe}.
#' If \code{dir} is missing then \code{system.file(package = "accessr")} is
#' used. This should enable \code{OfficeToPDF.exe} to be found but
#' there may be a problem if \code{\link{.libPaths}} refers to a cloud
#' storage directory, such as OneDrive.
#' @param dir Directory into which to download the executable file
#' \code{OfficeToPDF.exe}. **This argument must be supplied**. Pass
#' `dir = "accessr"` to choose the `accessr` package directory, that is,
#' \code{system.file(package = "accessr")}. This choice should enable
#' \code{OfficeToPDF.exe} to be found but there may be a problem if
#' \code{\link{.libPaths}} refers to a cloud storage directory, such as
#' OneDrive.
#' @param url URL from which to download \code{OfficeToPDF.exe}. If this is
#' missing then
#' \url{https://github.com/cognidox/OfficeToPDF/releases/download/v1.9.0.2/OfficeToPDF.exe}
Expand All @@ -26,12 +28,14 @@
#' documents in \code{\link{rmd2word}}.
#' @return See the \strong{Value} section of \code{\link[utils]{download.file}}.
#' @examples
#' \dontrun{
#' # If dir is not supplied install_otp stops and dir = "accessr" is suggested
#' install_otp()
#' }
#' @export
install_otp <- function(dir, url, method, quiet = TRUE, ...) {
if (missing(dir)) {
stop("You must supply ''dir''. Perhaps choose dir = ''accessr''.")
}
if (dir == "accessr") {
dir <- system.file(package = "accessr")
}
if (missing(url)) {
Expand All @@ -49,7 +53,7 @@ install_otp <- function(dir, url, method, quiet = TRUE, ...) {
val <- utils::download.file(url = url, destfile = dir, method = method,
quiet = quiet, mode = "wb", ...)
if (val != 0) {
warning("")
warning("utils::download.file() returned a non-zero (failure) code")
}
return(invisible(val))
}
12 changes: 7 additions & 5 deletions man/install_otp.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-install_otp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Calling install_otp() with out supplying the argument dir throws an error

test_that("install_otp() throws an error", {
expect_error(install_otp())
})

0 comments on commit 9d7f352

Please sign in to comment.