Writes the R code that creates a design: a pipe of the design steps that
starts with qdm_endpoint and ends with
qdm_build, or a call of the design_*() function of
the endpoint. Evaluating the code gives a design identical to the
original. The code can be kept with a study protocol or a report (see the
argument code of show_report), or used as the start
of a new analysis.
Usage
show_code(x, style = c("pipe", "design"), name = "design")Arguments
- x
A design (created by a
design_*()function such asdesign_binary), a design specification (started byqdm_endpoint), or a result ofqdm_oc,qdm_calibrate,qdm_find_n,qdm_boundaryorqdm_decide.- style
"pipe"(the default) for the pipe of the design steps, or"design"for the call of thedesign_*()function.- name
Name to which the code assigns the design, or
NULLfor no assignment.
Value
An object of class "qdm_code": a character vector with one
line of code per element, which is printed as the code.
Details
The arguments are written with the values that the design keeps (the
numbers with the fewest digits that give them exactly), and the arguments
equal to their defaults are left out. For a design specification, the
code of the pipe gives the specification (without qdm_build()).
For a result of an analysis, the code creates the design of the result;
the scenarios, the number of simulated studies and the seed of the
analysis are not part of the code.
Examples
des <- design_binary(
n_t = 12, n_c = 12,
prior_t = prior_beta(0.5, 0.5), prior_c = prior_beta(0.5, 0.5),
criterion = criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
gamma_go = 0.5, gamma_nogo = 0.8),
external_c = borrow(data_binary(n = 40, y = 12), a0 = 0.5)
)
show_code(des)
#> design <- qdm_endpoint("binary") |>
#> qdm_sample_size(n_t = 12, n_c = 12) |>
#> qdm_prior(prior_t = prior_beta(a = 0.5, b = 0.5),
#> prior_c = prior_beta(a = 0.5, b = 0.5)) |>
#> qdm_criterion(criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
#> gamma_go = 0.5, gamma_nogo = 0.8)) |>
#> qdm_external(external_c = borrow(data = data_binary(n = 40, y = 12),
#> a0 = 0.5)) |>
#> qdm_build()
show_code(des, style = "design")
#> design <- design_binary(
#> n_t = 12, n_c = 12, prior_t = prior_beta(a = 0.5, b = 0.5),
#> prior_c = prior_beta(a = 0.5, b = 0.5),
#> criterion = criterion_posterior(theta_tv = 0.2, theta_mav = 0.1,
#> gamma_go = 0.5, gamma_nogo = 0.8),
#> external_c = borrow(data = data_binary(n = 40, y = 12), a0 = 0.5)
#> )
# The code gives the same design
code <- show_code(des, name = NULL)
identical(eval(parse(text = code)), des)
#> [1] TRUE
