I want to write a template that creates new projects in RStudio. What I want to do is:
ProjectTemplate
package in this folder by: create.project('MyNewProject')
. I believe I can code steps 2 and 3. But I don't know how to create a new project in RStudio by a script. If it is possible, how can I do that?
Nothing special about a .Rproj
file, just a text file with (or what ever defaults):
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
Encoding: UTF-8
RnwWeave: knitr
LaTeX: pdfLaTeX
So this function would do what you're after:
myProject <- function(proj, ...) {
require(ProjectTemplate)
create.project(proj, ...)
x <- c("Version: 1.0", "", "RestoreWorkspace: Default", "SaveWorkspace: Default",
"AlwaysSaveHistory: Default", "", "EnableCodeIndexing: Yes",
"UseSpacesForTab: Yes", "NumSpacesForTab: 4", "Encoding: UTF-8",
"", "RnwWeave: knitr", "LaTeX: pdfLaTeX")
cat(paste(x, collapse="\n"), file=file.path(proj, paste0(basename(proj), ".Rproj")))
message(paste(basename(proj), "has been created"))
}
myProject("MyNewProject.Rproj")
For the git
requirement, open the folder and use:
qdapTools::repo2github()
in the console (of course you'll need to install qdapTools
).