Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console messages for building the graph #122

Merged
merged 3 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @param targets character vector of targets to make
#' @param envir environment containing user-defined functions
#' @param cache optional drake cache. See \code{\link{new_cache}()}
#' @param verbose logical, whether to log progress to the console.
#' @examples
#' \dontrun{
#' load_basic_example()
Expand All @@ -21,11 +22,12 @@ check <- function(
plan = workplan(),
targets = drake::possible_targets(plan),
envir = parent.frame(),
cache = drake::get_cache()
cache = drake::get_cache(),
verbose = TRUE
){
force(envir)
config <- build_config(plan = plan, targets = targets, envir = envir,
verbose = TRUE, hook = function(code) force(code),
verbose = verbose, hook = function(code) force(code),
cache = cache, parallelism = "mclapply",
jobs = 1, packages = character(0),
prepend = character(0), prework = character(0), command = character(0),
Expand Down
3 changes: 2 additions & 1 deletion R/color.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Below, the colors from "target" through
# "unload" are for the console. The rest
# "fail" are for the console. The rest
# are for plot_graph().
colors <- c(
target = "green3",
import = "dodgerblue3",
missing = "darkorchid3",
check = "skyblue1",
interconnect = "skyblue1",
load = "#ff9933",
unload = "#ff7221",
timeout = "maroon",
Expand Down
8 changes: 8 additions & 0 deletions R/console.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ console <- function(imported, target, config) {
finish_console(message = message)
}

console_dependencies <- function(targets, config){
console_many_targets(
targets = targets,
message = "interconnect",
config = config
)
}

console_many_targets <- function(
targets, message, config, color = color_of(message)
){
Expand Down
2 changes: 1 addition & 1 deletion R/dataframes_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' @param subset Optional character vector of of target/import names.
#' Subset of nodes to display in the graph.
#' Applied after \code{from}, \code{mode}, and \code{order}.
#' Be advised: edges are only kept for adgacent nodes in \code{subset}.
#' Be advised: edges are only kept for adjacent nodes in \code{subset}.
#' If you do not select all the intermediate nodes,
#' edges will drop from the graph.
#'
Expand Down
17 changes: 15 additions & 2 deletions R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ build_graph <- function(
)
true_import_names <- setdiff(names(imports), targets)
imports <- imports[true_import_names]
console_dependencies(
targets = names(imports),
config = list(verbose = verbose)
)
import_deps <- lightly_parallelize(
imports, import_dependencies, jobs = jobs)
console_dependencies(
targets = plan$target,
config = list(verbose = verbose)
)
command_deps <- lightly_parallelize(
plan$command, command_dependencies, jobs = jobs)
names(command_deps) <- plan$target
Expand Down Expand Up @@ -88,6 +96,8 @@ build_graph <- function(
#' @param jobs number of jobs to accelerate the construction
#' of the dependency graph. A light \code{mclapply}-based
#' parallelism is used if your operating system is not Windows.
#' @param verbose logical, whether to print
#' progress messages to the console.
#' @examples
#' \dontrun{
#' load_basic_example()
Expand All @@ -97,11 +107,14 @@ tracked <- function(
plan = workplan(),
targets = drake::possible_targets(plan),
envir = parent.frame(),
jobs = 1
jobs = 1,
verbose = TRUE
){
force(envir)
graph <- build_graph(
plan = plan, targets = targets, envir = envir, jobs = jobs)
plan = plan, targets = targets, envir = envir,
jobs = jobs, verbose = verbose
)
V(graph)$name
}

Expand Down
2 changes: 1 addition & 1 deletion R/plotgraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' @param subset Optional character vector of of target/import names.
#' Subset of nodes to display in the graph.
#' Applied after \code{from}, \code{mode}, and \code{order}.
#' Be advised: edges are only kept for adgacent nodes in \code{subset}.
#' Be advised: edges are only kept for adjacent nodes in \code{subset}.
#' If you do not select all the intermediate nodes,
#' edges will drop from the graph.
#'
Expand Down
20 changes: 14 additions & 6 deletions inst/examples/torque/torque.tmpl
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# from https://github.com/HenrikBengtsson/future.batchtools/blob/master/inst/templates/torque.tmpl
#!/bin/bash
######################################################################
# A batchtools launch script template for a Torque/PBS
#
# https://github.com/HenrikBengtsson/future.batchtools/blob/master/inst/templates/torque.tmpl
# Author: Henrik Bengtsson
# Modified: Will Landau
######################################################################

## Run all jobs in the current working directory.
#PBS -D <%= getwd() %>

## Job name:
#PBS -N <%= if (exists("job.name", mode = "character")) job.name else job.hash %>

Expand All @@ -19,5 +15,17 @@
## Merge standard error and output:
#PBS -j oe

## Email on abort (a) and termination (e), but not when starting (b)
## Requires mailutils if on Linux.
#PBS -m ae

## Resources needed:
<% if (length(resources) > 0) {
opts <- unlist(resources, use.names = TRUE)
opts <- sprintf("%s=%s", names(opts), opts)
opts <- paste(opts, collapse = ",") %>
#PBS -l <%= opts %>
<% } %>

## Launch R and evaluated the batchtools R job
#Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
4 changes: 3 additions & 1 deletion man/check.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/dataframes_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/tracked.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/testthat/test-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ test_with_dir(

test_with_dir("tracked() works", {
config <- dbug()
x <- sort(tracked(plan = config$plan, envir = config$envir))
x <- sort(
tracked(plan = config$plan, envir = config$envir, verbose = FALSE))
y <- sort(c("'intermediatefile.rds'",
"yourinput", "nextone",
"combined", "myinput", "final", "j", "i", "h", "g", "f",
"c", "b", "a", "saveRDS", "'input.rds'", "readRDS"))
expect_equal(x, y)
x <- sort(tracked(plan = config$plan, targets = "myinput",
envir = config$envir))
envir = config$envir, verbose = FALSE))
y <- sort(c("myinput", "'input.rds'", "readRDS"))
expect_equal(x, y)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-edge-cases.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test_with_dir("different graphical arrangements for distributed parallelism", {
expect_equal(2, max_useful_jobs(x, envir = e, config = con,
parallelism = "future_lapply", jobs = 1))
y <- workplan(a = 1, b = 2)
tmp <- dataframes_graph(y, parallelism = "Makefile")
tmp <- dataframes_graph(y, parallelism = "Makefile", verbose = FALSE)
expect_true(is.list(tmp))
})

Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-import-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ drake_context("import file")
test_with_dir("responses to imported file", {
config <- dbug()
expect_output(check(plan = config$plan, envir = config$envir))
expect_warning(check(plan = config$plan[-1, ], envir = config$envir))
expect_silent(check(plan = config$plan[c(-1, -6), ], envir = config$envir))
expect_warning(
check(plan = config$plan[-1, ], envir = config$envir,
verbose = FALSE))
expect_silent(
check(plan = config$plan[c(-1, -6), ], envir = config$envir,
verbose = FALSE))
testrun(config)
expect_true(length(justbuilt(config)) > 0)
testrun(config)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-other-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test_with_dir(".onLoad() warns correctly and .onAttach() works", {

test_with_dir("graph functions work", {
config <- dbug()
expect_equal(class(build_graph(config$plan)), "igraph")
expect_equal(class(build_graph(config$plan, verbose = FALSE)), "igraph")
pdf(NULL)
tmp <- plot_graph(plan = config$plan, envir = config$envir,
verbose = FALSE)
Expand Down Expand Up @@ -131,9 +131,9 @@ test_with_dir("targets can be partially specified", {
testrun(config)
expect_true(is.numeric(readd(final, search = FALSE)))
pl <- workplan(x = 1, y = 2)
expect_error(check(pl, "lskjdf"))
expect_warning(check(pl, c("lskdjf", "x")))
expect_silent(check(pl))
expect_error(check(pl, "lskjdf", verbose = FALSE))
expect_warning(check(pl, c("lskdjf", "x"), verbose = FALSE))
expect_silent(check(pl, verbose = FALSE))
})

test_with_dir("misc stuff", {
Expand Down
11 changes: 5 additions & 6 deletions tests/testthat/test-workplan.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ test_with_dir("plan set 4", {
target = eply::quotes(letters[1:4], single = TRUE),
command = c("c", "'c'", "d", "readRDS('e')"), stringsAsFactors = F)
expect_equal(x, y)
expect_warning(check(x))

expect_warning(check(x, verbose = FALSE))
})

test_with_dir("workplan() trims outer whitespace in target names", {
Expand All @@ -84,25 +83,25 @@ test_with_dir("make() and check() trim outer whitespace in target names", {
"nobody_home")))

x <- data.frame(target = c("a", " a"), command = 1)
expect_error(check(x))
expect_error(check(x, verbose = FALSE))
})

test_with_dir("make() plays nicely with tibbles", {
if (!("tibble" %in% rownames(installed.packages()))){
skip("Package tibble not installed.")
}
x <- tibble::tribble(~target, ~command, "nothing", 1)
expect_silent(check(x))
expect_silent(check(x, verbose = FALSE))
expect_silent(make(x, verbose = FALSE))
})

test_with_dir("check() finds bad symbols", {
x <- data.frame(
target = c("gotcha", "b", "\"targs\"", "a'x'", "b'x'"),
command = 1)
expect_warning(o <- check(x))
expect_warning(o <- check(x, verbose = FALSE))
x <- data.frame(
target = c("gotcha", "b", "\"targs\""),
command = 1)
expect_silent(o <- check(x))
expect_silent(o <- check(x, verbose = FALSE))
})