file_new: Create a new file

Description Usage Arguments Value Examples

View source: R/func_files.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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")

}

jdtrat/jdtools documentation built on Dec. 20, 2021, 10:05 p.m.