Skip to contents

Assign new values for specified fields in a BibEntry object using a named character vector or list of named character vectors.

Usage

# S3 method for BibEntry
[(x, i, j, ...) <- value

Arguments

x

- a BibEntry object.

i

- see [.BibEntry

j

- see [.BibEntry

...

- see [.BibEntry

value

- values to be assigned to x. To update one entry only, should be a named character vector with names corresponding to fields. To update multiple entries, should be a list of named character vectors. Can also be an object of class BibEntry.

Value

an object of class BibEntry.

Details

Date and name list fields should be in the format expected by Biblatex (see BibEntry).

To clear a field ‘field_name’ from an entry use field_name = "".

See also

Other operators: $.BibEntry(), $<-.BibEntry(), +.BibEntry(), [.BibEntry(), [[.BibEntry(), [[<-.BibEntry(), c.BibEntry()

Examples

if (requireNamespace("bibtex")) {
    file.name <- system.file("Bib", "RJC.bib", package="RefManageR")
    bib <- ReadBib(file.name)
    print(bib[seq_len(3L)], .opts = list(sorting = "none", bib.style = "alphabetic"))
    ## add month to Serban et al., add URL and urldate to Jennings et al., and
    ##   add DOI and correct journal to Garcia et al.
    bib[seq_len(3L)] <- list(c(date="2013-12"),
                            c(url="https://bsb.eurasipjournals.com/content/2013/1/13",
                              urldate = "2014-02-02"),
                            c(doi="10.1093/bioinformatics/btt608",
                              journal = "Bioinformatics"))
    print(bib[seq_len(3L)], .opts = list(sorting = "none", bib.style = "alphabetic"))
    bib2 <- bib[seq_len(3L)]
    bib2[2:3] <- bib[5:6]
    bib2
    bib2[3] <- c(journal='', eprinttype = "arxiv", eprint = "1308.5427",
      eprintclass = "math.ST", pubstate = "submitted", bibtype = "misc")
    bib2
}
#> [SSC13] N. Serban, A. M. Staicu, and R. J. Carroll. “Multilevel
#> Cross-Dependent Binary Longitudinal Data”. In: _Biometrics_ 69.4
#> (2013), pp. 903-913.
#> 
#> [Jen+13] E. M. Jennings, J. S. Morris, R. J. Carroll, et al. “Bayesian
#> methods for expression-based integration of various types of genomics
#> data”. In: _EURASIP Journal on Bioinformatics and Systems Biology_
#> 2013.1 (2013), pp. 1-11.
#> 
#> [Gar+13] T. P. Garcia, S. Müller, R. J. Carroll, et al. “Identification
#> of important regressor groups, subgroups and individuals via
#> regularization methods: application to gut microbiome data”. In:
#> _Bioinformatics, btt_ 608 (2013).
#> Error in (function (x, i, j, ..., drop = FALSE) {    if (!length(x) || (missing(i) && missing(...)))         return(x)    ind <- NULL    if (missing(i)) {        dots <- list(...)    }    else if (is.numeric(i)) {        ind <- i    }    else if (is.logical(i)) {        ind <- which(i)    }    else if (is.character(i) && missing(j) && missing(...)) {        if (is.null(names(i))) {            ind <- match(i, names(x))            ind <- ind[!is.na(ind)]        }        else {            dots <- as.list(i)        }    }    else if (is.list(i) && missing(j) && missing(...)) {        dots <- i    }    else if (is.list(i) || is.character(i)) {        kall <- match.call(expand.dots = FALSE)        if (!missing(j)) {            kall$j <- NULL        }        if (!missing(...)) {            kall$... <- NULL        }        if (is.list(i[[1L]])) {            kall$i <- i[[1L]]            kall$j <- i[[-1L]]        }        ret.ind <- .BibOptions$return.ind        .BibOptions$return.ind <- TRUE        tryCatch({            kall$x <- force(x)            ind <- suppressMessages(eval(kall))            if (!missing(j)) {                if (is.list(j[[1L]])) {                  kall$i <- j[[1L]]                  kall$j <- j[[-1L]]                }                else {                  kall$i <- j                  if (!missing(...)) {                    kall$j <- list(...)                  }                }                ind <- unique(c(ind, suppressMessages(eval(kall))))            }            else if (!missing(...)) {                kall$i <- list(...)                ind <- unique(c(ind, suppressMessages(eval(kall))))            }        }, error = function(e) {            .BibOptions$return.ind <- ret.ind            stop(e)        })        .BibOptions$return.ind <- ret.ind    }    else {        stop("Invalid index.")    }    if (exists("dots", inherits = FALSE)) {        add <- function(x) suppressMessages(Reduce("|", x))        y <- .BibEntry_expand_crossrefs(x)        fields <- names(dots)        ind <- seq_along(x)        for (i in seq_along(dots)) {            ind <- ind[add(lapply(dots[[i]], function(trm, bib,                 fld) {                len <- nchar(trm)                if (len > 2L && substr(trm, 1L, 1L) == "!") {                  trm <- substr(trm, 2L, len)                  !FindBibEntry(bib, trm, fld)                }                else {                  FindBibEntry(bib, trm, fld)                }            }, bib = y[[ind]], fld = fields[i]))]            if (!length(ind))                 break        }    }    if (.BibOptions$return.ind)         return(ind)    if (!length(ind)) {        message("No results.")        return(invisible(list()))    }    y <- .BibEntry_expand_crossrefs(unclass(x[[ind]]), unclass(x[[-ind]]))    if (!drop)         attributes(y) <- attributes(x)[bibentry_list_attribute_names]    class(y) <- c("BibEntry", "bibentry")    return(y)})(x = `*tmp*`, i = seq_len(3L)): object '*tmp*' not found