Copy shared resources into a packet directory. You can use this to
share common resources (data or code) between multiple packets.
Additional metadata will be added to keep track of where the files
came from. Using this function requires the shared resources
directory shared/
exists at the orderly root; an error will be
raised if this is not configured when we attempt to fetch files.
Arguments
- ...
The shared resources to copy. If arguments are named, the name will be the destination file while the value is the filename within the shared resource directory.
You can use a limited form of string interpolation in the names of this argument; using
${variable}
will pick up values fromenvir
and substitute them into your string. This is similar to the interpolation you might be familiar with fromglue::glue
or similar, but much simpler with no concatenation or other fancy features supported.
Value
Invisibly, a data.frame with columns here
(the filenames
as as copied into the running packet) and there
(the filenames
within shared/
). Do not rely on the ordering where directory
expansion was performed.
Examples
# An example in context within the orderly examples:
orderly_example_show("shared")
#>
#> ── src/shared/shared.R ─────────────────────────────────────────────────────────
#> # Pull in the file 'shared/palette.R' as 'cols.R'
#> orderly_shared_resource(cols.R = "palette.R")
#>
#> # Then source it, as usual
#> source("cols.R")
#>
#> # And use the function 'palette()' found within
#> png("volcano.png")
#> image(volcano, col = palette())
#> dev.off()
# Here's the directory structure for this example:
path <- orderly_example(names = "shared")
#> ✔ Created orderly root at '/tmp/Rtmp3NBL3X/orderly2_ex_1cf169e85324'
fs::dir_tree(path)
#> /tmp/Rtmp3NBL3X/orderly2_ex_1cf169e85324
#> ├── orderly_config.yml
#> ├── shared
#> │ └── palette.R
#> └── src
#> └── shared
#> └── shared.R
# We can run this packet:
orderly_run("shared", root = path)
#> ℹ Starting packet 'shared' `20250807-155627-ea5935ed` at 2025-08-07 15:56:27.919771
#> > # Pull in the file 'shared/palette.R' as 'cols.R'
#> > orderly_shared_resource(cols.R = "palette.R")
#> > # Then source it, as usual
#> > source("cols.R")
#> > # And use the function 'palette()' found within
#> > png("volcano.png")
#> > image(volcano, col = palette())
#> > dev.off()
#> agg_record_896085249
#> 2
#> ✔ Finished running shared.R
#> ℹ Finished 20250807-155627-ea5935ed at 2025-08-07 15:56:27.965104 (0.04533291 secs)
#> [1] "20250807-155627-ea5935ed"
# In the final archive version of the packet, 'cols.R' is copied
# over from `shared/`, so we have a copy of the version of the code
# that was used in the analysis
fs::dir_tree(path)
#> /tmp/Rtmp3NBL3X/orderly2_ex_1cf169e85324
#> ├── archive
#> │ └── shared
#> │ └── 20250807-155627-ea5935ed
#> │ ├── cols.R
#> │ ├── shared.R
#> │ └── volcano.png
#> ├── draft
#> │ └── shared
#> ├── orderly_config.yml
#> ├── shared
#> │ └── palette.R
#> └── src
#> └── shared
#> └── shared.R