Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
vignettes/*.html
vignettes/*.md
*.zip
src/*.so
src/*.o
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions R/resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
17 changes: 12 additions & 5 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions inst/tests/test-director_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
Expand Down