Skip to content

Commit 1bb296a

Browse files
Choose template according to script name. Closes #16
1 parent 533d1e8 commit 1bb296a

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

R/scripts.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
#' (optional) name of the script to create and/or open. This parameter can also include
88
#' the subfolder where to save the script (see examples).
99
#' @param template
10-
#' One of "analysis", "data" or "function". For new scripts, template to use.
11-
#' prScript adds a few comments that encourage you to add comments and explain
12-
#' what the script will do. These comments depend on the choosen template.
10+
#' (Optional) One of "analysis", "data" or "function". Template to use for the
11+
#' creation of a script. \code{prScript} adds a few comments that encourage the user to add
12+
#' comments and explain what the script will do. These comments depend on the
13+
#' choosen template. If the argument is missing, the choosen template depends
14+
#' on the name of the script: "data" if the name begins with "data", "function"
15+
#' if it start with "tools" and "analysis" in all other cases.
1316
#' @param subdir
1417
#' subdirectory where the scripts needs to be created or opened. The
1518
#' subdirectory can also be directly specified in the parameter \code{name}.
@@ -39,7 +42,13 @@
3942
#'
4043
#' @export
4144
#'
42-
prScript <- function(name, template=c("analysis", "data", "function"), subdir = ".") {
45+
prScript <- function(name, template, subdir = ".") {
46+
if (missing(template)) {
47+
if (grepl("^data", name, ignore.case = TRUE)) template <- "data"
48+
else if (grepl("^tools", name, ignore.case = TRUE)) template <- "function"
49+
else template <- "analysis"
50+
}
51+
4352
template <- match.arg(template[1],
4453
c("analysis", "data", "function", "main", "start"))
4554

inst/scriptTemplates/analysis.brew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
#////////
66
# GOAL:
7-
# what is the goal of this project ?
7+
# what is the question this script tries to answer ?
88
#
99
#////////
1010
# APPROACH:

inst/scriptTemplates/data.brew

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#
99
#////////
1010
# OUTPUT:
11-
# what objects will the script create ?
11+
# what data objects will the script create ?
1212
#
1313
#////////
1414
# DETAILS:
15-
# Anything else ?
15+
# Anything else ? Where did you get the data ? Did you do some manual
16+
# transformation ?
1617
#
1718
#///////////////////////////////////////////////////////////////////////////////
1819

inst/scriptTemplates/function.brew

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
#////////
66
# DESCRIPTION:
7-
# what do the function ?
7+
# what does the function do ?
88
#
99
#////////
1010
# ARGS:
@@ -14,7 +14,7 @@
1414
#
1515
#////////
1616
# RETURNS:
17-
# Anything else ?
17+
# what is the result of the function ?
1818
#
1919
#////////
2020
# EXAMPLES:

inst/scriptTemplates/start.brew

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
# This script is sourced when you open the project. Load libraries with
66
# "prLibrary". Load data with "prLoad" and source files with "prSource".
77
#
8-
#////////
9-
# DETAILS:
10-
# Anything special ?
11-
#
128
#///////////////////////////////////////////////////////////////////////////////
139

1410

0 commit comments

Comments
 (0)