Skip to content

Commit 965d378

Browse files
committed
reuse knitr's sweave output hooks, instead of copying them over to this package (#311)
1 parent d75ed3a commit 965d378

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rticles
22
Type: Package
33
Title: Article Formats for R Markdown
4-
Version: 0.15
4+
Version: 0.15.1
55
Authors@R: c(
66
person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"),
77
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
@@ -56,3 +56,4 @@ BugReports: https://github.com/rstudio/rticles/issues
5656
RoxygenNote: 7.1.1
5757
Suggests: testit, bookdown, xtable
5858
Encoding: UTF-8
59+
Remotes: yihui/knitr

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
rticles 0.16
2+
---------------------------------------------------------------------
3+
4+
5+
16
rticles 0.15
27
---------------------------------------------------------------------
38

R/jss_article.R

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,14 @@ jss_article <- function(
4949
)
5050
}
5151

52-
hook_chunk <- function(x, options) {
53-
if (output_asis(x, options)) return(x)
54-
paste0('```{=latex}\n\\begin{CodeChunk}\n', x, '\\end{CodeChunk}\n```')
55-
}
56-
hook_input <- function(x, options) {
57-
if (length(x)) {
58-
x <- knitr:::hilight_source(x, 'sweave', options)
59-
}
60-
paste0(c('\n\\begin{CodeInput}', x, '\\end{CodeInput}', ''),
61-
collapse = '\n')
62-
}
63-
hook_output <- function(x, options) {
64-
paste0('\n\\begin{CodeOutput}\n', x, '\\end{CodeOutput}\n')
52+
hooks <- knitr::hooks_sweave(c('CodeInput', 'CodeOutput', 'CodeChunk'))
53+
hook_chunk <- hooks[['chunk']]
54+
hooks[['chunk']] <- function(x, options) {
55+
x2 <- hook_chunk(x, options)
56+
if (identical(x, x2)) x else paste0('```{=latex}\n', x2, '\n```')
6557
}
6658

67-
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, list(
68-
chunk = hook_chunk,
69-
source = hook_input,
70-
output = hook_output,
71-
message = hook_output,
72-
warning = hook_output,
73-
plot = knitr::hook_plot_tex
74-
))
59+
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, hooks)
7560

7661
base
7762
}

0 commit comments

Comments
 (0)