Skip to content

Commit

Permalink
Merge branch 'master' into htmltools-figures
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Mar 15, 2019
2 parents e48dd76 + d411348 commit 65ee249
Show file tree
Hide file tree
Showing 43 changed files with 422 additions and 277 deletions.
35 changes: 12 additions & 23 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
For general questions, please ask them on StackOverflow first, using the tags `r` and `knitr`: http://stackoverflow.com/questions/ask Please come back here only if nobody answers your question there, and let me know the URL of your StackOverflow post. It is a better idea to use the wisdom of the community than the limited time of a single person.

For bug reports, please provide a minimal, self-contained, and reproducible example by reducing your example as much as possible right before the problem goes away. By doing this, you may be able to figure out what the problem really is before reporting to me. You can attach your example as a zip file here along with `devtools::session_info('knitr')`, and screenshots are often very helpful to illustrate your issues.

To include a verbatim chunk of arbitrary text, wrap it in a pair of three backticks. When any line of your text contains N backticks (N >= 3), use N + 1 backticks to wrap the text, e.g. use four backticks to wrap three:

````
A sample document.
```{r}
1 + 1 # a line of code
```
Another paragraph.
````

If it is just a chunk of R code (or other languages) and you want syntax highlighting, you may use three backticks to format it, e.g.

```r
rnorm(10)
```

Usually your issue will be closed after it is fixed, but sometimes it is closed only because I'm not able to offer any help. It does not mean your issue is not real or bad. You can propose a fix by yourself through a pull request. Your constructive feedback is always appreciated.
By filing an issue to this repo, I promise that

- [ ] I have fully read the isse guide at https://yihui.name/issue/.
- [ ] I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included `xfun::session_info('knitr')`. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: `remotes::install_github('yihui/knitr')`.
- If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [ ] I have learned the Github Markdown syntax, and formatted my issue correctly.

<!--
Pleaes keep the above portion in your issue and delete the portion below. Your issue will be closed if any of the above boxes is not checked. In certain (rare) cases, you may be exempted if you give a brief explanation (e.g., you are only making a suggestion for improvement). Thanks!
-->
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: r

sudo: false

# environment variables
env:
matrix:
Expand Down Expand Up @@ -37,6 +35,8 @@ addons:
- qpdf
- texinfo
- cargo
- libmagick++-dev
- libpoppler-cpp-dev

repos:
XRAN: https://xran.yihui.name
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.21.5
Version: 1.22.4
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Adam", "Vogt", role = "ctb"),
Expand All @@ -22,6 +22,7 @@ Authors@R: c(
person("Doug", "Hemken", role = "ctb"),
person("Duncan", "Murdoch", role = "ctb"),
person("Elio", "Campitelli", role = "ctb"),
person("Emily", "Riederer", role = "ctb"),
person("Fabian", "Hirschmann", role = "ctb"),
person("Fitch", "Simeon", role = "ctb"),
person("Forest", "Fang", role = "ctb"),
Expand Down Expand Up @@ -122,6 +123,7 @@ Suggests:
tinytex,
reticulate (>= 1.4),
JuliaCall (>= 0.11.1),
magick,
png,
jpeg,
gifski,
Expand Down
50 changes: 49 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
# CHANGES IN knitr VERSION 1.23

## NEW FEATURES

- It is possible to customize the sign `\times` used for the scientific notation of inline numeric output via a global option, e.g., `options(knitr.inline.times = '\\cdot ')` (thanks, @wuffi @trentks, #1563).

## BUG FIXES

- For R Markdown documents, inline numeric output that is formatted with the scientific notation will be wrapped in `\ensuremath{}`. This will fix the LaTeX error `! Missing $ inserted.`. However, you are still recommended to add a pair of dollar signs around the inline output when it is formatted with the scientific notation (e.g., `` $`r 1.234e12`$``), otherwise it will not work with other R Markdown output formats such as HTML or Word (thanks, @billdenney and many who have suffered from this issue, rstudio/rmarkdown#1527).

- For an input file that contains no code chunks or inline R code expressions, `purl()` should return an empty string instead of the original text from the input (thanks, @jrnold, #1660).

- `purl()` might trigger a warning for non-R code chunks (thanks, @adamcagle, rstudio/rmarkdown#1528).

## MAJOR CHANGES

- `knitr::knit()` will try to read the input file with the UTF-8 encoding first. If UTF-8 doesn't work, it will try to read with the system native encoding instead (with a warning). The `encoding` argument of `knitr::knit()` is completely ignored. In the future, only UTF-8 will be supported, and we will stop retrying with the system native encoding. The output file from `knitr::knit()` is always encoded in UTF-8.

# CHANGES IN knitr VERSION 1.22

## NEW FEATURES

- Added chunk options `class.error`, `class.warning`, and `class.message` to customize the CSS classes for errors, warnings, and messages in R Markdown output, respectively (thanks, @gadenbuie, #1676).

- Added a new engine `sass`/`scss` to convert Sass/SCSS to CSS using either the **sass** [R package](https://github.com/rstudio/sass) (LibSass) or Dart Sass [executable](https://sass-lang.com/install) (when R package not found, the engine option `engine.opts = list(package = FALSE)`, or `engine.path` to executable is provided). After conversion, resulting CSS is treated as in the CSS engine (thanks, @emilyriederer, #1666).

- The `cat` engine supports the chunk option `eval = FALSE` now (thanks, @HanOostdijk, #1618).

- The chunk option `out.extra` can be used to include extra attributes for the `<iframe>` generated from `knitr::include_url()` or `knitr::include_app()` (thanks, @jvcasillas, #1648).

## BUG FIXES

- `knit_meta_add()` could exhaust the system's memory because of a wrong method of vectorization (thanks, @kevinushey @nikkoc, rstudio/rmarkdown#1538).

- The output path should be quoted in `pandoc()` (thanks, @antoine-sachet, #1644).

- When there are multiple figures with multiple captions in a code chunk, **bookdown**'s figure numbering is incorrect (thanks, Catherine Peng, https://stackoverflow.com/q/53880195/559676).

- Added an argument `label` to `kable()` so that users can manually specify a label (thanks, @Inferrator, #1655).

- The chunk option `fig.show='hide'` doesn't work for `knitr::include_graphics()` (thanks, @vincentarelbundock, #1675).

- The `tikz` engine doesn't work on Windows (thanks, Andry, https://stackoverflow.com/q/54839403/559676).

- `kable()` now generates a table for R Markdown documents even when the data has 0 rows (thanks, @yutannihilation, #1677).

- The chunk options `dev = 'tikz'` and `external = FALSE` didn't work in R Markdown (thanks, @martinschmelzer, #1649).

## MAJOR CHANGES

- `knitr::knit()` starts to warn against non-UTF8 encodings ([Why?](https://yihui.name/en/2018/11/biggest-regret-knitr/)). In the future, we will only support UTF-8 input. If your input file is not encoded in UTF-8, we strongly recommend that you re-save it with UTF-8.

- Removed the `encoding` arguments in `knitr::pandoc()`, `knitr::knit2pandoc()`, `knitr::knit2pdf()`, `knitr2wp()`, and `knitr::Sweave2knitr()`. The input files must be encoded in UTF-8.
- Removed the `encoding` arguments in `knitr::pandoc()`, `knitr::knit2pdf()`, `knitr2wp()`, and `knitr::Sweave2knitr()`. The input files must be encoded in UTF-8.

- `knitr::knit2html()` still has the `encoding` argument, but it only supports UTF-8 internally.

## MINOR CHANGES

- Changed `tools::texi2dvi()` to `tinytex::latexmk()` for the `tikz` engine to compile TikZ graphics to other foramts (e.g., `svg` or `png`). This requires the **tinytex** package >= v0.10.10: https://github.com/yihui/tinytex.

- Empty lines are no longer removed in the output of `purl()` (thanks, Marius Hofert).

# CHANGES IN knitr VERSION 1.21

## NEW FEATURES
Expand Down
16 changes: 8 additions & 8 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ call_block = function(block) {
)
if (!params$eval) return('')
cmds = lapply(sc_split(params$child), knit_child, options = block$params)
out = paste(unlist(cmds), collapse = '\n')
out = one_string(unlist(cmds))
return(out)
}

Expand Down Expand Up @@ -161,7 +161,7 @@ block_exec = function(options) {
# only evaluate certain lines
if (is.numeric(ev <- options$eval)) {
# group source code into syntactically complete expressions
if (isFALSE(options$tidy)) code = sapply(highr:::group_src(code), paste, collapse = '\n')
if (isFALSE(options$tidy)) code = sapply(highr:::group_src(code), one_string)
iss = seq_along(code)
code = comment_out(code, '##', setdiff(iss, iss[ev]), newline = FALSE)
}
Expand Down Expand Up @@ -464,25 +464,25 @@ process_tangle.block = function(x) {
}
if (isFALSE(params$purl)) return('')
label = params$label; ev = params$eval
if (params$engine != 'R') return(comment_out(knit_code$get(label)))
if (params$engine != 'R') return(one_string(comment_out(knit_code$get(label))))
code = if (!isFALSE(ev) && !is.null(params$child)) {
cmds = lapply(sc_split(params$child), knit_child)
paste(unlist(cmds), collapse = '\n')
one_string(unlist(cmds))
} else knit_code$get(label)
# read external code if exists
if (!isFALSE(ev) && length(code) && any(grepl('read_chunk\\(.+\\)', code))) {
eval(parse_only(unlist(stringr::str_extract_all(code, 'read_chunk\\(([^)]+)\\)'))))
}
code = parse_chunk(code)
if (isFALSE(ev)) code = comment_out(code, params$comment, newline = FALSE)
if (opts_knit$get('documentation') == 0L) return(paste(code, collapse = '\n'))
if (opts_knit$get('documentation') == 0L) return(one_string(code))
label_code(code, x$params.src)
}
#' @export
process_tangle.inline = function(x) {

output = if (opts_knit$get('documentation') == 2L) {
output = paste(line_prompt(x$input.src, "#' ", "#' "), collapse = '\n')
output = one_string(line_prompt(x$input.src, "#' ", "#' "))
} else ''

code = x$code
Expand All @@ -496,13 +496,13 @@ process_tangle.inline = function(x) {
output = c(output, cout, '')
}

paste(output, collapse = '\n')
one_string(output)
}


# add a label [and extra chunk options] to a code chunk
label_code = function(code, label) {
code = paste(c('', code, ''), collapse = '\n')
code = one_string(c('', code, ''))
paste0('## ----', stringr::str_pad(label, max(getOption('width') - 11L, 0L), 'right', '-'),
'----', code)
}
Expand Down
2 changes: 1 addition & 1 deletion R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,6 @@ clean_cache = function(clean = FALSE, path = opts_chunk$get('cache.path')) {
if (p1 != '') i = i & (substr(base, 1, nchar(p1)) == p1)
if (!any(i)) return()
if (clean) unlink(files[i]) else message(
'Clean these cache files?\n\n', paste(files[i], collapse = '\n'), '\n'
'Clean these cache files?\n\n', one_string(files[i]), '\n'
)
}
7 changes: 4 additions & 3 deletions R/defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ new_defaults = function(value = list()) {
#'
#' A list of available options:
#' \url{https://yihui.name/knitr/options/#chunk_options}
#' @note \code{opts_current} is read-only in the sense that it does nothing if
#' you call \code{opts_current$set()}; you can only query the options via
#' \code{opts_current$get()}.
#' @note \code{opts_current} should be treated as read-only and you are supposed
#' to only query its values via \code{opts_current$get()}. Technically you
#' could also call \code{opts_current$set()} to change the values, but you are
#' not recommended to do so unless you understand the consequences.
#' @export
#' @examples opts_chunk$get('prompt'); opts_chunk$get('fig.keep')
opts_chunk = new_defaults(list(
Expand Down
Loading

0 comments on commit 65ee249

Please sign in to comment.