## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = FALSE, comment = "")
# Console colour carries no meaning on a rendered page. pkgdown turns it on for
# its own build, and the escape sequences then reach the reader as literal text,
# so colour is switched off here for a plain vignette render and a site build
# alike. The fixed width keeps tibbles inside the documentation column.
options(cli.num_colors = 1, cli.hyperlink = FALSE, crayon.enabled = FALSE,
        width = 80)
# Print data frames and tibbles as formatted tables.
local({
  kp <- function(x, ...) {
    if (any(vapply(x, is.list, logical(1)))) return(knitr::normal_print(x))
    knitr::knit_print(knitr::kable(x))
  }
  for (cls in c("data.frame", "tbl_df", "tbl")) {
    registerS3method("knit_print", cls, kp, envir = asNamespace("knitr"))
  }
})

## ----setup--------------------------------------------------------------------
library(scopusflow)

## -----------------------------------------------------------------------------
baseline <- example_records[example_records$year <= 2023, ]
nrow(baseline)

## -----------------------------------------------------------------------------
later <- example_records[-1, ]
nrow(later)

## -----------------------------------------------------------------------------
changes <- scopus_diff_dois(old = baseline, new = later)
print(changes)

## -----------------------------------------------------------------------------
head(changes[changes$status == "added", ])

## -----------------------------------------------------------------------------
combined <- scopus_combine(baseline, later, dedupe = TRUE)
nrow(combined)

## -----------------------------------------------------------------------------
stacked <- c(baseline, later)
nrow(stacked)

## -----------------------------------------------------------------------------
path <- file.path(tempdir(), "baseline.rds")
write_scopus_records(baseline, path)
identical(read_scopus_records(path), baseline)

## ----eval = FALSE-------------------------------------------------------------
# later <- scopus_fetch("graphene supercapacitor", field = "TITLE-ABS-KEY")
# attr(later, "retrieved_at")
# scopus_diff_dois(old = read_scopus_records(path), new = later)

