These functions are inspired by usethis::use_r() to create .R files in the R/ directory for packages. Unlike use_r(), these functions allow you to pass in any path within your RStudio Project. It will then create and (optionally) open the file within RStudio.

There is both a generic file_new() function, which accepts paths and the file extension, as well as several utility functions that simply require a path. See usage or examples for more details.

file_new(path, ext, open = interactive())

file_new_r(path, open = interactive())

file_new_stan(path, open = interactive())

file_new_js(path, open = interactive())

file_new_css(path, open = interactive())

file_new_html(path, open = interactive())

file_new_text(path, open = interactive())

file_new_md(path, open = interactive())

file_new_rmd(path, open = interactive())

Arguments

path

A character vector of the file path to be created.

ext

The file extension, e.g. "R" or "Rmd" for .R and .Rmd files, respectively.

open

Logical: whether to open the file for editing. Default calls base::interactive().

Value

NA; used to create and (optionally) open a new file of the specified type.

Examples

if (interactive()) { # Create a new R file, specifying the extension file_new(path = "test-folder/test-file", ext = "R") # Create a new R file with the shortcut: file_new_r(path = "test-folder/test-file") # Create a new Stan file file_new(path = "test-folder/test-file", ext = "stan") # Alternatively: # file_new_stan(path = "test-folder/test-file") # Create a new JavaScript file file_new(path = "test-folder/test-file", ext = "js") # Alternatively: # file_new_js(path = "test-folder/test-file") # Create a new CSS file file_new(path = "test-folder/test-file", ext = "css") # Alternatively: # file_new_css(path = "test-folder/test-file") # Create a new HTML file file_new(path = "test-folder/test-file", ext = "html") # Alternatively: # file_new_html(path = "test-folder/test-file") # Create a new Text file file_new(path = "test-folder/test-file", ext = "txt") # Alternatively: # file_new_text(path = "test-folder/test-file") # Create a new Markdown file file_new(path = "test-folder/test-file", ext = "md") # Alternatively: # file_new_md(path = "test-folder/test-file") # Create a new RMarkdown file file_new(path = "test-folder/test-file", ext = "Rmd") # Alternatively: # file_new_rmd(path = "test-folder/test-file") }