R/compare_creators.R

Defines functions compare_creators

#' @keywords internal
compare_creators <- function(x, y) {
  creators_x <- creator(x)
  creators_y <- creator(y)
  all_creators <- c(creators_x, creators_y)

  identity_keys <- vapply(all_creators, function(p) {
    paste(
      p$given %||% "",
      p$family %||% "",
      p$email %||% "",
      p$comment %||% "",
      sep = "|"
    )
  }, character(1))

  unique_keys <- unique(identity_keys)
  merged <- vector("list", length(unique_keys))

  for (i in seq_along(unique_keys)) {
    key <- unique_keys[i]
    matches <- all_creators[identity_keys == key]
    roles <- unique(unlist(lapply(matches, function(p) p$role)))
    base <- matches[[1]]

    merged[[i]] <- person(
      given = base$given,
      family = base$family,
      email = base$email,
      comment = base$comment,
      role = roles
    )
  }

  do.call(c, merged)
}

Try the dataset package in your browser

Any scripts or data that you put into this service are public.

dataset documentation built on June 8, 2025, 10:15 a.m.