Skip to content

Commit

Permalink
Include \R macro in output (#35)
Browse files Browse the repository at this point in the history
The test for "special" macros in reconstruct() gave a false-positive
for "\\R" when "\\R" should be treated like "\\cr". This caused
reconstruct() to omit the "\\R" in the roxygen comments.

Add test for NULL tags. Without this test `tag(rd) != "\\R"` and
`tag(rd) == toupper(tag(rd))` are both logical(0). The result of
`logical(0) && logical(0)` is NA, and ifelse() returns NA if the test
argument is NA. So both the prefix and suffix would contain NA.

Fixes #34.
  • Loading branch information
joshuaulrich authored Mar 13, 2024
1 parent 2840432 commit d050bfb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ reconstruct = function(rd) {
'}', sep = "", collapse = ""))
} else if (length(rd) == 0) return(tag(rd))
}
special = tag(rd) == toupper(tag(rd))
singles = tag(rd) %in% c('\\tab', '\\cr')
prefix = ifelse(special, "",
paste(tag(rd), ifelse(singles, "", "{"), sep = ""))
suffix = ifelse(special, "", ifelse(singles, "", "}"))

special = tag(rd) == toupper(tag(rd)) && tag(rd) != '\\R'
if (is.null(tag(rd)) || special) {
prefix = ""
suffix = ""
} else {
singles = tag(rd) %in% c('\\tab', '\\cr', '\\R')
prefix = paste0(tag(rd), ifelse(singles, "", "{"))
suffix = ifelse(singles, "", "}")
}
paste(prefix, paste(sapply(rd, reconstruct), collapse = ""), suffix,
sep = "")
} else {
Expand Down

0 comments on commit d050bfb

Please sign in to comment.