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

Remove dependency eply #156

Merged
merged 5 commits into from
Nov 14, 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
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Depends:
Imports:
codetools,
crayon,
eply,
evaluate,
digest,
future,
Expand Down
6 changes: 3 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export(drake_config)
export(drake_example)
export(drake_examples)
export(drake_palette)
export(drake_quotes)
export(drake_session)
export(drake_strings)
export(drake_tip)
export(drake_unquote)
export(empty_hook)
export(evaluate)
export(evaluate_plan)
Expand Down Expand Up @@ -113,9 +116,6 @@ importFrom(R.utils,withTimeout)
importFrom(codetools,findGlobals)
importFrom(crayon,make_style)
importFrom(digest,digest)
importFrom(eply,quotes)
importFrom(eply,strings)
importFrom(eply,unquote)
importFrom(evaluate,try_capture_stack)
importFrom(future,future_lapply)
importFrom(future,plan)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- `summaries()` => `plan_summaries()`
- Disallow `output` and `code` as names in the workflow plan data frame. Use `target` and `command` instead. This naming switch has been formally deprecated for several months prior.
- Deprecate the ..analysis.. and ..dataset.. wildcards in favor of analysis__ and dataset__, respectively. The new wildcards are stylistically better an pass linting checks.
- Add new functions `drake_quotes()`, `drake_unquote()`, and `drake_strings()` to remove the silly dependence on the `eply` package.

# Changes in release 4.4.0

Expand Down
6 changes: 3 additions & 3 deletions R/Makefile.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ build_recipe <- function(target, recipe_command,
}
if (is_file(target)){
target <- paste0("drake::as_drake_filename(\"",
eply::unquote(target), "\")")
drake::drake_unquote(target), "\")")
} else{
target <- eply::quotes(
eply::unquote(target), single = FALSE)
target <- drake::drake_quotes(
drake::drake_unquote(target), single = FALSE)
}
r_recipe <- paste0("drake::mk(target = ", target,
", cache_path = \"", cache_path, "\")")
Expand Down
9 changes: 6 additions & 3 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ check_built_file <- function(target){
if (!is_file(target)){
return()
}
if (!file.exists(eply::unquote(target))){
if (!file.exists(drake::drake_unquote(target))){
warning(
"File target ", target, " was built,\n",
"but the file itself does not exist.",
Expand Down Expand Up @@ -153,8 +153,11 @@ store_object <- function(target, value, config) {
store_file <- function(target, meta, config) {
config$cache$set(key = target, value = "file",
namespace = "type")
config$cache$set(key = target, value = file.mtime(eply::unquote(target)),
namespace = "mtimes")
config$cache$set(
key = target,
value = file.mtime(drake::drake_unquote(target)),
namespace = "mtimes"
)
hash <- ifelse(
meta$imported,
meta$file,
Expand Down
6 changes: 3 additions & 3 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ missing_input_files <- function(config) {
missing_files <- V(config$graph)$name %>%
setdiff(y = config$plan$target) %>%
Filter(f = is_file) %>%
unquote %>%
drake_unquote %>%
Filter(f = function(x) !file.exists(x))
if (length(missing_files))
warning("missing input files:\n", multiline_message(missing_files),
Expand All @@ -75,7 +75,7 @@ missing_input_files <- function(config) {
}

warn_bad_symbols <- function(x) {
x <- unquote(x)
x <- drake_unquote(x)
bad <- which(!is_parsable(x)) %>% names
if (!length(bad))
return(invisible())
Expand All @@ -101,7 +101,7 @@ check_strings <- function(plan) {
for (target in seq_len(length(x))) {
message("\ntarget: ", names(x)[target])
message("strings in command:\n",
multiline_message(eply::quotes(x[[target]],
multiline_message(drake::drake_quotes(x[[target]],
single = FALSE)), sep = "")
}
}
2 changes: 1 addition & 1 deletion R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ remove_file_target <- function(target, cache){
cache = cache
)
){
unquote(target) %>%
drake_unquote(target) %>%
unlink(recursive = TRUE, force = TRUE)
}
}
Expand Down
4 changes: 2 additions & 2 deletions R/dataframes_graph_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ default_graph_title <- function(
}

file_hover_text <- Vectorize(function(quoted_file, targets){
unquoted_file <- unquote(quoted_file)
unquoted_file <- drake_unquote(quoted_file)
if (quoted_file %in% targets | !file.exists(unquoted_file))
return(quoted_file)
tryCatch({
Expand Down Expand Up @@ -149,7 +149,7 @@ missing_import <- function(x, envir) {
FALSE
},
error = function(e) TRUE)
missing_file <- is_file(x) & !file.exists(unquote(x))
missing_file <- is_file(x) & !file.exists(drake_unquote(x))
missing_object | missing_file
}

Expand Down
6 changes: 3 additions & 3 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
deps <- function(x){
if (is.function(x)){
out <- function_dependencies(x)
} else if (is_file(x) & file.exists(file <- eply::unquote(x))){
} else if (is_file(x) & file.exists(file <- drake::drake_unquote(x))){
out <- knitr_deps(x)
} else if (is.character(x)){
out <- command_dependencies(x)
Expand Down Expand Up @@ -102,7 +102,7 @@ dependency_profile <- function(target, config){
cached_file_modification_time <- safe_get(
key = target, namespace = "mtimes", config = config)
current_file_modification_time <- ifelse(is_file(target),
file.mtime(eply::unquote(target)), NA)
file.mtime(drake::drake_unquote(target)), NA)

out <- list(
cached_command = cached_command,
Expand Down Expand Up @@ -178,7 +178,7 @@ command_dependencies <- function(command){
unlist()
files <- extract_filenames(command)
if (length(files)){
files <- eply::quotes(files, single = TRUE)
files <- drake::drake_quotes(files, single = TRUE)
}
knitr <- find_knitr_doc(command) %>%
knitr_deps
Expand Down
6 changes: 3 additions & 3 deletions R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ config <- function(
msg = paste(
"drake::evaluate() is deprecated",
"due to possible name conflicts.",
"Use drake_drake_config() instead."
"Use drake_config() instead."
)
)
drake_config(
Expand Down Expand Up @@ -502,7 +502,7 @@ plan <- function(
)
from_dots <- plan$target %in% names(commands_dots)
if (file_targets){
plan$target <- eply::quotes(plan$target, single = TRUE)
plan$target <- drake::drake_quotes(plan$target, single = TRUE)
}
if (strings_in_dots == "filenames"){
plan$command[from_dots] <- gsub("\"", "'", plan$command[from_dots])
Expand Down Expand Up @@ -864,7 +864,7 @@ workflow <- function(
)
from_dots <- plan$target %in% names(commands_dots)
if (file_targets){
plan$target <- eply::quotes(plan$target, single = TRUE)
plan$target <- drake::drake_quotes(plan$target, single = TRUE)
}
if (strings_in_dots == "filenames"){
plan$command[from_dots] <- gsub("\"", "'", plan$command[from_dots])
Expand Down
4 changes: 2 additions & 2 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ knitr_deps <- function(target){
if (!length(target)){
return(character(0))
}
file <- unquote(target)
file <- drake_unquote(target)
if (!file.exists(file)){
warning(
"dynamic report '", file,
Expand Down Expand Up @@ -141,7 +141,7 @@ is_function_call <- function(
){
package <- match.arg(package)
what <- match.arg(what)
eply::unquote(deparse(expr[[1]])) %in%
drake::drake_unquote(deparse(expr[[1]])) %in%
paste0(c("", paste0(package, c("::", ":::"))), what)
}

Expand Down
16 changes: 11 additions & 5 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
#' \code{\link{drake_example}("basic")}
#'
#' @param jobs number of parallel processes or jobs to run.
#' For \code{"future_lapply"} parallelism, \code{jobs}
#' only applies to the imports.
#' See \code{future::future.options} for environment variables that
#' control the number of \code{future_lapply()} jobs for building targets.
#' For example, you might use \code{options(mc.cores = max_jobs)}.
#' See \code{\link{max_useful_jobs}()} or \code{\link{vis_drake_graph}()}
#' to help figure out what the number of jobs should be.
#' Windows users should not set \code{jobs > 1} if
Expand All @@ -77,6 +72,17 @@
#' who use \code{parallelism == "Makefile"} will need to
#' download and install Rtools.
#'
#' For \code{"future_lapply"} parallelism, \code{jobs}
#' only applies to the imports.
#' To set the max number of jobs for \code{"future_lapply"}
#' parallelism, set the \code{workers}
#' argument where it exists: for example, call
#' \code{future::plan(multisession(workers = 4))},
#' then call \code{\link{make}(your_plan, parallelism = "future_lapply")}.
#' You might also try \code{options(mc.cores = jobs)},
#' or see \code{?future::future::.options}
#' for environment variables that set the max number of jobs.
#'
#' If \code{parallelism} is \code{"Makefile"}, Makefile-level parallelism is
#' only used for targets in your workflow plan data frame, not imports. To
#' process imported objects and files, drake selects the best parallel backend
Expand Down
4 changes: 2 additions & 2 deletions R/meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ self_hash <- Vectorize(function(target, config) {

rehash_file <- function(target, config) {
digest::digest(
object = eply::unquote(target),
object = drake::drake_unquote(target),
algo = config$long_hash_algo,
file = TRUE,
serialize = FALSE
Expand All @@ -80,7 +80,7 @@ should_rehash_file <- function(filename, new_mtime, old_mtime,

file_hash <- function(target, config, size_cutoff = 1e5) {
if (is_file(target)) {
filename <- eply::unquote(target)
filename <- drake::drake_unquote(target)
} else {
return(as.character(NA))
}
Expand Down
4 changes: 2 additions & 2 deletions R/migrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ legacy_self_hash <- Vectorize(function(target, config) {

legacy_file_hash <- function(target, config, size_cutoff = 1e5) {
if (is_file(target)) {
filename <- eply::unquote(target)
filename <- drake::drake_unquote(target)
} else {
return(as.character(NA))
}
Expand Down Expand Up @@ -309,7 +309,7 @@ legacy_file_current <- function(target, hashes, config){
if (!is_file(target)){
return(TRUE)
}
if (!file.exists(unquote(target))){
if (!file.exists(drake_unquote(target))){
return(FALSE)
}
out <- config$cache$get(target)
Expand Down
1 change: 0 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#' @importFrom codetools findGlobals
#' @importFrom crayon make_style
#' @importFrom digest digest
#' @importFrom eply quotes strings unquote
#' @importFrom evaluate try_capture_stack
#' @importFrom future future_lapply plan
#' @importFrom grDevices col2rgb rgb
Expand Down
8 changes: 6 additions & 2 deletions R/parallel_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
#' from scratch, so this backend type is higher overhead than either
#' \code{mclapply} or \code{parLapply}.
#' Also, the \code{jobs} argument only applies to the imports.
#' for the max number of jobs to use for building targets,
#' use options(mc.cores = jobs), or see \code{?future::future::.options}
#' To set the max number of jobs, set the \code{workers}
#' argument where it exists. For example, call
#' \code{future::plan(multisession(workers = 4))},
#' then call \code{\link{make}(your_plan, parallelism = "future_lapply")}.
#' You might also try options(mc.cores = jobs),
#' or see \code{?future::future::.options}
#' for environment variables that set the max number of jobs.
#' }
#'
Expand Down
65 changes: 65 additions & 0 deletions R/strings.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# All functions in this file are taken from eply:
# https://github.com/wlandau-lilly/eply

#' @title Function \code{drake_quotes}
#' @description Put quotes around each element of a character vector.
#' @seealso \code{\link{drake_unquote}}, \code{\link{drake_strings}}
#' @export
#' @return character vector with quotes around it
#' @param x character vector or object to be coerced to character.
#' @param single Add single quotes if \code{TRUE}
#' and double quotes otherwise.
#' @examples
#' # Single-quote this string.
#' drake_quotes("abcd", single = TRUE) # "'abcd'"
#' # Double-quote this string.
#' drake_quotes("abcd") # "\"abcd\""
drake_quotes <- function(x = NULL, single = FALSE){
stopifnot(is.logical(single))
if (single){
paste0("'", x, "'")
} else {
paste0("\"", x, "\"")
}
}

#' @title Function \code{drake_unquote}
#' @description Remove leading and trailing
#' escaped quotes from character strings.
#' @seealso \code{\link{drake_quotes}}, \code{\link{drake_strings}}
#' @export
#' @return character vector without leading
#' or trailing escaped quotes around
#' the elements
#' @param x character vector
#' @param deep remove all outer quotes if \code{TRUE}
#' and only the outermost set otherwise. Single and double
#' quotes are treated interchangeably, and matching is not checked.
#' @examples
#' x <- "'abcd'"
#' # Remove the literal quotes around x.
#' drake_unquote(x) # "abcd"
drake_unquote <- function(x = NULL, deep = FALSE){
if (deep){
gsub("^[\"']*|[\"']*$", "", x)
} else {
gsub("^[\"']|[\"']$", "", x)
}
}

#' @title Function \code{drake_strings}
#' @description Turn valid expressions into character strings.
#' @seealso \code{\link{drake_quotes}}, \code{\link{drake_unquote}}
#' @export
#' @return a character vector
#' @param ... unquoted symbols to turn into character strings.
#' @examples
#' # Turn symbols into strings.
#' drake_strings(a, b, c, d) # [1] "a" "b" "c" "d"
drake_strings <- function(...){
args <- structure(as.list(match.call()[-1]), class = "uneval")
keys <- names(args)
out <- as.character(args)
names(out) <- keys
out
}
2 changes: 1 addition & 1 deletion R/triggers.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ file_trigger <- function(target, meta, config){
if (!is_file(target)){
return(FALSE)
}
if (!file.exists(unquote(target))){
if (!file.exists(drake_unquote(target))){
return(TRUE)
}
tryCatch(
Expand Down
4 changes: 2 additions & 2 deletions R/workplan.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ workplan <- function(
)
from_dots <- plan$target %in% names(commands_dots)
if (file_targets){
plan$target <- eply::quotes(plan$target, single = TRUE)
plan$target <- drake::drake_quotes(plan$target, single = TRUE)
}
if (strings_in_dots == "filenames"){
plan$command[from_dots] <- gsub("\"", "'", plan$command[from_dots])
Expand All @@ -78,7 +78,7 @@ workplan <- function(
#' # Wraps the string in single quotes.
#' as_drake_filename("my_file.rds") # "'my_file.rds'"
as_drake_filename <- function(x){
eply::quotes(x, single = TRUE)
drake::drake_quotes(x, single = TRUE)
}

wide_deparse <- function(x){
Expand Down
Loading