[rkward] rkward/rbackend/rpackages/rkward: added two parameters to rk.check.for.pandoc()
m.eik michalke
null at kde.org
Thu Oct 11 16:49:11 BST 2018
Git commit 15012c947e5eed79bdabc4918012299b28ee3b3d by m.eik michalke.
Committed on 11/10/2018 at 15:46.
Pushed by meikm into branch 'master'.
added two parameters to rk.check.for.pandoc()
- the function can now check for valid output formats directly
- if can also operate in two modes, either just return the info, or stop with an error if soemthing is indeed missing
M +1 -1 rkward/rbackend/rpackages/rkward/DESCRIPTION
M +18 -2 rkward/rbackend/rpackages/rkward/R/rk.check.for.pandoc.R
M +12 -3 rkward/rbackend/rpackages/rkward/man/rk.check.for.pandoc.Rd
https://commits.kde.org/rkward/15012c947e5eed79bdabc4918012299b28ee3b3d
diff --git a/rkward/rbackend/rpackages/rkward/DESCRIPTION b/rkward/rbackend/rpackages/rkward/DESCRIPTION
index 1c126bb2..bb558956 100755
--- a/rkward/rbackend/rpackages/rkward/DESCRIPTION
+++ b/rkward/rbackend/rpackages/rkward/DESCRIPTION
@@ -28,7 +28,7 @@ Collate:
'internal_help.R'
'public_graphics.R'
'rk.KDE_GUI-functions.R'
- 'rk.check_for_pandoc.R'
+ 'rk.check.for.pandoc.R'
'rk.demo.R'
'rk.edit-functions.R'
'rk.filename-functions.R'
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.check.for.pandoc.R b/rkward/rbackend/rpackages/rkward/R/rk.check.for.pandoc.R
index ccc7a345..f4bfe17f 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.check.for.pandoc.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.check.for.pandoc.R
@@ -1,8 +1,12 @@
#' Check for pandoc installation and its features
#'
#' This function looks for a pandoc installation and if found, gathers information
-#' on its path, supported output formats, and the version number. It has no parameters.
+#' on its path, supported output formats, and the version number.
#'
+#' @param stop_if_missing Logical, whether an error should be thrown if either pandoc can't be found at all
+#' or a requested output format is not supported.
+#' @param output_format A character string, name of a requested output format. If not \code{NA},
+#' the function will check if the format is supported and return a boolean value.
#' @return A named list with at least the boolean element \code{available}, and if
#' that is \code{TRUE}, also the character vectors \code{path}, \code{output_formats}, and \code{version}.
#' @author Meik Michalke \email{rkward-devel@@kde.org}
@@ -14,7 +18,7 @@
#'
#' rk.check.for.pandoc()
-"rk.check.for.pandoc" <- function(){
+"rk.check.for.pandoc" <- function(stop_if_missing=FALSE, output_format=NA){
pandoc <- list(available=FALSE)
pandoc_path <- Sys.which("pandoc")[["pandoc"]]
if(!"" %in% pandoc_path){
@@ -22,6 +26,18 @@
pandoc[["available"]] <- TRUE
pandoc[["output_formats"]] <- system("pandoc --list-output-formats", intern=TRUE)
pandoc[["version"]] <- gsub("[[:space:]]*pandoc[[:space:]]*", "", system("pandoc --version", intern=TRUE)[1])
+
+ if(!is.na(output_format)){
+ pandoc <- output_format %in% pandoc[["output_formats"]]
+ if(all(isTRUE(stop_if_missing), !isTRUE(pandoc))){
+ stop(simpleError(
+ paste0("The requested output format '", output_format, "' is not supported by your pandoc installation.")
+ ))
+ } else {}
+ } else {}
+ } else if(isTRUE(stop_if_missing)){
+ stop(simpleError("'pandoc' was not found, please check your installation!"))
} else {}
+
return(pandoc)
}
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.check.for.pandoc.Rd b/rkward/rbackend/rpackages/rkward/man/rk.check.for.pandoc.Rd
index 5a061c53..043cea2e 100644
--- a/rkward/rbackend/rpackages/rkward/man/rk.check.for.pandoc.Rd
+++ b/rkward/rbackend/rpackages/rkward/man/rk.check.for.pandoc.Rd
@@ -1,10 +1,19 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/rk.check_for_pandoc.R
+% Please edit documentation in R/rk.check.for.pandoc.R
\name{rk.check.for.pandoc}
\alias{rk.check.for.pandoc}
\title{Check for pandoc installation and its features}
\usage{
-rk.check.for.pandoc()
+rk.check.for.pandoc(stop_if_missing = FALSE, output_format = NA)
+}
+\arguments{
+\item{stop_if_missing}{Logical,
+ whether an error should be thrown if either pandoc can't be found at all
+or a requested output format is not supported.}
+
+\item{output_format}{A character string,
+ name of a requested output format. If not \code{NA},
+the function will check if the format is supported and return a boolean value.}
}
\value{
A named list with at least the boolean element \code{available}, and if
@@ -13,7 +22,7 @@ A named list with at least the boolean element \code{available}, and if
}
\description{
This function looks for a pandoc installation and if found, gathers information
-on its path, supported output formats, and the version number. It has no parameters.
+on its path, supported output formats, and the version number.
}
\examples{
More information about the rkward-tracker
mailing list