## ----include = FALSE----------------------------------------------------------
# Everything below needs to download the live index, which isn't available
# on CRAN's build machines or in an offline R CMD check. Try it once; if it
# fails, every chunk after this is skipped instead of erroring the build.
eval_chunks <- tryCatch(
  {
    psreplicate::refresh_index()
    TRUE
  },
  error = function(e) FALSE
)

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = eval_chunks
)

# The file-download section further down needs the (optional) dataverse
# package too, independent of whether the network check above passed.
eval_dataverse <- eval_chunks && requireNamespace("dataverse", quietly = TRUE)

## ----setup--------------------------------------------------------------------
library(psreplicate)

## -----------------------------------------------------------------------------
list_functions()

## -----------------------------------------------------------------------------
search_replications(query = "regression discontinuity", journal = "AJPS")

## -----------------------------------------------------------------------------
search_replications(method = "Survey Experiment", year = 2020:2024)

## -----------------------------------------------------------------------------
search_by_title("regression discontinuity")   # title only
search_by_abstract("difference-in-differences") # abstract/description only
search_by_author("Wantchekon")                  # author names only

## -----------------------------------------------------------------------------
search_by_journal(c("AJPS", "APSR"))
search_by_method("Field Experiment")
search_by_data_type("Elections / Voting")
search_by_year(2015:2020)

## -----------------------------------------------------------------------------
list_journals()
list_methods()
list_data_types()

## -----------------------------------------------------------------------------
hit <- search_by_title("Rebel Victory and Authoritarian")
dataset_info(hit$doi[1])

## ----eval = FALSE-------------------------------------------------------------
# browse_dataset(hit$doi[1])

## ----eval = eval_dataverse----------------------------------------------------
list_dataset_files(hit$doi[1])

## ----eval = FALSE-------------------------------------------------------------
# # downloads every file into a new temporary directory and returns the paths
# paths <- download_dataset(hit$doi[1])
# 
# # or into a specific directory, and only specific files
# download_dataset(hit$doi[1], dest = "replication_data", files = "README.rtf")

## ----eval = eval_dataverse----------------------------------------------------
load_dataset_file(hit$doi[1], "area.tab")

## ----eval = FALSE-------------------------------------------------------------
# refresh_index(force = TRUE)

