-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.R
100 lines (81 loc) · 3.16 KB
/
template.R
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#' Project templates
#' @description Generate a project template directory.
#' @param project_name project name/title
#' @param path target file path for project directory
#' @param type project type. Should be one returned by \code{projectTypes()}.
#' @param renv add renv infrastructure for reproducible a R package environment
#' @param docker TRUE/FALSE. Create project infrastructure for building a docker container to compile the project.
#' @param git TRUE/FALSE. Initialise a Git repository?
#' @param github TRUE/FALSE. Create a GitHub repository? Ignored if argument \code{git} is FALSE.
#' @param private TRUE/FALSE. Should the GitHub repository be private? Evaluated only if arguments \code{git} and \code{github} are TRUE.
#' @param github_actions TRUE/FALSE. Add Github actions infrastructure? Evaluated only if arguments \code{git}, \code{github} and \code{docker} are TRUE.
#' @param force force project creation if project directory already exists
#' @param start TRUE/FALSE. Should the project be automatically activated in a new RStudio session?
#' @importFrom rstudioapi openProject
#' @examples
#' \dontrun{
#' template('A new project',
#' type = 'report',
#' github = FALSE,
#' start = FALSE)
#' }
#' @export
template <- function(project_name,
path = '.',
type = projectTypes(),
renv = TRUE,
docker = TRUE,
git = TRUE,
github = FALSE,
private = FALSE,
github_actions = FALSE,
force = FALSE,
start = TRUE){
type <- match.arg(type,
choices = projectTypes())
project_directory <- projectDirectory(project_name,path)
projectSkeleton(project_directory,force = force)
readme(project_name,path,type,renv)
targets(project_directory,
type = type,
renv = renv)
Rprofile(project_directory,
renv = renv)
utils(str_c(project_directory,'/R'))
output(project_name,project_directory,type)
if(isTRUE(renv)){
renvInitialise(project_directory,
dependencies = githubPackages(type))
}
if(isTRUE(docker)){
docker(project_name,type,path,renv)
}
if (all(git,github,docker,github_actions)){
githubActions(project_name,path)
}
if (isTRUE(git)) {
createGit(project_directory,type)
}
if (all(git,github)) {
createGithub(project_name,path,private)
}
message(glue('Template output complete. See {project_directory}/README.md for details on how to get started.'))
if (isTRUE(start) & isAvailable()) {
message('Opening project in a new RStudio session')
openProject(project_directory,newSession = TRUE)
}
}
#' Available project types
#' @description Available project types within the projecttemplates package
#' @examples
#' projectTypes()
#' @export
projectTypes <- function(){
c('report','manuscript','presentation')
}
githubPackages <- function(type){
switch(type,
report = 'jasenfinch/jfmisc',
presentation = 'jasenfinch/jfmisc',
manuscript = 'jasenfinch/jfmisc')
}