wflow_open opens R Markdown files in RStudio and sets the working directory to the knit directory (see Details). If a file does not exist, a minimal one is created.

wflow_open(files, change_wd = TRUE, edit_in_rstudio = TRUE, project = ".")

Arguments

files

character. R Markdown file(s) to open. Files must have the extension Rmd or rmd. Supports file globbing. Set project = NULL to create an R Markdown file outside of the R Markdown directory of a workflowr project.

change_wd

logical (default: TRUE). Change the working directory to the knit directory. If project = NULL, the working directory is not changed.

edit_in_rstudio

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

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

An object of class wflow_open, which is a list with the following elements:

files

The input argument files as absolute paths.

change_wd

The input argument change_wd.

edit_in_rstudio

The input argument edit_in_rstudio.

knit_root_dir

The knit directory (see wflow_html for details). This is NULL if project was set to NULL.

previous_wd

The working directory in which wflow_open was executed.

new_wd

The working directory that wflow_open changed to. The value is NULL if the working directory was not changed.

files_new

The subset of the input argument files that were newly created. Paths are absolute.

Details

wflow_open is a convenience function to make it easier to begin working, especially when starting a new analysis. First, it creates a new file if necessary and tries to make educated guesses about metadata like the title, author, and date. Second, it sets the working directory to the knit directory. The knit directory is where the code in the R Markdown files is executed, and may be defined via the field knit_root_dir in the file _workflowr.yml (see wflow_html for all the details). If this field is not defined, then the knit directory is the R Markdown directory. Third, it opens the file(s) in RStudio if applicable. The latter two side effects can be turned off if desired.

If you would like to create an R Markdown file with wflow_open for an analysis that is not part of a workflowr project, set project = NULL. Otherwise wflow_open will throw an error. Note that the working directory is not changed when project = NULL.

Examples

if (FALSE) {
wflow_open("analysis/model-data.Rmd")
# Multiple files
wflow_open(c("analysis/model-data.Rmd", "analysis/another-analysis.Rmd"))
# Open all R Markdown files
wflow_open("analysis/*Rmd")
# Create an R Markdown file in a non-worklowr project
wflow_open("model-data.Rmd", project = NULL)
}