Skip to content

Commit

Permalink
CRAN release 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
crsh committed Dec 17, 2019
1 parent d31bffe commit 6f92114
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 109 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^CRAN-RELEASE$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
Expand Down
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Package: rmdfiltr
Type: Package
Title: Lua filters for R Markdown
Version: 0.1.0
Title: 'Lua' filters for R Markdown
Version: 0.1.2
Authors@R: c(
person("Frederik", "Aust", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4900-788X"))
)
URL: https://github.com/crsh/rmdfiltr
BugReports: https://github.com/crsh/rmdfiltr/issues
Description: Provides a collection of Lua filters that extend the functionality
of R Markdown templates.
Description: A collection of 'Lua' filters that extend the functionality
of R Markdown templates (e.g., count words or post-process 'pandoc-citeproc'-
citations).
Imports:
assertthat (>= 0.2.1),
utils,
Expand All @@ -17,7 +18,7 @@ SystemRequirements: pandoc (>= 2.0; https://pandoc.org)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
Suggests:
dplyr (>= 0.8.0.1),
ggplot2 (>= 3.0.0),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export(add_custom_filter)
export(add_lua_filter)
export(add_replace_ampersands_filter)
export(add_wordcount_filter)
export(verify_pandoc_version)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# rmdfiltr 0.1.0

* Updates pandoc-checks to comply with CRAN policy; replaces `report` argument
with `error` flag.

# rmdfiltr 0.1.0

* Initial release with word count and ampersand replacement filter.
46 changes: 29 additions & 17 deletions R/add_lua_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' @param lua Logical. Whether the filter(s) was written in Lua (results in
#' \code{--lau-filter}-call) or not (results in \code{--filter}-call). Will be
#' recycled to fit length of \code{filter_path}.
#' @inheritParams verify_pandoc_version
#' @param error Logical. Whether to throw an error if (required version of)
#' \code{pandoc} is not available.
#'
#' @details The following Lua filters are available from \pkg{rmdfiltr}.
#' Convenience functions named after the filter are available
Expand All @@ -34,54 +35,65 @@
#'
#' @examples
#'
#' add_lua_filter(NULL, "wordcount", report = "silent")
#' add_lua_filter(NULL, "wordcount", error = FALSE)

add_lua_filter <- function(args = NULL, filter_name, report = "error") {
add_lua_filter <- function(args = NULL, filter_name, error = TRUE) {
assertthat::assert_that(is.character(filter_name))

filter_path <- system.file(paste0(filter_name, ".lua"), package = "rmdfiltr")
add_custom_filter(args, filter_path = filter_path, lua = TRUE, report = report)
add_custom_filter(args, filter_path = filter_path, lua = TRUE, error = error)
}

#' @rdname add_lua_filter
#' @export
#' @examples
#' add_wordcount_filter(NULL, report = "silent")
#' add_wordcount_filter(NULL, error = FALSE)

add_wordcount_filter <- function(args = NULL, report = "error") {
add_lua_filter(args, "wordcount", report = report)
add_wordcount_filter <- function(args = NULL, error = TRUE) {
add_lua_filter(args, "wordcount", error = error)
}

#' @rdname add_lua_filter
#' @export
#' @examples
#' add_replace_ampersands_filter(NULL, report = "silent")
#' add_replace_ampersands_filter(NULL, error = FALSE)

add_replace_ampersands_filter <- function(args = NULL, report = "error") {
add_lua_filter(args, "replace_ampersands", report = report)
add_replace_ampersands_filter <- function(args = NULL, error = TRUE) {
add_lua_filter(args, "replace_ampersands", error = error)
}

#' @rdname add_lua_filter
#' @export
#' @examples
#' add_citeproc_filter(NULL)
#' add_citeproc_filter(NULL, error = FALSE)

add_citeproc_filter <- function(args = NULL, report = "error") {
citeproc_path <- utils::getFromNamespace("pandoc_citeproc", "rmarkdown")
add_custom_filter(args, filter_path = citeproc_path(), lua = FALSE, report = report)
add_citeproc_filter <- function(args = NULL, error = TRUE) {
if(rmarkdown::pandoc_available(error = error)) {
citeproc_path <- utils::getFromNamespace("pandoc_citeproc", "rmarkdown")
add_custom_filter(args, filter_path = citeproc_path(), lua = FALSE, error = error)
} else {
NULL
}
}

#' @rdname add_lua_filter
#' @export
#' @examples
#' add_custom_filter(NULL, filter_path = "foo/bar")
#' add_custom_filter(NULL, filter_path = "foo/bar", error = FALSE)

add_custom_filter <- function(args = NULL, filter_path, lua = FALSE, report = "error") {
add_custom_filter <- function(args = NULL, filter_path, lua = FALSE, error = TRUE) {
if(!is.null(args)) assertthat::assert_that(is.character(args))
assertthat::assert_that(is.character(filter_path))
assertthat::assert_that(is.logical(lua))

if(any(lua)) verify_pandoc_version(report = report)
if(any(lua)) {
tryCatch(
rmarkdown::pandoc_available("2.0", error = error)
, error = function(e) stop(paste("For Lua filters,", e$message), call. = FALSE)
)
} else {
rmarkdown::pandoc_available(error = error)
}

lua <- rep_len(lua, length(filter_path))
filter_call <- ifelse(lua, "--lua-filter", "--filter")
Expand Down
58 changes: 29 additions & 29 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#' Verify minimum pandoc version
#' #' Verify minimum pandoc version
#' #'
#' #' Verifies that pandoc version 2.0 or later is available.
#' #'
#' #' @param report Character. In case pandoc version is < 2.0 errors if
#' #' \code{error}, warns if \code{warn}, or remains silent otherwise.
#' #'
#' #' @return Logical. \code{TRUE} if pandoc version is 2.0 or later, \code{FALSE}
#' #' otherwise.
#' #' @export
#' #'
#' #' @examples
#' #'
#' #' verify_pandoc_version(report = "silent")
#'
#' Verifies that pandoc version 2.0 or later is available.
#' verify_pandoc_version <- function(report = "error") {
#' assertthat::assert_that(length(report) == 1)
#' assertthat::assert_that(is.character(report))
#'
#' @param report Character. In case pandoc version is < 2.0 errors if
#' \code{error}, warns if \code{warn}, or remains silent otherwise.
#' lua_available <- utils::compareVersion("2.0", as.character(rmarkdown::pandoc_version())) <= 0
#'
#' @return Logical. \code{TRUE} if pandoc version is 2.0 or later, \code{FALSE}
#' otherwise.
#' @export
#' report_fun <- switch(
#' report
#' , "error" = stop
#' , "warn" = function(x) { warning(x); return(FALSE) }
#' , function(x) return(FALSE)
#' )
#'
#' @examples
#' if(!lua_available) {
#' report_fun("Lua filters require pandoc 2.0 or later (https://pandoc.org/).")
#' }
#'
#' verify_pandoc_version(report = "silent")

verify_pandoc_version <- function(report = "error") {
assertthat::assert_that(length(report) == 1)
assertthat::assert_that(is.character(report))

lua_available <- utils::compareVersion("2.0", as.character(rmarkdown::pandoc_version())) <= 0

report_fun <- switch(
report
, "error" = stop
, "warn" = function(x) { warning(x); return(FALSE) }
, function(x) return(FALSE)
)

if(!lua_available) {
report_fun("Lua filters require pandoc 2.0 or later (https://pandoc.org/).")
}

lua_available
}
#' lua_available
#' }
6 changes: 4 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ knitr::opts_chunk$set(
out.width = "100%"
)
```

# rmdfiltr

<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Travis build status](https://travis-ci.org/crsh/rmdfiltr.svg?branch=master)](https://travis-ci.org/crsh/rmdfiltr)
[![CRAN status](https://www.r-pkg.org/badges/version/rmdfiltr)](https://cran.r-project.org/package=rmdfiltr)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/last-month/rmdfiltr)
<!-- badges: end -->

`rmdfiltr` provides a collection of [Lua-filters](https://pandoc.org/lua-filters.html) that extend the functionality
Expand Down Expand Up @@ -70,7 +72,7 @@ See [R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/new-
# Contributions

Contributions of new filters are welcome.
Pleas refer to the [contributing guidelines](.github/CONTRIBUTING.md) before you start working or open a pull request.
Pleas refer to the [contributing guidelines](https://github.com/crsh/rmdfiltr/blob/master/.github/CONTRIBUTING.md) before you start working or open a pull request.
Also, please note that the `rmdfiltr` project is released with a
[Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md).
[Contributor Code of Conduct](https://github.com/crsh/rmdfiltr/blob/master/.github/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
status](https://travis-ci.org/crsh/rmdfiltr.svg?branch=master)](https://travis-ci.org/crsh/rmdfiltr)
[![CRAN
status](https://www.r-pkg.org/badges/version/rmdfiltr)](https://cran.r-project.org/package=rmdfiltr)
\[![CRAN
downloads](https://cranlogs.r-pkg.org/badges/last-month/rmdfiltr)
<!-- badges: end -->

`rmdfiltr` provides a collection of
Expand Down Expand Up @@ -67,8 +69,9 @@ details on how to create custom formats.
# Contributions

Contributions of new filters are welcome. Pleas refer to the
[contributing guidelines](.github/CONTRIBUTING.md) before you start
working or open a pull request. Also, please note that the `rmdfiltr`
project is released with a [Contributor Code of
Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project,
you agree to abide by its terms.
[contributing
guidelines](https://github.com/crsh/rmdfiltr/blob/master/.github/CONTRIBUTING.md)
before you start working or open a pull request. Also, please note that
the `rmdfiltr` project is released with a [Contributor Code of
Conduct](https://github.com/crsh/rmdfiltr/blob/master/.github/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
11 changes: 10 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Test environments

* local OS X 10.12.6 install, R 3.4.4
* macOS 10.11 El Capitan, R-release (r-hub)
* Ubuntu 14.04 (on travis-ci), R 3.4.4
* Fedora Linux, R-devel, clang, gfortran (r-hub)
* Ubuntu Linux 16.04 LTS, R-release, GCC (r-hub)
Expand All @@ -12,4 +13,12 @@

0 errors | 0 warnings | 0 note

* This is a new release.
## Comments

This is a resubmission. Thank you for the swift response. I fixed the following
issue:

check ERRORs on Solaris and macOS

> add_citeproc_filter(NULL, error = FALSE)
Error in if (file.exists(p)) p else bin : argument is of length zero
24 changes: 12 additions & 12 deletions man/add_lua_filter.Rd

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

23 changes: 0 additions & 23 deletions man/verify_pandoc_version.Rd

This file was deleted.

12 changes: 7 additions & 5 deletions tests/testthat/test_convenience_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ test_that(
"Convenience functions"
, {
expect_identical(
add_lua_filter(filter_name = "wordcount", report = "silent")
, add_wordcount_filter(report = "silent")
add_lua_filter(filter_name = "wordcount", error = FALSE)
, add_wordcount_filter(error = FALSE)
)

expect_identical(
add_lua_filter(filter_name = "replace_ampersands", report = "silent")
, add_replace_ampersands_filter(report = "silent")
add_lua_filter(filter_name = "replace_ampersands", error = FALSE)
, add_replace_ampersands_filter(error = FALSE)
)

skip_on_cran()

citeproc_path <- utils::getFromNamespace("pandoc_citeproc", "rmarkdown")

expect_identical(
add_citeproc_filter(NULL)
add_citeproc_filter(NULL, error = FALSE)
, c("--filter", citeproc_path())
)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_vectorization.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ test_that(
"Vectorization"
, {
expect_identical(
add_lua_filter(filter_name = c("replace_ampersands", "wordcount"), report = "silent")
, c(add_replace_ampersands_filter(report = "silent"), add_wordcount_filter(report = "silent"))
add_lua_filter(filter_name = c("replace_ampersands", "wordcount"), error = FALSE)
, c(add_replace_ampersands_filter(error = FALSE), add_wordcount_filter(error = FALSE))
)

expect_identical(
add_custom_filter(filter_path = c("foo/bar", "bar/foo"), lua = c(TRUE, FALSE), report = "silent")
add_custom_filter(filter_path = c("foo/bar", "bar/foo"), lua = c(TRUE, FALSE), error = FALSE)
, c("--lua-filter", "foo/bar", "--filter", "bar/foo")
)

expect_identical(
add_custom_filter(filter_path = c("foo/bar", "bar/foo"), lua = TRUE, report = "silent")
add_custom_filter(filter_path = c("foo/bar", "bar/foo"), lua = TRUE, error = FALSE)
, c("--lua-filter", "foo/bar", "--lua-filter", "bar/foo")
)
}
)
)
Loading

0 comments on commit 6f92114

Please sign in to comment.