## ----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)

## -----------------------------------------------------------------------------
summary(example_records)

## -----------------------------------------------------------------------------
head(tibble::as_tibble(example_records))
as.data.frame(example_records)[1:3, c("title", "year")]

## -----------------------------------------------------------------------------
dois <- scopus_extract_dois(example_records)
length(dois)
head(dois, 6)

## -----------------------------------------------------------------------------
scopus_extract_dois(c("https://doi.org/10.1/A", "doi: 10.1/a", "10.2/B"))
scopus_extract_dois(c("https://doi.org/10.1/A", "doi: 10.1/a", "10.2/B"),
                    dedupe = FALSE)

## -----------------------------------------------------------------------------
out <- file.path(tempdir(), "reference-set.csv")
scopus_extract_dois(example_records, file = out)
writeLines(head(readLines(out), 6))

## -----------------------------------------------------------------------------
cat(substr(as_ris(example_records), 1, 470))

## -----------------------------------------------------------------------------
bib <- file.path(tempdir(), "reference-set.bib")
as_bibtex(example_records, file = bib)

## -----------------------------------------------------------------------------
m <- as_bibliometrix(example_records)
head(m[, c("AU", "TI", "PY", "SO", "TC", "DB")])

## ----eval = FALSE-------------------------------------------------------------
# if (requireNamespace("bibliometrix", quietly = TRUE)) {
#   results <- bibliometrix::biblioAnalysis(m)
#   summary(results, k = 10)
# }

## -----------------------------------------------------------------------------
path <- file.path(tempdir(), "records.rds")
write_scopus_records(example_records, path)
identical(read_scopus_records(path), example_records)

