Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 270 lines (242 sloc) 11.992 kB
532cbc4 @trinker added the project creation function
authored
1 #' Project Template
2 #'
3 #' Generate a project template to increase efficiency.
4 #'
5 #' @param project A character vector of the project name.
6 #' @param path The path to where the project should be created. Default is the
7 #' current working directory.
09e12eb @trinker updated version
authored
8 #' @param open logical. If \code{TRUE} the project will be opened in RStudio.
9 #' The default is to test if \code{new_project} is being used in the global
10 #' environment, if it is then the project directory will be opened.
11 #' @param github logical. If \code{TRUE} the repo will be sent to public
12 #' \href{https://github.com/}{GitHub} account.
4fbeb11 @trinker updated qdap with reports package
authored
13 #' @param \ldots Other arguments passed to \code{\link[reports]{new_report}}.
532cbc4 @trinker added the project creation function
authored
14 #' @details The project template includes these main directories and scripts:
15 #' \itemize{
51328e0 @trinker documentation
authored
16 #' \item{CODEBOOK}{ - A directory to store coding conventions or demographics data:
42292a4 @trinker added stuff
authored
17 #' \itemize{
bfb61b5 @trinker Updated new_project
authored
18 #' \item{KEY.csv}{ - A blank template for demographic information}
42292a4 @trinker added stuff
authored
19 #' }
20 #' }
cb1e0d6 @trinker added new workflow
authored
21 #' \item{CORRESPONDENCE}{ - A directory to store correspondence and agreements with the client:
42292a4 @trinker added stuff
authored
22 #' \itemize{
bfb61b5 @trinker Updated new_project
authored
23 #' \item{CONTACT_INFO.txt}{ - A text file to put research team members' contact information}
42292a4 @trinker added stuff
authored
24 #' }
25 #' }
bfb61b5 @trinker Updated new_project
authored
26 #' \item{DATA}{ - A directory to store data:}
cb1e0d6 @trinker added new workflow
authored
27 #' \itemize{
bfb61b5 @trinker Updated new_project
authored
28 #' \item{CLEANED_TRANSCRIPTS}{ - A directory to store the cleaned transcripts (If the transcripts are already cleaned you may choose to not utilize the RAW_TRANSCRIPTS directory)}
29 #' \item{CM_DATA}{ - A directory to export/import scripts for cm_xxx family of functions}
30 #' \item{DATA_FOR_REVIEW}{ - A directory to put data that may need to be altered or needs to be inspected more closely}
31 #' \item{RAW_DATA}{ - A directory to store non-transcript data related to the project:
32 #' \itemize{
33 #' \item{ANALYTIC_MEMOS}{ - A directory to put audio files (or shortcuts)}
34 #' \item{AUDIO}{ - A directory to put audio files (or shortcuts)}
35 #' \item{FIELD_NOTES}{ - A directory to put audio files (or shortcuts)}
36 #' \item{PAPER_ARTIFACTS}{ - A directory to put paper artifacts}
37 #' \item{PHOTOGRAPHS}{ - A directory to put photographs}
38 #' \item{VIDEO}{ - A directory to put video files (or shortcuts)}
39 #' }
40 #' }
41 #' \item{TRANSCRIPTS}{ - A directory to put transcription data:
42 #' \itemize{
43 #' \item{CLEANED_TRANSCRIPTS}{ - A directory to store the cleaned transcripts (If the transcripts are already cleaned you may choose to not utilize the RAW_TRANSCRIPTS directory)}
44 #' \item{RAW_TRANSCRIPTS}{ - A directory to store the raw transcripts}
45 #' }
cb1e0d6 @trinker added new workflow
authored
46 #' }
47 #' }
bfb61b5 @trinker Updated new_project
authored
48 #' \item{DOCUMENTATION}{ - A directory to store documents related to the project}
49 #' \item{PLOTS}{ - A directory to store plots}
4fbeb11 @trinker updated qdap with reports package
authored
50 #' \item{REPORTS}{ - A directory with report and presentation related tools. Please see the \cr \href{https://dl.dropbox.com/u/61803503/packages/REPORT_WORKFLOW_GUIDE.pdf}{REPORT_WORKFLOW_GUIDE.pdf} for more details}
5cb061c @trinker updated order in docuemntation for new_project
authored
51 #' \item{SCRIPTS}{ - A directory to store scripts; already contains the following:
52 #' \itemize{
53 #' \item{01_clean_data.R}{ - initial cleaning of raw transcripts}
54 #' \item{02_analysis_I.R}{ - initial analysis}
55 #' \item{03_plots.R}{ - plotting script}
56 #' }
57 #' }
532cbc4 @trinker added the project creation function
authored
58 #' \item{TABLES}{ - A directory to export tables to}
51328e0 @trinker documentation
authored
59 #' \item{WORD_LISTS}{ - A directory to store word lists that can be sourced and supplied to functions}
1156a0b @trinker rechecked functions for new upload to CRAN; fixed bugs
authored
60 #' \item{.Rprofile}{ - Performs certain tasks such as loading libraries, data and sourcing functions upon startup in \href{http://www.rstudio.com/}{RStudio}}
cb1e0d6 @trinker added new workflow
authored
61 #' \item{extra_functions.R}{ - A script to store user made functions related to the project
62 #' \itemize{
bfb61b5 @trinker Updated new_project
authored
63 #' \item{email}{ - A function to view, and optionally copy to the clipboard, emails for the client/lead researcher, analyst and/or other project members (information taking from ~/CORRESPONDENCE/CONTACT_INFO.txt file)}
64 #' \item{todo}{ - A function to view, and optionally copy to the clipboard, non-completed tasks from the \code{TO_DO.txt} file}
cb1e0d6 @trinker added new workflow
authored
65 #' }
66 #' }
8eaa0cf @trinker updated new_project to allow the directory to be transfered
authored
67 #' \item{LOG}{ - A text file documenting project changes/needs etc.}
5cb061c @trinker updated order in docuemntation for new_project
authored
68 #' \item{PROJECT_WORKFLOW_GUIDE.pdf}{ - A pdf explaining the structure of the project template}
bcb01b7 @trinker added some explicitness with what .Rpoj does
authored
69 #' \item{xxx.Rproj}{ - A project file used by \href{http://www.rstudio.com/}{RStudio}; clicking this will open the project in RStudio.}
8eaa0cf @trinker updated new_project to allow the directory to be transfered
authored
70 #' \item{TO_DO}{ - A text file documenting project tasks}
532cbc4 @trinker added the project creation function
authored
71 #' }
51328e0 @trinker documentation
authored
72 #'
1156a0b @trinker rechecked functions for new upload to CRAN; fixed bugs
authored
73 #' The template comes with a .Rproj file. This makes operating in
74 #' \href{http://www.rstudio.com/}{RStudio} very easy. The file can be kept on
75 #' the desktop or a git application such as \href{https://github.com/}{github},
51328e0 @trinker documentation
authored
76 #' \href{https://bitbucket.org/}{bitbucket} or \href{https://www.dropbox.com/}{dropbox},
77 #' depending on what the client/research team is comfortable utilizing.
78 #'
532cbc4 @trinker added the project creation function
authored
79 #' @return Creates a project template.
09e12eb @trinker updated version
authored
80 #' @keywords project, workflow, is.global
532cbc4 @trinker added the project creation function
authored
81 #' @export
bfb61b5 @trinker Updated new_project
authored
82 #' @importFrom reports delete folder new_report
3bcd00d @trinker updated
authored
83 #' @importFrom tools file_ext
09e12eb @trinker updated version
authored
84 new_project <- function(project = "new", path = getwd(),
bfb61b5 @trinker Updated new_project
authored
85 open = is.global(2), github = FALSE, ...) {
86
87 ## Replace spaces in path with underscores
88 project <- sub("'", "", gsub("\\s+", "_", project))
89
90 ## get the working directory and save for later
532cbc4 @trinker added the project creation function
authored
91 WD <- getwd()
92 on.exit(setwd(WD))
bfb61b5 @trinker Updated new_project
authored
93
94 ## handle if the directory already exists
09e12eb @trinker updated version
authored
95 if(file.exists(file.path(path, project))) {
96 message(paste0("\"", paste0(path, "/", project),
97 "\" already exists:\nDo you want to overwrite?\n"))
532cbc4 @trinker added the project creation function
authored
98 ans <- menu(c("Yes", "No"))
99 if (ans == "2") {
4185ace @trinker typo fix new_project
authored
100 stop("new_project aborted")
532cbc4 @trinker added the project creation function
authored
101 } else {
85c1c0c @trinker updated new_project
authored
102 delete(paste0(path, "/", project))
532cbc4 @trinker added the project creation function
authored
103 }
104 }
bfb61b5 @trinker Updated new_project
authored
105
106 ## Create the main directory and set wd to there
107 x <- suppressWarnings(invisible(folder(folder.name=file.path(path,
108 project))))
532cbc4 @trinker added the project creation function
authored
109 setwd(x)
bfb61b5 @trinker Updated new_project
authored
110
111 ## NULL to variables not defined
112 SCRIPTS <- CODEBOOK <- DATA <- DATA_FOR_REVIEW <- RAW_DATA <- NULL
7cac7da @trinker altered location of new_project
authored
113 RAW_TRANSCRIPTS <- PLOTS <- TABLES <- CM_DATA <- WORD_LISTS <- NULL
bfb61b5 @trinker Updated new_project
authored
114 CORRESPONDENCE <- DOCUMENTATION <- CLEANED_TRANSCRIPTS <- NULL
115
116 ## Add level 2 folders
117 y <- invisible(folder(SCRIPTS, CODEBOOK, DATA,
118 PLOTS, TABLES, WORD_LISTS, CORRESPONDENCE,
119 DOCUMENTATION))
120
121 ## Create a to do file
ff63598 @trinker functions are in qdap extra docs now
authored
122 todo <- paste("#when a task is complete put - in front of the item",
123 "#Use hanging indent",
124 "1. Task 1", sep = "\n")
8eaa0cf @trinker updated new_project to allow the directory to be transfered
authored
125 cat(todo, file=paste0(x, "/", "TO_DO"))
bfb61b5 @trinker Updated new_project
authored
126
127 ## Create a project log
85c1c0c @trinker updated new_project
authored
128 cat(paste0("Project \"", project, "\" created: ", Sys.time(), "\n"),
8eaa0cf @trinker updated new_project to allow the directory to be transfered
authored
129 file=paste0(x, "/", "LOG"))
bfb61b5 @trinker Updated new_project
authored
130
131 ## Subdirectories in DATA folder
132 data_nms <- c("RAW_DATA", "DATA_FOR_REVIEW", "CM_DATA",
133 "TRANSCRIPTS", "CLEANED_DATA")
134 datas <- invisible(folder(folder.name=file.path(y[[3]], data_nms)))
135
136 ## Add RAW_DATA subfolders
09e12eb @trinker updated version
authored
137 dats <- c("ANALYTIC_MEMOS", "AUDIO", "VIDEO", "FIELD_NOTES", "INTERVIEWS",
138 "PAPER_ARTIFACTS", "PHOTOGRAPHS")
bfb61b5 @trinker Updated new_project
authored
139 invisible(folder(folder.name=file.path(datas[[1]], dats)))
140
141 ## Add TRANSCRIPTS subfolders
142 trans <- c("RAW_TRANSCRIPTS", "CLEANED_TRANSCRIPTS")
143 invisible(folder(folder.name=file.path(datas[[4]], trans)))
144
145 ## Add directory for data already reviewed
146 invisible(folder(folder.name=file.path(datas[[2]], "ALREADY_REVIEWED")))
147
148 ## Add first script (CLEANING DATA) in SCRIPTS folder
149 cat(paste0("## Load required packages\npacks <- c(\"qdap\")\n",
150 "invisible(lapply(packs, library, character.only=TRUE))\n\n",
151 "trans_dir <- \"DATA/TRANSCRIPTS/CLEANED_TRANSCRIPTS\"\n",
152 "dir_map(trans_dir)\n\n\n\n",
153 "len <- length(dir(trans_dir))\n",
8eaa0cf @trinker updated new_project to allow the directory to be transfered
authored
154 "L1 <- lapply(paste0(\"dat\", 1:len), function(x) get(x))\n",
155 "names(L1) <- paste0(\"dat\", 1:len)\n",
bfb61b5 @trinker Updated new_project
authored
156 "\n\n\n\nsave( , file = \"DATA/CLEANED_DATA/cleaned.RData\")\n"),
09e12eb @trinker updated version
authored
157 file=file.path(y[[1]], "01_clean_data.R"))
bfb61b5 @trinker Updated new_project
authored
158
159 ## Add 2nd script (02_analysis_I) in SCRIPTS folder
160 cat(paste0("## Load required packages\n",
161 "packs <- c(\"qdap\", \"ggplot2\", \"grid\", \"scales\")\n",
162 "invisible(lapply(packs, library, character.only=TRUE))\n\n",
09e12eb @trinker updated version
authored
163 "source(\"extra_functions.R\")\n",
bfb61b5 @trinker Updated new_project
authored
164 "load(\"DATA/CLEANED_DATA/cleaned.RData\")\n"),
96ab5c2 @trinker added some niceties with reports in new_project
authored
165 file=paste0(y[[1]], "/", "02_analysis_I.R"))
bfb61b5 @trinker Updated new_project
authored
166
167 ## Add 3rd script (03_plots) in SCRIPTS folder
168 cat(paste0("## Load required packages\n",
169 "packs <- c(\"qdap\", \"ggplot2\", \"grid\", \"scales\")\n",
170 "invisible(lapply(packs, library, character.only=TRUE))\n\n",
09e12eb @trinker updated version
authored
171 "source(\"extra_functions.R\")\n",
bfb61b5 @trinker Updated new_project
authored
172 "load(\"DATA/CLEANED_DATA/cleaned.RData\")\n"),
09e12eb @trinker updated version
authored
173 file=file.path(y[[1]], "03_plots.R"))
bfb61b5 @trinker Updated new_project
authored
174
175 ## Add Project Workflow guide PDF
e5fff27 @trinker added some niceties to new_project to operate within RStudio
authored
176 root <- system.file("extdata/docs", package = "qdap")
09e12eb @trinker updated version
authored
177 pdfloc <- file.path(root, "PROJECT_WORKFLOW_GUIDE.pdf")
cb1e0d6 @trinker added new workflow
authored
178 invisible(file.copy(pdfloc, x))
bfb61b5 @trinker Updated new_project
authored
179
180 ## Create .rproj
09e12eb @trinker updated version
authored
181 pdfloc4 <- file.path(root, "TEMP.txt")
e5fff27 @trinker added some niceties to new_project to operate within RStudio
authored
182 invisible(file.copy(pdfloc4, x))
09e12eb @trinker updated version
authored
183 invisible(file.rename(file.path(x, "TEMP.txt"),
184 file.path(x, paste0(project, ".Rproj"))))
bfb61b5 @trinker Updated new_project
authored
185
186 ## Create extra_functions.R
09e12eb @trinker updated version
authored
187 pdfloc5 <- file.path(root, "extra_functions.R")
ff63598 @trinker functions are in qdap extra docs now
authored
188 invisible(file.copy(pdfloc5, x))
bfb61b5 @trinker Updated new_project
authored
189
190 ## Create CONTACT_INFO in the CORRESPONDENCE folder
42292a4 @trinker added stuff
authored
191 info <- c("PROJECT NAME: Project",
ff63598 @trinker functions are in qdap extra docs now
authored
192 "CLIENT/LEAD RESEARCHER: lead_researcher<numero_uno@email> 555-555-5555[skype: num1]",
42292a4 @trinker added stuff
authored
193 "ANALYST: analyst_name<analyst@email> 555-555-5555[skype: analyst_guy12]",
194 paste0("PROJECT MEMBERS:\n john doe<j.doe@email> 555-555-5555[skype: jd156]\n",
195 " jane doe<jane@email> 555-555-5555[skype: jd157]\n",
196 " nth_member<member_nth@email> 555-555-5555[skype: nmem123]\n"),
197 paste("PROJECT CREATED:", Sys.time())
198 )
199 info <- paste(info, collapse = "\n\n")
bfb61b5 @trinker Updated new_project
authored
200 cat(info, file=paste0(y[[7]], "/", "CONTACT_INFO"))
201
202 ## Create a KEY.csv codebook
42292a4 @trinker added stuff
authored
203 write.csv(data.frame(person=""), file=paste0(y[[2]], "/", "KEY.csv"),
204 row.names = FALSE)
09e12eb @trinker updated version
authored
205
206 ## Copy .Rprofile to main directory
6ddb283 @trinker Reworked new_project to make sure .Rprofile copies. Close #184
authored
207 pdfloc6 <- file.path(root, "Rprofile.txt")
09e12eb @trinker updated version
authored
208 invisible(file.copy(pdfloc6, x))
6ddb283 @trinker Reworked new_project to make sure .Rprofile copies. Close #184
authored
209 invisible(file.rename(file.path(x, "Rprofile.txt"),
210 file.path(x, ".Rprofile")))
09e12eb @trinker updated version
authored
211
bfb61b5 @trinker Updated new_project
authored
212 ## Create the reports folder with `new_report`
4fbeb11 @trinker updated qdap with reports package
authored
213 invisible(new_report(c("REPORTS", project), ...))
214 o <- paste0("Project \"", project, "\" created:\n", x, "\n")
215 class(o) <- "qdapProj"
09e12eb @trinker updated version
authored
216
217 ## Send to github
218 if (github) {
305b076 @trinker bumped version to 2.0.0
authored
219 try(qdapTools::repo2github(project.dir = x))
09e12eb @trinker updated version
authored
220 }
221
222 ## Open Project in RStudio
223 if (open) {
224 open_project(file.path(x, project, paste0(project, ".Rproj")))
225 }
4fbeb11 @trinker updated qdap with reports package
authored
226 return(o)
227 }
228
229 #' Prints a qdapProj Object
230 #'
231 #' Prints a qdapProj object.
232 #'
233 #' @param x The qdapProj object.
234 #' @param \ldots ignored
235 #' @method print qdapProj
9877d76 @trinker update the @S3method to @export close #172
authored
236 #' @export
4fbeb11 @trinker updated qdap with reports package
authored
237 print.qdapProj <-
238 function(x, ...) {
239 class(x) <- NULL
09e12eb @trinker updated version
authored
240 message(x)
241 }
242
243 wheresRstudio <-
244 function() {
245 myPaths <- c("rstudio", "~/.cabal/bin/rstudio",
246 "~/Library/Haskell/bin/rstudio", "C:\\PROGRA~1\\RStudio\\bin\\rstudio.exe",
247 "C:\\RStudio\\bin\\rstudio.exe", "/Applications/RStudio.app/Contents/MacOS/RStudio")
248 panloc <- Sys.which(myPaths)
249 temp <- panloc[panloc != ""]
250 if (identical(names(temp), character(0))) {
251 ans <- readline("RStudio not installed in one of the typical locations.\n
252 Do you know where RStudio is installed? (y/n) ")
253 if (ans == "y") {
254 temp <- readline("Enter the (unquoted) path to RStudio: ")
255 } else {
256 if (ans == "n") {
257 stop("RStudio not installed or not found.")
258 }
259 }
260 }
261 short.path <- which.min(unlist(lapply(gregexpr("RStudio", temp), "[[", 1)))
262 temp[short.path]
3bcd00d @trinker updated
authored
263 }
09e12eb @trinker updated version
authored
264
265 open_project <- function(Rproj.loc) {
266 action <- paste(wheresRstudio(), Rproj.loc)
267 message("Preparing to open project!")
268 try(system(action, wait = FALSE, ignore.stderr = TRUE))
9877d76 @trinker update the @S3method to @export close #172
authored
269 }
Something went wrong with that request. Please try again.