Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
929bcd8
Create new "tar_external" class for storage outside data store
wlandau Apr 8, 2021
ad94fec
Avoid recording paths of internal store files
wlandau Apr 8, 2021
1ef57e8
Migrate tests
wlandau Apr 8, 2021
4751304
Add tests
wlandau Apr 8, 2021
73fdfaa
Add test
wlandau Apr 8, 2021
1472267
Fix lint
wlandau Apr 8, 2021
b05ad6e
Implement TAR_STORE env var
wlandau Apr 8, 2021
82472d8
Reset TAR_STORE before and after tests
wlandau Apr 8, 2021
14697b6
Test TAR_STORE
wlandau Apr 8, 2021
f8c1d4b
Update news
wlandau Apr 8, 2021
7316ef9
Add AWS tests
wlandau Apr 8, 2021
917b713
Add a URL test
wlandau Apr 8, 2021
50e5177
More safeguards in tests
wlandau Apr 8, 2021
7928629
Update docs
wlandau Apr 8, 2021
8dee6e1
Add tar_envvars()
wlandau Apr 8, 2021
387f6bd
Edit pkgdown.yml
wlandau Apr 8, 2021
1ba67d6
Define function families
wlandau Apr 8, 2021
d335371
Add back tar_watch() files
wlandau Apr 8, 2021
9ba436b
Spelling
wlandau Apr 8, 2021
4b8089d
Fix lints
wlandau Apr 8, 2021
0ffd3e5
Switch from TAR_STORE env var to _targets.yaml
wlandau Apr 8, 2021
079718c
Edit families
wlandau Apr 8, 2021
7c4081b
Start tar_yaml()
wlandau Apr 8, 2021
7f3fbbf
tar_config_set() and tar_config_get()
wlandau Apr 9, 2021
76f34af
Test tar_config_set() and get()
wlandau Apr 9, 2021
f1ebb13
Fix lints
wlandau Apr 9, 2021
9d6fc20
Regen docs
wlandau Apr 9, 2021
64991a0
Add to test
wlandau Apr 9, 2021
fb05322
Edit profiling study
wlandau Apr 9, 2021
387ec98
Protect running pipeline if _targets.yaml is broken
wlandau Apr 9, 2021
b2af6d1
Try to fix transient errors
wlandau Apr 9, 2021
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: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
^_pkgdown\.yml$
^_targets$
^_targets\.R$
^_targets\.yaml$
^docs$
^CODE_OF_CONDUCT.md$
^codemeta\.json$
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ README.html
paper.html
.Rproj.user
_packages.R
_targets.yaml
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Imports:
tidyselect (>= 1.1.0),
utils,
vctrs (>= 0.2.4),
withr (>= 2.1.2)
withr (>= 2.1.2),
yaml (>= 2.2.1)
Suggests:
arrow (>= 3.0.0),
aws.s3 (>= 0.3.21),
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ S3method(store_new,qs)
S3method(store_new,rds)
S3method(store_new,torch)
S3method(store_new,url)
S3method(store_path_from_record,default)
S3method(store_path_from_record,tar_external)
S3method(store_produce_path,default)
S3method(store_produce_path,tar_aws)
S3method(store_produce_path,tar_store_file)
Expand All @@ -115,6 +117,8 @@ S3method(store_read_path,tar_rds)
S3method(store_read_path,tar_store_file)
S3method(store_read_path,tar_torch)
S3method(store_read_path,tar_url)
S3method(store_row_path,default)
S3method(store_row_path,tar_external)
S3method(store_serialize_object,default)
S3method(store_serialize_object,tar_keras)
S3method(store_serialize_object,tar_torch)
Expand Down Expand Up @@ -248,6 +252,8 @@ export(starts_with)
export(tar_bind)
export(tar_branches)
export(tar_cancel)
export(tar_config_get)
export(tar_config_set)
export(tar_cue)
export(tar_deduplicate)
export(tar_delete)
Expand All @@ -257,6 +263,7 @@ export(tar_destroy)
export(tar_dir)
export(tar_edit)
export(tar_envir)
export(tar_envvars)
export(tar_exist_meta)
export(tar_exist_objects)
export(tar_exist_process)
Expand Down Expand Up @@ -371,3 +378,4 @@ importFrom(withr,local_envvar)
importFrom(withr,local_options)
importFrom(withr,with_dir)
importFrom(withr,with_seed)
importFrom(yaml,read_yaml)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* Add new "summary" and "about" views to `tar_watch()` (#382).
* Implement `tar_poll()` to repeatedly poll runtime progress in the R console (#381). `tar_poll()` is a lightweight alternative to `tar_watch()`.
* Change the color of the "dormant" status in the graph.
* Add a `tar_envvar()` function to list values of special environment variables supported in `targets`. The help file explains each environment variable in detail.
* Support extra project-level configuration settings with `_targets.yaml` (#297). New functions `tar_config_get()` and `tar_config_set()` interact with the `_targets.yaml` file. Currently only supports the `store` field to set the data store path to something other than `_targets/`.

## Performance

Expand Down
14 changes: 7 additions & 7 deletions R/class_aws.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# Semi-automated tests of Amazon S3 integration live in tests/aws/. # nolint
# These tests should not be fully automated because they
# automatically create S3 buckets and upload data,
# which could put an unexpected and unfair burden on
# external contributors from the open source community.
# nocov start
#' @export
store_produce_path.tar_aws <- function(store, name, object) {
bucket <- store$resources$bucket
assert_nonempty(bucket, "S3 bucket name cannot be empty.")
assert_chr(bucket, "S3 bucket name must be character.")
assert_scalar(bucket, "invalid S3 bucket name.")
assert_nzchar(bucket, "invalid S3 bucket name.")
prefix <- store$resources$prefix %|||% path_objects_dir()
prefix <- store$resources$prefix %|||% path_objects_dir_cloud()
assert_nonempty(prefix, "S3 object prefix cannot be empty.")
assert_chr(prefix, "invalid S3 prefix.")
assert_scalar(prefix, "invalid S3 prefix.")
Expand All @@ -20,6 +14,12 @@ store_produce_path.tar_aws <- function(store, name, object) {
c(bucket, object)
}

# Semi-automated tests of Amazon S3 integration live in tests/aws/. # nolint
# These tests should not be fully automated because they
# automatically create S3 buckets and upload data,
# which could put an unexpected and unfair burden on
# external contributors from the open source community.
# nocov start
#' @export
store_produce_stage.tar_aws <- function(store, name, object) {
tempfile(pattern = name)
Expand Down
8 changes: 7 additions & 1 deletion R/class_aws_feather.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ aws_feather_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_feather", "tar_aws", "tar_feather", "tar_store")
c(
"tar_aws_feather",
"tar_aws",
"tar_external",
"tar_feather",
"tar_store"
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_file_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_file", "tar_aws", "tar_store_file", "tar_store")
c("tar_aws_file", "tar_aws", "tar_external", "tar_store_file", "tar_store")
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_fst.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_fst_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_fst", "tar_aws", "tar_fst", "tar_store")
c("tar_aws_fst", "tar_aws", "tar_external", "tar_fst", "tar_store")
)
}

Expand Down
1 change: 1 addition & 0 deletions R/class_aws_fst_dt.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ aws_fst_dt_new <- function(file = NULL, resources = NULL) {
c(
"tar_aws_fst_dt",
"tar_aws",
"tar_external",
"tar_fst_dt",
"tar_fst",
"tar_store"
Expand Down
1 change: 1 addition & 0 deletions R/class_aws_fst_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ aws_fst_tbl_new <- function(file = NULL, resources = NULL) {
c(
"tar_aws_fst_tbl",
"tar_aws",
"tar_external",
"tar_fst_tbl",
"tar_fst",
"tar_store"
Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_keras_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_keras", "tar_aws", "tar_keras", "tar_store")
c("tar_aws_keras", "tar_aws", "tar_external", "tar_keras", "tar_store")
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_parquet_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_parquet", "tar_aws", "tar_parquet", "tar_store")
c("tar_aws_parquet", "tar_aws", "tar_external", "tar_parquet", "tar_store")
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_qs.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_qs_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_qs", "tar_aws", "tar_qs", "tar_store")
c("tar_aws_qs", "tar_aws", "tar_external", "tar_qs", "tar_store")
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_rds.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_rds_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_rds", "tar_aws", "tar_rds", "tar_store")
c("tar_aws_rds", "tar_aws", "tar_external", "tar_rds", "tar_store")
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/class_aws_torch.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws_torch_new <- function(file = NULL, resources = NULL) {
force(resources)
enclass(
environment(),
c("tar_aws_torch", "tar_aws", "tar_torch", "tar_store")
c("tar_aws_torch", "tar_aws", "tar_external", "tar_torch", "tar_store")
)
}

Expand Down
111 changes: 111 additions & 0 deletions R/class_config.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
config_init <- function(path = tempfile()) {
config_new(path = path)
}

config_new <- function(
path = NULL,
data = NULL,
time = NULL,
lock = NULL
) {
config_class$new(
path = path,
data = data,
time = time,
lock = lock
)
}

config_class <- R6::R6Class(
classname = "tar_config",
class = FALSE,
portable = FALSE,
cloneable = FALSE,
public = list(
path = NULL,
data = NULL,
time = NULL,
lock = NULL,
initialize = function(
path = NULL,
data = NULL,
time = NULL,
lock = NULL
) {
self$path <- path
self$data <- data
self$time <- time
self$lock <- lock
},
set_lock = function() {
self$lock <- TRUE
},
unset_lock = function() {
self$lock <- FALSE
},
is_unlocked = function() {
!identical(self$lock, TRUE)
},
path_exists = function() {
file.exists(self$path)
},
produce_time = function() {
if_any(self$path_exists(), file.mtime(self$path), NULL)
},
read = function() {
as.list(yaml::read_yaml(self$path))
},
load = function() {
if (self$is_unlocked()) {
self$data <- self$read()
self$time <- self$produce_time()
}
},
write = function() {
if (self$is_unlocked()) {
tmp <- tempfile()
yaml::write_yaml(x = self$data, file = tmp)
file.rename(from = tmp, to = self$path)
}
invisible()
},
unload = function() {
if (self$is_unlocked()) {
self$data <- NULL
self$time <- NULL
}
},
update = function() {
if_any(self$path_exists(), self$load(), self$unload())
},
outdated = function() {
!identical(self$time, self$produce_time())
},
ensure = function() {
if (self$outdated()) {
self$update()
}
},
get_store = function() {
self$ensure()
self$data$store
},
set_store = function(store) {
self$ensure()
if (self$is_unlocked()) {
self$data$store <- store
}
self$write()
},
validate = function() {
assert_chr(self$path %|||% "")
assert_scalar(self$path %|||% "")
assert_list(self$data %|||% list())
if (!is.null(self$time)) {
assert_inherits(self$time, "POSIXct")
}
}
)
)

tar_config <- config_init(path = "_targets.yaml")
9 changes: 9 additions & 0 deletions R/class_external.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' @export
store_row_path.tar_external <- function(store) {
store$file$path
}

#' @export
store_path_from_record.tar_external <- function(store, record) {
record$path
}
4 changes: 1 addition & 3 deletions R/class_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ meta_class <- R6::R6Class(
memory_get_object(self$depends, name)
},
get_record = function(name) {
row <- self$database$get_row(name)
row <- lapply(row, unlist)
do.call(record_init, row)
record_from_row(self$database$get_row(name))
},
set_record = function(record) {
self$database$set_row(record_produce_row(record))
Expand Down
2 changes: 1 addition & 1 deletion R/class_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pipeline_validate_conflicts <- function(pipeline) {
". Suppress this warning with Sys.setenv(TAR_WARN = \"false\") ",
"in _targets.R."
)
if (length(conflicts) && Sys.getenv("TAR_WARN") != "false") {
if (length(conflicts) && !identical(Sys.getenv("TAR_WARN"), "false")) {
warn_validate(msg)
}
}
Expand Down
14 changes: 13 additions & 1 deletion R/class_record.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ record_produce_row <- function(record) {
command = record$command,
depend = record$depend,
seed = record$seed,
path = list(record$path),
path = list(record_row_path(record)),
time = record$time,
size = record$size,
bytes = record$bytes,
Expand All @@ -114,6 +114,18 @@ record_produce_row <- function(record) {
)
}

record_row_path <- function(record) {
store <- store_init(record$format)
store$file$path <- record$path
store_row_path(store)
}

record_from_row <- function(row) {
record <- do.call(record_init, lapply(row, unlist))
record$path <- store_path_from_record(store_init(record$format), record)
record
}

record_encode_field <- function(field) {
if (!length(field) || anyNA(field)) {
return(NA_character_)
Expand Down
18 changes: 18 additions & 0 deletions R/class_store.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ store_produce_path.default <- function(store, name, object) {
path_objects(name)
}

store_row_path <- function(store) {
UseMethod("store_row_path")
}

#' @export
store_row_path.default <- function(store) {
NA_character_
}

store_path_from_record <- function(store, record) {
UseMethod("store_path_from_record")
}

#' @export
store_path_from_record.default <- function(store, record) {
path_objects(record$name)
}

store_update_stage <- function(store, name, object) {
store$file$stage <- store_produce_stage(store, name, object)
}
Expand Down
Loading