## ----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)

## -----------------------------------------------------------------------------
scopus_field_tags()

## -----------------------------------------------------------------------------
# molecular biology
scopus_query("CRISPR", .field = "TITLE-ABS-KEY")
scopus_query("gravitational waves", .field = "TITLE-ABS-KEY") # physics
# environmental science
scopus_query("microplastics", .field = "TITLE-ABS-KEY")
scopus_query("blockchain", .field = "TITLE-ABS-KEY")          # computer science
scopus_query("digital humanities", .field = "AUTHKEY")        # humanities

## -----------------------------------------------------------------------------
# Two concepts that must co-occur (materials science).
scopus_query("perovskite", "solar cell", .field = "TITLE-ABS-KEY")

# Spelling variants, either of which will do (economics).
scopus_query("behavioral economics", "behavioural economics", .op = "OR")

# A family of related tools (molecular biology).
scopus_query("CRISPR", "Cas9", "Cas12", .op = "OR")

# Excluding a dominant homonym, so the snake stays out of the results.
scopus_query("python", "snake", .op = "AND NOT", .field = "TITLE-ABS-KEY")

## -----------------------------------------------------------------------------
q <- scopus_query("gut microbiome", "immunology", .field = "TITLE-ABS-KEY")
q
plan <- scopus_plan(q, years = 2015:2022, partition = "year")
plan

## ----eval = FALSE-------------------------------------------------------------
# scopus_count(q, years = 2015:2022)
# records <- scopus_fetch_plan(plan)

## -----------------------------------------------------------------------------
scopus_query("Max Planck", .field = "AFFILORG")

## -----------------------------------------------------------------------------
tryCatch(
  scopus_query("graphene", ""),
  scopus_error_bad_input = function(e) conditionMessage(e)
)

