-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
109 lines (84 loc) · 2.39 KB
/
README.Rmd
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
101
102
103
104
105
106
107
108
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "",
fig.path = "README-"
)
library("data.tree")
# Adapted from https://stackoverflow.com/questions/14188197/representing-a-directory-tree-as-a-recursive-list
tree_list <- function(x) {
if(grepl("/packrat$", x)) return(list(" ..." = list()))
if(grepl("/\\.git$", x)) return(list(" ..." = list()))
isdir <- file.info(x)$isdir
if(!isdir) {
out <- list()
} else {
files <- list.files(
x
, full.names = TRUE
, include.dirs = FALSE
, all.files = TRUE
)
dirs <- list.dirs(
x
, full.names = TRUE
, recursive = FALSE
)
files <- files[!files %in% dirs]
files <- c(
dirs[!grepl("^\\.", basename(dirs))]
, dirs[grepl("^\\.", basename(dirs))]
, files[!grepl("^\\.", basename(files))]
, files[grepl("^\\.", basename(files))]
)
files <- files[!grepl("\\.$", files)]
if(length(files) > 0) {
out <- lapply(files, tree_list)
isdir <- sapply(files, function(x) file.info(x)$isdir)
names(out) <- basename(files)
names(out)[isdir] <- paste0(names(out)[isdir], "/")
} else {
out <- list(NULL)
names(out) <- paste0(basename(files), "/")
}
}
out
}
```
# template
`template` contains functions to initialize a new project according to my needs.
## Installation
You can install `template` from github with:
```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("crsh/template")
```
## Example
To set up a new project repository using our standard project structure see `init_project()`:
```{r init-project, results = "hide", message = FALSE}
library("template")
# Set up project structure in temporary directory
tmp_dir <- tempfile("template-")
init_project(
x = "myproject"
, path = tmp_dir
)
project_path <- file.path(tmp_dir, "myproject")
# Start another study
add_study(x = "myproject", path = project_path)
# Start new manuscript
add_paper(
x = project_path
, shorttitle = "myproject-paper"
)
```
The resulting directory structure is looks like this:
```{r print-directory-structure, echo = FALSE}
project_structure <- tree_list(tmp_dir)
project_structure <- as.Node(project_structure)
print(project_structure$children$`myproject/`)
```