-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathtar_source.Rd
89 lines (85 loc) · 2.67 KB
/
tar_source.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tar_source.R
\name{tar_source}
\alias{tar_source}
\title{Run R scripts.}
\usage{
tar_source(
files = "R",
envir = targets::tar_option_get("envir"),
change_directory = FALSE
)
}
\arguments{
\item{files}{Character vector of file and directory paths
to look for R scripts to run. Paths must either be absolute
paths or must be relative to the current working directory
just before the function call.}
\item{envir}{Environment to run the scripts. Defaults to
\code{tar_option_get("envir")}, the environment of the pipeline.}
\item{change_directory}{Logical, whether to temporarily change
the working directory to the directory of each R script
before running it.}
}
\value{
\code{NULL} (invisibly)
}
\description{
Run all the R scripts in a directory
in the environment specified.
}
\details{
\code{tar_source()} is a convenient way to load R scripts
in \verb{_targets.R} to make custom functions available to the pipeline.
\code{tar_source()} recursively looks for files ending
in \code{.R} or \code{.r}, and it runs each with
\code{eval(parse(text = readLines(script_file, warn = FALSE)), envir)}.
}
\section{Storage access}{
Several functions like \code{tar_make()}, \code{tar_read()}, \code{tar_load()},
\code{tar_meta()}, and \code{tar_progress()} read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the \code{tarchetypes} package such as \code{tar_render()}
and \code{tar_quarto()}.
}
\examples{
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
# Running in tar_dir(), these files are written in tempdir().
dir.create("R")
writeLines("f <- function(x) x + 1", file.path("R", "functions.R"))
tar_script({
tar_source()
list(tar_target(x, f(1)))
})
tar_make()
tar_read(x) # 2
})
}
}
\seealso{
Other utilities:
\code{\link{tar_active}()},
\code{\link{tar_backoff}()},
\code{\link{tar_call}()},
\code{\link{tar_cancel}()},
\code{\link{tar_definition}()},
\code{\link{tar_described_as}()},
\code{\link{tar_envir}()},
\code{\link{tar_format_get}()},
\code{\link{tar_group}()},
\code{\link{tar_name}()},
\code{\link{tar_path}()},
\code{\link{tar_path_script}()},
\code{\link{tar_path_script_support}()},
\code{\link{tar_path_store}()},
\code{\link{tar_path_target}()},
\code{\link{tar_store}()},
\code{\link{tar_unblock_process}()}
}
\concept{utilities}