Learn R Programming

workflowr (version 0.11.0)

wflow_open: Open R Markdown analysis file(s)

Description

wflow_open opens R Markdown files in RStudio and sets the working directory to the analysis directory. If a file does not exist, it is created using the workflowr R Markdown template.

Usage

wflow_open(files, change_wd = TRUE, open_file = TRUE, standalone = FALSE,
  project = ".")

Arguments

files

character. The name of the R Markdown file(s). If project points to a workflowr project (or any subdirectory) the file(s) will be saved in the analysis directory. Set project = NULL to override this default behavior. Files must have the extension Rmd or rmd. Supports file globbing.

change_wd

logical (default: TRUE). Change the working directory to the analysis directory. If project = NULL, change working directory to destination of first file in files.

open_file

logical (default: TRUE). Open the file in the RStudio editor.

standalone

logical (default: FALSE). Embed the configuration chunks directly in the document to create a standalone file. Should only need to be used when creating files outside the context of a workflowr project.

project

character (or NULL). By default the function assumes the current working directory is within the project. If this is not true, you'll need to provide the path to the project directory. Set project = NULL if running this command to create a file for a non-workflowr project.

Value

Invisibly returns the relative path(s) to the R Markdown file(s).

Details

wflow_open is a convenience function to make it easier to begin working, especially when starting a new analysis. It will create a new file if necessary using the workflowr template, set the working directory to the analysis directory, and open the file(s) in RStudio. The latter two side effects can be turned off if desired.

If you would like to create a file using the workflowr template for an analysis that is not part of a workflowr project, set standalone = TRUE to directly embed the shared configuration chunks into the document and set project = NULL to prevent wflow_open from searching for an analysis directory.

If you are not using RStudio and are comfortable with relative paths and managing your working directory, you could instead directly use the underlying commands. First set the working directory to the analysis directory of your workflowr project. Second create the new file with draft("model-data.Rmd", template = "analysis", package = "workflowr", edit = FALSE). Third open the file in your text editor.

Examples

Run this code
# NOT RUN {
# Any of the following are valid input. Files would be created if they did
# not exist.
# Basename of file:
wflow_open("model-data.Rmd")
# Path to file
wflow_open("analysis/model-data.Rmd")
# Multiple files
wflow_open(c("model-data.Rmd", "another-analysis.Rmd"))
# Use the workflowr template in a non-worklowr project
wflow_open("model-data.Rmd", standalone = TRUE, project = NULL)
# }

Run the code above in your browser using DataLab