Learn R Programming

drake (version 5.2.1)

load_mtcars_example: Load the mtcars example from drake_example("mtcars")

Description

Is there an association between the weight and the fuel efficiency of cars? To find out, we use the mtcars dataset. The mtcars dataset itself only has 32 rows, so we generate two larger bootstrapped datasets and then analyze them with regression models. Finally, we summarize the regression models to see if there is an association.

Usage

load_mtcars_example(envir = parent.frame(), seed = NULL, cache = NULL,
  report_file = "report.Rmd", overwrite = FALSE, to = report_file,
  verbose = drake::default_verbose(), force = FALSE)

Arguments

envir

The environment to load the example into. Defaults to your workspace. For an insulated workspace, set envir = new.env(parent = globalenv()).

seed

integer, the root pseudo-random seed to use for your project. To ensure reproducibility across different R sessions, set.seed() and .Random.seed are ignored and have no affect on drake workflows. Conversely, make() does not change .Random.seed, even when pseudo-random numbers are generated.

On the first call to make() or drake_config(), drake uses the random number generator seed from the seed argument. Here, if the seed is NULL (default), drake uses a seed of 0. On subsequent make()s for existing projects, the project's cached seed will be used in order to ensure reproducibility. Thus, the seed argument must either be NULL or the same seed from the project's cache (usually the .drake/ folder). To reset the random number generator seed for a project, use clean(destroy = TRUE).

cache

Optional storr cache to use.

report_file

where to write the report file report.Rmd.

overwrite

logical, whether to overwrite an existing file report.Rmd

to

deprecated, where to write the dynamic report source file report.Rmd

verbose

logical or numeric, control printing to the console. Use pkgconfig to set the default value of verbose for your R session: for example, pkgconfig::set_config("drake::verbose" = 2).

0 or FALSE:

print nothing.

1 or TRUE:

print only targets to build.

2:

in addition, print checks and cache info.

3:

in addition, print any potentially missing items.

4:

in addition, print imports. Full verbosity.

force

logical, whether to force the loading of a non-back-compatible cache from a previous version of drake.

Value

A drake_config() configuration list.

Details

Use drake_example("mtcars") to get the code for the mtcars example. The included R script is a detailed, heavily-commented walkthrough. The chapter of the user manual at https://ropenscilabs.github.io/drake-manual/mtcars.html # nolint also walks through the mtcars example. This function also writes/overwrites the file, report.Rmd.

Examples

Run this code
# NOT RUN {
test_with_dir("Quarantine side effects.", {
# Populate your workspace and write 'report.Rmd'.
load_mtcars_example() # Get the code: drake_example("mtcars")
# Check the dependencies of an imported function.
deps_code(reg1)
# Check the dependencies of commands in the workflow plan.
deps_code(my_plan$command[1])
deps_code(my_plan$command[4])
# Plot the interactive network visualization of the workflow.
config <- drake_config(my_plan)
vis_drake_graph(config)
# Run the workflow to build all the targets in the plan.
make(my_plan)
# For the reg2() model on the small dataset,
# the p-value is so small that there may be an association
# between weight and fuel efficiency after all.
readd(coef_regression2_small)
# Remove the whole cache.
clean(destroy = TRUE)
# Clean up the imported file.
unlink("report.Rmd")
})
# }

Run the code above in your browser using DataLab