Skip to content

Commit

Permalink
refactoring + add better doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Feb 17, 2020
1 parent 7aca2af commit aaf845a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
28 changes: 13 additions & 15 deletions R/create_temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@
#' @param template which template to use?
#'
#' @details
#' The available templates are: \emph{united_html} (default).
#' The name of the main \code{.Rmd} file will be \emph{test.Rmd}.
#' The available templates are: \emph{united_html} (default), \emph{bookdown_lite}.
#' The name of the main \code{.Rmd} file will be \emph{index.Rmd}.
#'
#' @examples
#' \dontrun{
#' create_rtemp(dirname = "tmp_dir", format = "united_html")
#' create_rtemp(dirname = "tmp_dir", template = "united_html")
#' }
#'
#' @export
create_rtemp = function(dirname = "new-dir", template = "united_html") {
templates = c("united_html")
# check input
templates = c("united_html", "bookdown_lite")
temp = match.arg(template, templates)

# create directory
if (dir.exists(dirname)) {
stop(paste0("There is already a directory `", dirname,
"`. Please supply a different directory name"))
"`. Please specify a different directory name"))
}

dir.create(dirname)

file.copy(
system.file(file.path("rmarkdown", "templates", temp, "skeleton", "skeleton.Rmd"), package = "rtemps"),
file.path(dirname)
)
file.copy(
system.file(file.path("rmarkdown", "templates", temp, "skeleton", "style.css"), package = "rtemps"),
file.path(dirname)
)
# copy files from template directory
template.dir = system.file(file.path("rmarkdown", "templates", temp, "skeleton"), package = "rtemps")
files.to.copy = list.files(template.dir)
file.copy(file.path(template.dir, files.to.copy),
file.path(dirname), recursive = TRUE)

file.rename(file.path(dirname, "skeleton.Rmd"), file.path(dirname, "test.Rmd"))
file.rename(file.path(dirname, "skeleton.Rmd"), file.path(dirname, "index.Rmd"))
}

6 changes: 3 additions & 3 deletions man/create_rtemp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaf845a

Please sign in to comment.