Learn R Programming

mindr (version 1.3.2)

dir2r: Convert a hierarchical directory into R code

Description

Convert a hierarchical directory into R code

Usage

dir2r(
  from = ".",
  dir_files = TRUE,
  dir_all = TRUE,
  dir_excluded = NA,
  r_seclabel = " --------",
  r_chunkheading = FALSE
)

Arguments

from

Character. The source text of the (R) Markdown syntax text, the R code, the FreeMind mind map code, or the path to the directory.

dir_files

Logical. Whether to include files. If FALSE, only folders are included. If TRUE, folders and files are included.

dir_all

Logical. Whether to include all files in a directory. If FALSE, only the names of visible files are included (following Unix-style visibility, that is files whose name does not start with a dot). If TRUE, all file names will be included.

dir_excluded

Character. The directories which are not included in the output.

r_seclabel

Character. The ending characters indicating sections in R Markdown.

r_chunkheading

Logical. Whether process the chunk label as headings.

Value

Character, R code

Examples

Run this code
# NOT RUN {
input <- system.file(package = "mindr")
dir2r(input)
dir2r(input, dir_files = FALSE, dir_all = TRUE, dir_excluded = "Meta")

output_txt <- dir2r(input)
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(output_txt, output, useBytes = TRUE)
message("Input:  ", input, "\nOutput: ", output)
# system2('open', input) # Open the input dir in explorer.  file.show(output) #
# Open the output file file.remove(output) # remove the output file
# }

Run the code above in your browser using DataLab