-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55244e8
commit beba7b0
Showing
10 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
^build_site.R$ | ||
^pkgdown$ | ||
^\.DS_Store | ||
^_drake\.R$ | ||
^\.drake$ | ||
^\.drake_history$ | ||
^\.future$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Thumbs.db | |
*.synctex.gz | ||
*.toc | ||
*.vrb | ||
_drake.R | ||
.drake | ||
.drake_history | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' @title Write an example `_drake.R` script to the current working directory. | ||
#' @export | ||
#' @description A `_drake.R` file is required for [r_make()] and friends. | ||
#' See the [r_make()] help file for details. | ||
#' @return Nothing. | ||
#' @param code R code to put in `_drake.R` in the current working directory. | ||
#' If `NULL`, an example script is written. | ||
#' @examples | ||
#' \dontrun{ | ||
#' isolate_example("contain side-effects", { | ||
#' drake_script({ | ||
#' library(drake) | ||
#' plan <- drake_plan(x = 1) | ||
#' drake_config(plan, lock_cache = FALSE) | ||
#' }) | ||
#' cat(readLines("_drake.R"), sep = "\n") | ||
#' r_make() | ||
#' }) | ||
#' } | ||
drake_script <- function(code = NULL) { | ||
code <- substitute(code) | ||
if (length(code)) { | ||
text <- parse_drake_script_code(code) | ||
} else { | ||
text <- example_drake_script() | ||
} | ||
writeLines(text, "_drake.R") | ||
} | ||
|
||
example_drake_script <- function() { | ||
path <- system.file( | ||
file.path("templates", "drake_script", "example_drake.R"), | ||
package = "drake", | ||
mustWork = TRUE | ||
) | ||
readLines(path) | ||
} | ||
|
||
parse_drake_script_code <- function(code) { | ||
if (length(code) > 1L && safe_deparse(code[[1]]) == "`{`") { | ||
vcapply(code[-1], safe_deparse) | ||
} else { | ||
safe_deparse(code) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This file serves the r_*() functions (e.g. r_make()) documented at | ||
# https://books.ropensci.org/drake/projects.html#safer-interactivity # nolint | ||
# and | ||
# https://docs.ropensci.org/drake/reference/r_make.html | ||
|
||
# Load all your packages before calling make(). | ||
library(drake) | ||
library(tibble) | ||
|
||
# Custom functions are an important part of a drake workflow. | ||
# This is where you write them. | ||
# Details: https://books.ropensci.org/drake/plans.html#functions | ||
|
||
generate_data <- function() { | ||
tibble(x = rnorm(1e5), y = rnorm(1e5)) | ||
} | ||
|
||
fit_model <- function(data) { | ||
summary(lm(y ~ x, data = data)) | ||
} | ||
|
||
# This is where you write your drake plan. | ||
# Details: https://books.ropensci.org/drake/plans.html | ||
|
||
plan <- drake_plan( | ||
data = generate_data(), | ||
model = fit_model(data) | ||
) | ||
|
||
# You could have put all the above into separate script files and | ||
# source()'d them as below: | ||
|
||
# source("R/packages.R") # Load your packages, e.g. library(drake). # nolint | ||
# source("R/functions.R") # Define your custom code as a bunch of functions. # nolint | ||
# source("R/plan.R") # Create your drake plan. # nolint | ||
|
||
# _drake.R must end with a call to drake_config(). | ||
# The arguments to drake_config() are basically the same as those to make(). | ||
drake_config(plan) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters