Skip to content

Commit

Permalink
finalise v2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoBosh committed Aug 21, 2023
1 parent 672591b commit f83eba8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 455 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Rdpack
Type: Package
Title: Update and Manipulate Rd Documentation Objects
Version: 2.4.0.9000
Version: 2.5
Authors@R: c( person(given = c("Georgi", "N."),
family = "Boshnakov",
role = c("aut", "cre"),
Expand Down
16 changes: 13 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Rdpack 2.4.0.9000
# Rdpack 2.5

- Rd macros `insertCite` and friends were calling `insert_citeOnly` with
argument `key` instead of `keys`. This was not an error since partial matching
is ok here but not good practice. Fixes issue #28 reported by Marcel Ramos.


- changed the saved value in "tests/testthat/dummyArticle.rds" used in
'test-bib.R' with a value obtained with R-devel r84896 n previu versins of R
there wasasuperfluous final ' .').

- in some cases when square brackets were requested, rather than round ones,
`insertCiteOnly` was using closing round parenthesis.

- in some cases `insertCiteOnly` was not handling well the last cite when it was
followed by free text.


# Rdpack 2.4

Expand All @@ -13,7 +23,7 @@
since the preceding `\insertCited`. Prompted by issue #27 to allow separate
references lists for each method and the class in R6 documentation.

- It is no longer necessary to remove backslashes from `\&` in similar in bibtex
- It is no longer necessary to remove backslashes from `\&` and similar in bibtex
files (e.g. in "John Wiley \& Sons"). The backslash was appearing in the
rendered pdf manual but R-devel's checks started to warn about it recently
with something like `checkRd: (-1) pcts-package.Rd:287: Escaped LaTeX
Expand Down
33 changes: 25 additions & 8 deletions R/bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ makeVignetteReference <- function(package, vig = 1, verbose = TRUE,
}

## 2018-03-13 new

## 2023-08-19 TODO: this function was patched and its functionality extended via patches so
## many times that it needs consolidation.
insert_citeOnly <- function(keys, package = NULL, before = NULL, after = NULL,
bibpunct = NULL, ...,
cached_env = NULL, cite_only = FALSE, dont_cite = FALSE) {
Expand Down Expand Up @@ -765,14 +768,23 @@ insert_citeOnly <- function(keys, package = NULL, before = NULL, after = NULL,
keys <- substr(keys, 2, nchar(keys)) # drop refch
## TODO: check if there are still @'s at this point

refpat <- paste0("(", refch, "[^;,()[:space:]]+)") # "(@[^;,[:space:]]+)"
refpat <- paste0("(", refch, "[^;,()[:space:]]+)") # "(@[^;,[:space:]]+)"
refpat2 <- paste0( refch, "[^;,()[:space:]]+\\)")
if(textual){
wrkkeys <- strsplit(keys, "@")[[1]] # note [[1]] !!!

## the last key is special, since there is none after it
## 2023-08-19 Note:
##
## The code until the assignment to 'keys' puts a ')' at the end of each key.
## presumably to designate the end of the key for gregexpr below. But these ')'
## need to be removed later.
##
## first process the last key - it is special, since there is none after it
nk <- length(wrkkeys)
wrkkeys[nk] <- if(grepl("[;,]$", wrkkeys[nk]))
sub("([;,])$", ")\\1", wrkkeys[nk])
else if(grepl("[;,]", wrkkeys[nk]))
sub("([;,][^;,]*)$", ")\\1" , wrkkeys[nk])
else
paste0(wrkkeys[nk], ")")

Expand All @@ -789,6 +801,7 @@ insert_citeOnly <- function(keys, package = NULL, before = NULL, after = NULL,
keys <- paste0(wrkkeys, collapse = refch)
}

## find the positions of the keys (used further below to replace them with the cites
m <- gregexpr(refpat, keys)
allkeys <- regmatches(keys, m)[[1]] # note: [[1]]
allkeys <- gsub(refch, "", allkeys)
Expand All @@ -814,16 +827,20 @@ insert_citeOnly <- function(keys, package = NULL, before = NULL, after = NULL,
safe_cite(key, bibs, textual = textual, bibpunct = bibpunct,
from.package = package)
)
#print(refs)

if(textual){
## drop ")" - strong assumption that that is the last char
refs <- sapply(refs, function(s) substr(s, 1, nchar(s) - 1))
## 2023-08-19 Note: need to drop the ')' added above. The commented out solution
## below drop the last symbol in the prepared cites instead, which is
## equivalent but only if bibpunct is missing or specifies ')' as closing for
## the likes of Boshnakov (2020). The new solution matches again with a
## pattern including the ')' at the end of the key, so that ')' gets replaced
## along with the key.
## was: refs <- sapply(refs, function(s) substr(s, 1, nchar(s) - 1))
m <- gregexpr(refpat2, keys)
}
#print(refs)
## replace keys with citations
text <- keys
regmatches(text, m) <- list(refs)

## parentheses around the whole cite; 2022-02-05: also if !nobrackets
if(!textual && !nobrackets) # 2018-03-28 don't put parentheses in textual mode
text <- paste0("(", text, ")")
Expand All @@ -850,7 +867,7 @@ insert_citeOnly <- function(keys, package = NULL, before = NULL, after = NULL,

## 2022-06-05: was: toRd(text)
## workaround for issue #25; effectively assumes that citation text
## doesn't contain braces that need escaping
## doesn't contain braces that need escaping
.toRd_cite(text)
}

Expand Down
Binary file modified tests/testthat/dummyArticle.rds
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/initialize-methods.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
\code{\link{setMethod}} of the form:

\preformatted{ setMethod("initialize", "traceable",
function(.Object, def, tracer, exit, at, print) \dots
function(.Object, def, tracer, exit, at, print) \{ .... \}
)
}

Expand Down
49 changes: 27 additions & 22 deletions tests/testthat/test-bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ test_that("bib works fine", {
"@see also @Rpackage:rbibutils and @parseRd;textual", package = "Rdpack"),
"see also Boshnakov and Putman (2020) and Murdoch (2010)")

## commenting out since not sure if the ')' is on purpose after "among others" (:TODO:)
##
## expect_equal(insert_citeOnly("@see also @Rpackage:rbibutils and @parseRd, among others;textual", package = "Rdpack"),
## "see also Boshnakov and Putman (2020) and Murdoch (2010, among others)")
expect_equal(insert_citeOnly(
"@see also @Rpackage:rbibutils and @parseRd, among others;textual", package = "Rdpack"),
"see also Boshnakov and Putman (2020) and Murdoch (2010), among others")

expect_equal(insert_citeOnly(
"@see also @Rpackage:rbibutils and @parseRd", package = "Rdpack"),
Expand All @@ -53,22 +52,10 @@ test_that("bib works fine", {
"@see also @Rpackage:rbibutils and @parseRd;textual", package = "Rdpack"),
"see also Boshnakov and Putman (2020) and Murdoch (2010)")

insert_citeOnly(
expect_equal(insert_citeOnly(
"@see also @Rpackage:rbibutils and @parseRd;textual", package = "Rdpack",
bibpunct = c("[", "]"))

## TODO: bug here:
##
## expect_equal(insert_citeOnly(
## "@see also @Rpackage:rbibutils and @parseRd;textual", package = "Rdpack",
## bibpunct = c("[", "]")),
## "see also Boshnakov and Putman [2020] and Murdoch [2010]")
##
## produces:
## "see also Boshnakov and Putman [2020) and Murdoch [2010)"
## (note the closing parentheses)
## Uncomment the print comments in insertCite() to see more details.

bibpunct = c("[", "]")),
"see also Boshnakov and Putman [2020] and Murdoch [2010]")

expect_equal(insert_citeOnly(
"@see also @Rpackage:rbibutils and @parseRd;nobrackets", package = "Rdpack"),
Expand Down Expand Up @@ -127,11 +114,29 @@ test_that("bib works fine", {
expect_false(grepl("\\\\", insert_citeOnly("DiaLop2020ejor;textual", "Rdpack")))


## after fix of issue #26
## after fix of issue #26:
## before the fix it was necessary to manually remove the backslash from \&, \_, etc.
## in the bib file. Now the backslashes are removed by Rdpack
expect_known_value(insert_all_ref(matrix(c("dummyArticle", "Rdpack"), ncol = 2)),
"dummyArticle.rds", update = FALSE)
##
## fix in August 2023 for a change in R-devel (citation.R):
## resaved 'dummyArticle.rds' and conditioned on R-devel r84986.
##
## Previously the rendered version of the 'note' field contained a superfluous ' .'.
## This was fixed in R-devel r84986 (or somewhat earlier).
## After the change in R-devel, we get with the old dummyArticle.rds:
## > waldo::compare(readRDS("tests/testthat/dummyArticle.rds"),
## insert_all_ref(matrix(c("dummyArticle", "Rdpack"), ncol = 2)))
## lines(old) vs lines(new)
## "A. ZZZ (2018)."
## "\\dQuote{A relation between several fundamental constants: \\eqn{e^{i\\pi}=-1}.}"
## "\\emph{A non-existent journal with the formula \\eqn{L_2} in its name & an ampersand which is preceded by a backslash in the bib file.}."
## - "This reference does not exist. It is a test/demo that simple formulas in BibTeX files are OK. A formula in field 'note': \\eqn{c^2 = a^2 + b^2}. ."
## + "This reference does not exist. It is a test/demo that simple formulas in BibTeX files are OK. A formula in field 'note': \\eqn{c^2 = a^2 + b^2}."
##
## (notice '. .' at the end of the old string)
if(is.numeric(svnrev <- R.Version()$'svn rev') && svnrev >= 84986)
expect_known_value(insert_all_ref(matrix(c("dummyArticle", "Rdpack"), ncol = 2)),
"dummyArticle.rds", update = FALSE)

## makeVignetteReference("Rdpack", 1)

Expand Down
Loading

0 comments on commit f83eba8

Please sign in to comment.