diff --git a/.gitignore b/.gitignore index 72d68d7..973c726 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ vignettes/*.html vignettes/*.md *.zip +src/*.so +src/*.o diff --git a/DESCRIPTION b/DESCRIPTION index 4319269..aabbf17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,7 @@ Description: Director is responsible for managing and loading resources in consecutive loads of resources (so that we can tell if a script was modified since we last ran it) and defining parsers that allow us to generalize from the pernicious simple linear execution that is common to R. -Version: 0.2.3 +Version: 0.2.4 Authors@R: c(person("Robert", "Krzyzanowski", email = "technoguyrob@gmail.com", role = c("aut", "cre"))) Depends: diff --git a/R/resource.R b/R/resource.R index 7434650..af3bc2f 100644 --- a/R/resource.R +++ b/R/resource.R @@ -123,13 +123,13 @@ resource <- function(name, provides = list(), body = TRUE, soft = FALSE, ..., !isTRUE(modified) # No point in checking modifications in helpers otherwise # Touch helper files to see if they got modified. - helper_files <- get_helpers(resource_dir) - for (file in helper_files) { - helper <- resource(file.path(resource_key, file), body = FALSE, - tracking = FALSE, check.helpers = FALSE, - defining_environment = defining_environment) - if (tracking_is_on_and_resource_has_helpers) - modified <- modified || helper$modified + if (tracking_is_on_and_resource_has_helpers) { + helper_files <- get_helpers(dirname(filename), full.names = TRUE, leave_idempotent = TRUE) + mtime <- max(file.info(helper_files)$mtime, na.rm = TRUE) + if (!is.null(cached_details$info$mtime) && mtime > cached_details$info$mtime) { + modified <- TRUE + .cache[[cache_key]]$info$mtime <<- mtime + } } } diff --git a/R/utils.r b/R/utils.r index e777d79..a30e7f3 100644 --- a/R/utils.r +++ b/R/utils.r @@ -149,6 +149,9 @@ resource_cache_key <- function(resource_key) { #' Get all helper files associated with an idempotent resource directory. #' #' @param path character. The *absolute* path of the idempotent resource. +#' @param ... additional parameters to pass to \code{list.files}. +#' @param leave_idempotent logical. Whether or not to leave the +#' idempotent file (non-helper). By default \code{FALSE}. #' @return a character list of relative helper paths. #' @examples #' \dontrun{ @@ -157,11 +160,15 @@ resource_cache_key <- function(resource_key) { #' # below will return \code{c("constants.R", "functions.R")}. #' get_helpers("model") #' } -get_helpers <- function(path) { - helper_files <- list.files(path, pattern = '\\.[rR]$') # TODO: (RK) Recursive helpers? - same_file <- which(vapply(helper_files, - function(f) strip_r_extension(f) == basename(path), logical(1))) - helper_files <- helper_files[-same_file] +get_helpers <- function(path, ..., leave_idempotent = FALSE) { + helper_files <- list.files(path, pattern = '\\.[rR]$', ...) + if (leave_idempotent) { + helper_files + } else { + same_file <- which(vapply(helper_files, + function(f) basename(strip_r_extension(f)) == basename(path), logical(1))) + helper_files[-same_file] + } } #' Whether or not any substring of a string is any of a set of strings. diff --git a/inst/tests/test-director_resource.R b/inst/tests/test-director_resource.R index 005b560..15866e9 100644 --- a/inst/tests/test-director_resource.R +++ b/inst/tests/test-director_resource.R @@ -187,12 +187,11 @@ test_that('a sourced resource can pass args', { }) test_that("it does not allow access to another resource file's locals", { - within_file_structure(list(one.R = "one <- 1; browser(); resource('two')$value()", two.R = "2"), { + within_file_structure(list(one.R = "one <- 1; resource('two')$value()", two.R = "2"), { d <- director(tempdir) d$register_parser("one", function(source_args, source) { source_args$local$resource <- d$resource }) - browser() expect_error(d$resource("one")$value()) }) })