if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, 1))
}, ask = FALSE)
tar_make()
# Get the timestamp.
tar_timestamp(x)
# We can use the timestamp to cancel the target
# if it already ran within the last hour.
# Be sure to set `cue = tar_cue(mode = "always")`
# if you want the target to always check the timestamp.
tar_script({
list(
tar_target(
x,
tar_cancel((Sys.time() - tar_timestamp()) < 3600),
cue = tar_cue(mode = "always")
)
)}, ask = FALSE)
tar_make()
})
}
Run the code above in your browser using DataLab