Returns a single script suitable for the Code tab in Shiny. For Stata
replications, the substantive analysis from stata_source is inlined
after a short setup section so the script can be copied and run. When
stata_source is omitted but the runner calls nested do files,
those paths are inferred automatically (setup helpers such as
init_study_paths.do are skipped). R replications return the analysis
script only; optional format_* helpers in separate files are labeled
and omitted for Stata.
Arguments
- doi
Character. DOI of the paper, registry handle, or local study path. Pass
"local"to read code from the study in the current working directory — no registry lookup is needed; seeresolve_doi_input().- what
Character. Replication identifier (logical id).
- language
Optional
"R"or"stata".- style
Display style:
"inline"(default, inlines Stata sources for copy-paste) or"source"(raw runner only, for linked inspection in Shiny).- mode
"definitions"(default) returns the stored script (pure function definitions)."run"appends a yaml-implied execute recipe (loaddata:, callmake_*, pipeformat_*when applicable).- repo
Optional repository slug.
- folder
Optional registry folder name from
index.csv.
Details
Scripts keep pure make_* / format_* definitions; the package
orchestrates load \(\rightarrow\) make \(\rightarrow\) format via
run_replication() using replication.yml as the single source of truth.
Authors do not need an interactive sys.nframe() footer. Use
mode = "run" when you want script text that appends a yaml-implied
load \(\rightarrow\) make \(\rightarrow\) format expression so
eval(parse(text = ...)) can produce the object (working directory =
study root).
For package-backed studies, reads inst/replication_code/*.R from the
study package GitHub repo when the package is not installed (same idea as
reading code/*.R from the registry repo).
Examples
if (FALSE) { # \dontrun{
head(get_code("10.1177/00491241211036161", "fig_1"))
get_code("10.1017/S0003055403000534", "tab_1", language = "stata")
get_code("10.1017/S0003055422000284", "tab_1")
get_code("10.1257/aer.91.5.1369", "tab_1", language = "stata")
get_code("rep-template", "tab_1", mode = "run")
# setwd() to a checked-out study repo (or open its RStudio project):
setwd("path/to/rep-my-study")
head(get_code("local", "tab_1"))
} # }
