Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (66 sloc) 3.279 kb
fa3ccdc @trinker reloaded
authored
1 #' Document Template
2 #'
510304b @trinker documentation update
authored
3 #' This function generates a document template for personal use or submission to
4 #' the reports package to be included as a template in the doc_library. This
5 #' function is similar to \code{\link[utils]{package.skeleton}}.
fa3ccdc @trinker reloaded
authored
6 #'
7 #' @param temp.name The name of the template.
8 #' @param doc.type The type of report that the template will contain
8c406fc @trinker removed web and replaced with rmd
authored
9 #' (\code{"doc", "rnw", "tex" or "rmd"}). \code{"doc"} will contain a .docx
115df38 @trinker added a web template.
authored
10 #' document; \code{"rnw" and "tex"} contain both \code{doc.rnw}/\code{doc.tex} and
8c406fc @trinker removed web and replaced with rmd
authored
11 #' \code{preamble.tex} files; whereas \code{"rmd"} contains \code{doc.rmd}/.
fa3ccdc @trinker reloaded
authored
12 #' @param path The path to where the project should be created. Default is the
13 #' current working directory.
14 #' @details templates must contain the following two items:
15 #' \itemize{
16 #' \item{DESCRIPTION}{ - A file used to keep track of users and package
17 #' information. All fields must be filled in.}
18 #' \item{documents}{ - A minimal working document template.}
19 #' \itemize{
20 #' \item{If \code{doc.type = rnw}}{ - Must contain: doc.rnw (preamble included)}
21 #' \item{If \code{doc.type = tex}}{ - Must contain: doc.tex and preamble.tex}
115df38 @trinker added a web template.
authored
22 #' \item{If \code{doc.type = rmd}}{ - Must contain: doc.rmd}
fa3ccdc @trinker reloaded
authored
23 #' \item{If \code{doc.type = docx}}{ - Must contain: doc.docx}
24 #' }
25 #' }
c038dfb @trinker new_report now moves the css file to REPORT
authored
26 #' Additional project files and directories can be stored in the \bold{inst}
669386d @trinker updated reports including the bug in the ligiture warning
authored
27 #' directory. Files in this directory will be placed in the main directory of the
c038dfb @trinker new_report now moves the css file to REPORT
authored
28 #' template created by \code{\link[reports]{new_report}}. If a directory called
29 #' \bold{css} this directory will be moved to the \bold{REPORT} directory rather
30 #' than the main directory.
fa3ccdc @trinker reloaded
authored
31 #'
669386d @trinker updated reports including the bug in the ligiture warning
authored
32 #' To be submitted a .tex template must run in Debian TeX Live on Linux Mint and
33 #' MiKTex on Windows. After a template has been tested it can be sent as a
c350257 @trinker added internal style.css for use
authored
34 #' .zip file to the reports package \email{reports.rpackage@@gmail.com}. Please
35 #' note that the template folder/directory name must end in _tex, _rnw, _rmd or
36 #' _doc to indicate to the user the type of template.
fa3ccdc @trinker reloaded
authored
37 #' @return Creates a document template framework for template personal use or
38 #' submission.
39 #' @export
40 doc_temp <-
fa67653 @trinker Added the QP function for quick and safe path referencing.
authored
41 function(temp.name = "newDoc", doc.type = "rnw", path = getwd()) {
93a8148 @trinker fixed typos
authored
42
c038dfb @trinker new_report now moves the css file to REPORT
authored
43 if (!any(doc.type %in% c("doc", "rnw", "tex", "rmd"))) {
93a8148 @trinker fixed typos
authored
44 stop("doc.type must be one of the following: \"doc\", \"rnw\", \"tex\" or \"rmd\"")
45 }
23bb4aa @trinker removed unnecessary cats and replaced with message
authored
46
fa3ccdc @trinker reloaded
authored
47 tn <- paste0(temp.name, "_", doc.type)
23bb4aa @trinker removed unnecessary cats and replaced with message
authored
48
fa3ccdc @trinker reloaded
authored
49 if(file.exists(file.path(path, tn))) {
23bb4aa @trinker removed unnecessary cats and replaced with message
authored
50 message(paste0("\"", file.path(path, tn),
c038dfb @trinker new_report now moves the css file to REPORT
authored
51 "\" already exists:\nDo you want to overwrite?\n"))
fa3ccdc @trinker reloaded
authored
52 ans <- menu(c("Yes", "No"))
53 if (ans == "2") {
54 stop("doc_temp aborted")
55 } else {
56 delete(file.path(path, tn))
57 }
58 }
59 x <- folder(folder.name = tn)
60 root <- system.file(paste0("extdata/doc_temp/", doc.type),
61 package = "reports")
62 fls <- file.path(root, dir(root))
63 invisible(file.copy(file.path(root, dir(root)), x))
80fe0dd @trinker updated READme, fixed bug in reveal.js
authored
64 desc <- suppressWarnings(readLines(file.path(x, "DESCRIPTION")))
fa3ccdc @trinker reloaded
authored
65 desc[1:2] <- c(paste("Template:", temp.name), paste0(desc[2], Sys.Date()))
66 cat(paste(desc, collapse="\n"), file=file.path(x, "DESCRIPTION"))
67 folder(folder.name = file.path(tn, "inst"))
23bb4aa @trinker removed unnecessary cats and replaced with message
authored
68 message(paste0("template created:\n", x, "\n"))
b32be42 @trinker fixed final line warning devtools throws
authored
69 }
Something went wrong with that request. Please try again.