This workflow philosophy relies on RMarkdown files being run in a defined sequence. It follows that an RMarkdown file should not read from the data written by another RMarkdown file written later in the sequence. These functions help you implement this idea.

These functions are function factories; they themselves return functions. You can use those returned functions to access paths.

To make things a little easier, the template used by proj_workflow_use_rmd() includes a calls to proj_path_source() and proj_path_target(), with the name argument populated.

proj_path_target(name)

proj_path_source(name)

Arguments

name

character name of the workflow component.

Value

function that acts like here::here(), returning a character path.

Details

Each RMarkdown file in the sequence has its own target directory, created using proj_create_dir_target(). Once a target directory is created, use these functions to create functions to access your target directory, or previous RMarkdown files' target directories (as sources).

For example, use proj_path_target() to create a path-generating function that uses your target directory. Whenever you need to provide a path to a file in your target directory, e.g. the file argument to write.csv(), use this path-generating function.

Similarly, you can use proj_path_source() to create a path-generating function for your source directories, which must be earlier in the workflow than your current RMarkdown file. The path-generating function ckecks that the source directory is, in fact, earlier in the workflow.

Examples

  # create path-generating functions
  path_target <- proj_path_target("01-clean")
  path_source <- proj_path_source("01-clean")

  # not run because they depend on side effects
  if (FALSE) {
  # use path-generating functions

  # returns full path to a file in one of your source directories
  path_source("00-import", "old-data.csv")

  # returns full path to a file in your target directory
  path_target("new-data.csv")
  }