proj_workflow_use_rmd: Use opinionated Rmd template

View source: R/workflow.R

proj_workflow_use_rmdR Documentation

Use opinionated Rmd template

Description

Use this function to create a new, templated RMarkdown file in a workflow directory. It is mandatory to provide a name. However, the path_proj can be omitted if you have an RMarkdown file from your project open and active in the RStudio IDE; it will use the directory of that file.

Usage

proj_workflow_use_rmd(
  name,
  path_proj = NULL,
  open = rlang::is_interactive(),
  ignore = FALSE
)

Arguments

name

character name of the workflow component.

path_proj

character path to workflow directory, relative to the project directory.

open

logical indicates to open the file for interactive editing.

ignore

logical indicates to add this file to .Rbuildignore.

Details

This is an opinionated system; it introduces restrictions to help keep you "inside the boat":

  • All the RMarkdown files in a workflow are in the same directory; there are no sub-directories with RMarkdown files.

  • Using here::i_am() establishes the root of the workflow as the directory that contains the RMarkdown file. In other words, when the RMarkdown file is rendered, this directory becomes the here::here() root. Also, using here::i_am(), it provides a unique identifier for this file, which will make a stronger guarantee that any rendering of this file happens from inside this workflow directory.

  • It creates a dedicated data-directory for this file to write to, making sure that this data-directory is empty at the start of the rendering. It also provides an accessor function path_target() that you can use later in the file to compose paths to this data-directory. For example:

    write.csv(mtcars, path_target("mtcars.csv"))
    

    It also provides an accessor function to the data directory itself, which can be useful for reading data from "previous" files.

    fun_data <- read.csv(path_data("00-import", "fun_data.csv"))
    

These opinionated features can help you access your data more easily, while helping to keep you "safely inside the boat".

Value

Invisible NULL, called for side effects.

Examples

# not run because it creates side effects
## Not run: 
  # creates file `01-clean.Rmd`
  proj_workflow_use_rmd("01-clean")

## End(Not run)

ijlyttle/projthis documentation built on Aug. 18, 2022, 11:25 a.m.