Skip to content

Commit aa46920

Browse files
committed
switch bib parser from bibtex to rbibutils
1 parent bbd0f50 commit aa46920

File tree

90 files changed

+451
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+451
-317
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
auto/
12
/vignettes/.RData
23
/vignettes/Inserting_figures_and_evaluated_examples.tex
34
/vignettes/Inserting_bibtex_references.tex

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: Rdpack
22
Type: Package
33
Title: Update and Manipulate Rd Documentation Objects
4-
Version: 1.0.1
5-
Date: 2020-07-02
4+
Version: 2.0.0
5+
Date: 2020-10-02
66
Authors@R: c( person(given = c("Georgi", "N."),
77
family = "Boshnakov",
88
role = c("aut", "cre"),
@@ -26,13 +26,13 @@ Depends:
2626
Imports:
2727
tools,
2828
utils,
29-
bibtex (>= 0.4.0),
30-
gbRd
29+
gbRd,
30+
rbibutils (>= 1.3)
3131
Suggests:
3232
grDevices,
3333
testthat,
3434
rstudioapi,
3535
rprojroot
3636
License: GPL (>= 2)
3737
LazyLoad: yes
38-
RoxygenNote: 7.1.0
38+
RoxygenNote: 7.1.1

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ importFrom(tools, parse_Rd, toRd, checkRd, Rd2txt,
99
#importFrom(grDevices, dev.off, png)
1010

1111
importFrom(gbRd, Rd_help2txt)
12-
importFrom(bibtex, read.bib)
12+
#importFrom(bibtex, read.bib)
13+
importFrom(rbibutils, readBib)
1314

1415
S3method(as.character, f_usage)
1516
S3method(print, f_usage)

NEWS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
# Rdpack 2.0.0 (CRAN)
2+
3+
- removed `bibtex` from `Suggests` and elsewhere.
4+
5+
6+
# Rdpack 1.1.0
7+
8+
- imported `rbibutils` and made suitable adjustments to the code.
9+
10+
- moved `bibtex` to `Suggests` (since `bibtex` has been orphaned for several years).
11+
12+
113
# Rdpack 1.0.1
214

315
- removed a documentation link to a function in `gbutils`, which is not among
416
the dependencies of `Rdpack`. This was raising a NOTE on one of the CRAN
517
testing machines.
618

719

8-
# Rdpack 1.0.0
20+
# Rdpack 1.0.0 (CRAN)
921

1022
- `viewRd()` now loads also Rd macros declared by the package to which the
1123
rendered Rd file belongs. Previously only macros from `Rdpack` were loaded

R/bib.R

Lines changed: 125 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ get_bibentries <- function(..., package = NULL, bibfile = "REFERENCES.bib",
7373
## This is really for the case when system.file() is the one from devtools,
7474
## see the note above. TODO: check if this is the case?
7575
fn <- system.file("inst", ..., bibfile, package = package)
76-
77-
if(length(fn) == 1 && fn == "")
78-
## if system.file() didn't find the bib file, check if file package.bib is
79-
## provided by package "bibtex" (it is for core R packages, such as "base")
80-
fn <- system.file("bib", sprintf("%s.bib", package), package = "bibtex")
76+
77+
## 2020-09-27 removing this functionality since package 'bibtex' ca no longer be
78+
## relied upon and was dropped from the dependencies.
79+
##
80+
## if(length(fn) == 1 && fn == "")
81+
## ## if system.file() didn't find the bib file, check if file package.bib is
82+
## ## provided by package "bibtex" (it is for core R packages, such as "base")
83+
## fn <- system.file("bib", sprintf("%s.bib", package), package = "bibtex")
8184
}
8285

8386
if(length(fn) > 1){
@@ -109,7 +112,17 @@ get_bibentries <- function(..., package = NULL, bibfile = "REFERENCES.bib",
109112
else
110113
"UTF-8"
111114

112-
res <- read.bib(file = fn, encoding = encoding)
115+
## 2020-09-22 switching to 'rbibutils
116+
## res <- read.bib(file = fn, encoding = encoding)
117+
# rds <- tempfile(fileext = ".rds")
118+
# if(encoding == "UTF-8")
119+
# encoding = "utf8"
120+
# be <- bibConvert(fn, rds, "bibtex",
121+
# "bibentry", encoding = c(encoding, "utf8"), tex = "no_latex")
122+
# res <- readRDS(rds)
123+
# #print(res)
124+
# unlink(rds)
125+
res <- readBib(file = fn, encoding = encoding)
113126

114127
# 2018-03-10 commenting out
115128
# since bibtex v. >= 0.4.0 has been required for a long time in DESCRIPTION
@@ -120,33 +133,71 @@ get_bibentries <- function(..., package = NULL, bibfile = "REFERENCES.bib",
120133
# names(res) <- sapply(1:length(res), function(x) bibentry_key(res[[x]][[1]]))
121134
# }
122135

123-
for(nam in names(res)){
124-
## unconditionaly recode %'s in filed URL
125-
if(!is.null(res[nam]$url))
126-
res[nam]$url <- gsub("([^\\])%", "\\1\\\\%", res[nam]$url)
127-
128-
if(url_only){ # process also other fields
129-
## TODO: currently all unescaped $'s in all fields are recoded;
130-
## Maybe do it more selectively, e.g. only for %'s inside \url{},
131-
## or matching something like http(s)://
132-
fields <- names(unclass(res[nam])[[1]])
133-
134-
unclassed <- unclass(res[nam])
135-
flag <- FALSE
136-
for(field in fields){
137-
wrk <- unclass(res[nam])[[1]][[field]]
138-
if(is.character(wrk) && any(grepl("([^\\])%", wrk))){
139-
flag <- TRUE
140-
unclassed[[1]][[field]] <- gsub("([^\\])%", "\\1\\\\%", wrk)
141-
}
136+
## 2020-10-02 commenting out since taken care (hopefully) by readBib
137+
##
138+
# for(nam in names(res)){
139+
# ## unconditionaly recode %'s in filed URL
140+
# if(!is.null(res[nam]$url)) {
141+
# res[nam]$url <- gsub("([^\\])%", "\\1\\\\%", res[nam]$url)
142+
# }
143+
#
144+
# if(url_only){ # process also other fields
145+
# ## TODO: currently all unescaped %'s in all fields are recoded;
146+
# ## Maybe do it more selectively, e.g. only for %'s inside \url{},
147+
# ## or matching something like http(s)://
148+
# fields <- names(unclass(res[nam])[[1]])
149+
#
150+
# unclassed <- unclass(res[nam])
151+
# flag <- FALSE
152+
# for(field in fields){
153+
# wrk <- unclass(res[nam])[[1]][[field]]
154+
# if(is.character(wrk) && any(grepl("([^\\])%", wrk))){
155+
# flag <- TRUE
156+
# unclassed[[1]][[field]] <- gsub("([^\\])%", "\\1\\\\%", wrk)
157+
# }
158+
# }
159+
# if(flag){
160+
# class(unclassed) <- class(res[nam])
161+
# res[nam] <- unclassed
162+
# }
163+
# }
164+
# }
165+
166+
## new 2020-10-02 - allow \% in url's and doi's in the bib file
167+
for(nam in names(res)){
168+
#print(res[nam], style = "R")
169+
## unconditionaly recode %'s in filed URL
170+
if(!is.null(res[nam]$doi)) {
171+
res[nam]$doi <- gsub("([^\\\\])[\\\\]%", "\\1%", res[nam]$doi)
142172
}
143-
if(flag){
144-
class(unclassed) <- class(res[nam])
145-
res[nam] <- unclassed
173+
174+
if(!is.null(res[nam]$url)) {
175+
res[nam]$url <- gsub("([^\\\\])[\\\\]%", "\\1%", res[nam]$url)
146176
}
177+
178+
# if(url_only){ # process also other fields
179+
# ## TODO: currently all unescaped %'s in all fields are recoded;
180+
# ## Maybe do it more selectively, e.g. only for %'s inside \url{},
181+
# ## or matching something like http(s)://
182+
# fields <- names(unclass(res[nam])[[1]])
183+
#
184+
# unclassed <- unclass(res[nam])
185+
# flag <- FALSE
186+
# for(field in fields){
187+
# wrk <- unclass(res[nam])[[1]][[field]]
188+
# if(is.character(wrk) && any(grepl("([^\\])%", wrk))){
189+
# flag <- TRUE
190+
# unclassed[[1]][[field]] <- gsub("([^\\])%", "\\1\\\\%", wrk)
191+
# }
192+
# }
193+
# if(flag){
194+
# class(unclassed) <- class(res[nam])
195+
# res[nam] <- unclassed
196+
# }
197+
# }
147198
}
148-
}
149199

200+
150201
## 2018-03-03 new:
151202
class(res) <- c("bibentryRd", class(res))
152203

@@ -315,12 +366,53 @@ Rdo_flatinsert <- function(rdo, val, pos, before = TRUE){
315366
res
316367
}
317368

318-
## TODO: auto-deduce 'package'?
319-
insert_ref <- function(key, package = NULL, ...) { # bibfile = "REFERENCES.bib"
320-
if(is.null(package))
369+
370+
.get_bibs0 <- function(package, ..., cached_env) {
371+
if(is.null(package))
321372
stop("argument 'package' must be provided")
322373

323-
bibs <- get_bibentries(package = package, ..., stop_on_error = FALSE)
374+
if(!is.null(cached_env)){
375+
if(is.null(cached_env$refsmat))
376+
cached_env$refsmat <- matrix(character(0), nrow = 0, ncol = 2)
377+
if(is.null(cached_env$allbibs))
378+
cached_env$allbibs <- list()
379+
}
380+
381+
## if(length(keys) > 1)
382+
## stop("`keys' must be a character string")
383+
##
384+
## if(!cite_only)
385+
## cached_env$refsmat <- rbind(cached_env$refsmat, c(keys, package))
386+
##
387+
## if(dont_cite)
388+
## return(character(0))
389+
390+
391+
if(is.null(cached_env)){
392+
bibs <- get_bibentries(package = package, ..., stop_on_error = FALSE)
393+
}else{
394+
bibs <- cached_env$allbibs[[package]]
395+
if(is.null(bibs)){
396+
bibs <- get_bibentries(package = package, ..., stop_on_error = FALSE)
397+
cached_env$allbibs[[package]] <- bibs
398+
}
399+
}
400+
401+
bibs
402+
}
403+
404+
405+
## TODO: auto-deduce 'package'?
406+
## 2020-09-30: changing to cache bib as \insertCite does (new arg. cached_env, etc)
407+
insert_ref <- function(key, package = NULL, ..., cached_env = NULL) { # bibfile = "REFERENCES.bib"
408+
409+
# 2020-09-30: replaced by a single call
410+
# if(is.null(package))
411+
# stop("argument 'package' must be provided")
412+
#
413+
# bibs <- get_bibentries(package = package, ..., stop_on_error = FALSE)
414+
#
415+
bibs <- .get_bibs0(package, ..., cached_env = cached_env)
324416

325417
if(length(bibs) == 0){
326418
note <- paste0("\"Failed to insert reference with key = ", key,

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/authors.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/news/index.html

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ pandoc: '2.5'
22
pkgdown: 1.5.1
33
pkgdown_sha: ~
44
articles: {}
5-
last_built: 2020-07-02T08:12Z
5+
last_built: 2020-10-03T09:03Z
66

0 commit comments

Comments
 (0)