|
13 | 13 | #' is a duplicate? Can include \code{"bibtype"} to check entry type and |
14 | 14 | #' \code{"key"} to check entry keys. Specifying \code{"all"} checks all fields |
15 | 15 | #' using \code{\link{duplicated}}. |
| 16 | +#' @param ignore.case logical; if \code{TRUE}, case is ignored when determining |
| 17 | +#' if fields are duplicates. |
16 | 18 | #' @return an object of class BibEntry |
17 | 19 | #' @family operators |
18 | 20 | #' @seealso \code{\link{duplicated}}, \code{\link{unique}} |
|
27 | 29 | #' bib2 <- bib[45:length(bib)] |
28 | 30 | #' |
29 | 31 | #' ## The following is FALSE because the parent entry of one entry in bib1 |
30 | | -#' ## is in bib2, so the child entry in is expanded in the BibEntry object |
| 32 | +#' ## is in bib2, so the child entry is expanded in the BibEntry object |
31 | 33 | #' ## returned by `[` to include the fields inherited from the dropped parent |
32 | 34 | #' identical(merge(bib1, bib2, 'all'), bib) |
33 | 35 | #' toBiblatex(bib1[[1L]]) |
|
54 | 56 | #' @keywords methods |
55 | 57 | `+.BibEntry` <- function(e1, e2){ |
56 | 58 | fields.to.check <- .BibOptions$merge.fields.to.check |
| 59 | + ignore.case <- .BibOptions$ignore.case |
57 | 60 | awl <- "all" %in% fields.to.check |
58 | 61 | att1 <- attributes(e1)[bibentry_list_attribute_names] |
59 | 62 | att2 <- attributes(e2)[bibentry_list_attribute_names] |
|
81 | 84 | possible.dup <- unlist(e2$bibtype) %in% unlist(e1$bibtype) |
82 | 85 | } |
83 | 86 | remain.dup.f <- setdiff(fields.to.check, c('bibtype', 'key')) |
84 | | - |
| 87 | + |
85 | 88 | if (length(dup.ind <- possible.dup) && length(remain.dup.f)){ |
| 89 | + ty <- unclass(e1) |
| 90 | + ty <- lapply(ty, function(y, f, ignore.case){ |
| 91 | + y <- y[f] |
| 92 | + if (ignore.case) |
| 93 | + y <- lapply(y, tolower) |
| 94 | + y |
| 95 | + }, f = remain.dup.f, ignore.case = ignore.case) |
86 | 96 | dup.ind <- vapply(unclass(e2[possible.dup]), |
87 | | - function(x, y, flds){ |
| 97 | + function(x, y, flds, ignore.case){ |
88 | 98 | x <- x[flds] |
| 99 | + if (ignore.case) |
| 100 | + x <- lapply(x, tolower) |
89 | 101 | for (i in seq_along(y)){ |
90 | | - if (identical(y[[i]][flds], x)) |
| 102 | + if (identical(y[[i]], x)) |
91 | 103 | return(TRUE) |
92 | 104 | } |
93 | 105 | return(FALSE) |
94 | | - }, FALSE, y = unclass(e1), flds = remain.dup.f) |
| 106 | + }, FALSE, y = ty, flds = remain.dup.f, ignore.case = ignore.case) |
95 | 107 | if (length(dup.ind)) |
96 | 108 | dup.ind <- which(dup.ind) |
97 | 109 | } |
|
128 | 140 | #' @rdname merge.BibEntry |
129 | 141 | merge.BibEntry <- function(x, y, |
130 | 142 | fields.to.check = BibOptions()$merge.fields.to.check, |
| 143 | + ignore.case = BibOptions()$ignore.case, |
131 | 144 | ...){ |
132 | | - oldfields <- BibOptions(merge.fields.to.check = fields.to.check) |
| 145 | + oldfields <- BibOptions(merge.fields.to.check = fields.to.check, |
| 146 | + ignore.case = ignore.case) |
133 | 147 | on.exit(BibOptions(oldfields)) |
134 | 148 | `+.BibEntry`(x, y) |
135 | 149 | } |
|
0 commit comments