Skip to content

Commit 5e66827

Browse files
authored
Warn if R used by mistake (#1850)
1 parent ded433f commit 5e66827

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* `` `Rd expr` `` inline code now generates `\Sexpr[stage=render,results=rd]{expr}`, providing a convenient syntax for evaluating R code at documentation render time (#1214).
3333
* Indented bullet lists in `@param` and other two-part tags are no longer incorrectly nested (#1102).
3434
* Horizontal rules (e.g. `----`) now generate a clear warning instead of an internal error about an unknown `thematic_break` xml node (#1707).
35+
* Inline code with uppercase `` `R ` `` now warns that you should use lowercase `` `r ` `` instead, since knitr only supports lowercase.
3536
* Inline R code (`` `r expr` ``) in non-indented list continuation lines no longer causes an error (#1651).
3637
* Link text now supports non-code markup like bold and italic, e.g., `[*italic text*][func]` generates `\link[=func]{\emph{italic text}}`, matching R's support for markup in `\link` text in R 4.5.0.
3738
* Links now do a better job of resolving package names: the process is cached for better performance (#1724); it works with infix operators (e.g. `[%in%]`) (#1728); no longer changes the link text (#1662); and includes base packages when reporting ambiguous functions (#1725).

R/markdown.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ mdxml_break <- function(state) {
335335
mdxml_code <- function(xml, tag) {
336336
code <- xml_text(xml)
337337

338+
if (grepl("^R ", code)) {
339+
warn_roxy_tag(tag$tag, "use ` r`, not `R `, for inline code")
340+
}
341+
338342
if (grepl("^Rd ", code)) {
339343
paste0(
340344
"\\Sexpr[stage=render,results=rd]{",

tests/testthat/_snaps/markdown-code.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# uppercase R in inline code gives warning
2+
3+
Code
4+
. <- roc_proc_text(rd_roclet(), text)
5+
Message
6+
x <text>:2: @title use ` r`, not `R `, for inline code.
7+
18
# multi-line inline code gives useful warning
29

310
Code

tests/testthat/test-markdown-code.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ test_that("can eval inline code", {
3030
expect_equal(out1$get_value("description"), "Description 4")
3131
})
3232

33+
test_that("uppercase R in inline code gives warning", {
34+
text <- "
35+
#' @title Title `R 1 + 1`
36+
#' @md
37+
foo <- function() NULL
38+
"
39+
expect_snapshot(. <- roc_proc_text(rd_roclet(), text))
40+
})
41+
3342
test_that("can eval fenced code", {
3443
out1 <- roc_proc_text(
3544
rd_roclet(),

0 commit comments

Comments
 (0)