Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(getDependency)
export(onRender)
export(onStaticRenderComplete)
export(prependContent)
export(projectTemplate)
export(saveWidget)
export(scaffoldWidget)
export(setWidgetIdSeed)
Expand Down
65 changes: 65 additions & 0 deletions R/project.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' Creates an RStudio Project Template
#'
#' @param path Destination path where this project will be created.
#' @param ... Additional parameters, currently not used.
#'
#' @export
projectTemplate <- function(path, ...) {
project_name <- tolower(basename(path))

dots <- list(...)
bower <- if (nchar(dots$bower) == 0) NULL else dots$bower

description_file <- c(
paste("Package: ", project_name, sep = ""),
"Type: Package",
"Title: What the Package Does (Title Case)",
"Version: 0.1.0",
"Author: Who wrote it",
"Maintainer: The package maintainer <[email protected]>",
"Description: More about what it does (maybe more than one line)",
" Use four spaces when indenting paragraphs within the Description.",
"License: What license is it under?",
"Encoding: UTF-8",
"LazyData: true",
"Depends:",
" R (>= 3.1.2)",
"Imports:",
" htmlwidgets"
)

namespace_file <- c(
paste("export(", project_name, ")", sep = "")
)

readme_file <- c(
"---",
"title: \"What the Package Does (Title Case)\"",
"output:",
" github_document:",
" fig_width: 9",
" fig_height: 5",
"---",
"",
"## Getting Started",
"",
"Build the package then launch this `htmlwidget` as follows:",
"",
"```{r eval=FALSE}",
paste("library(", project_name, ")", sep = ""),
paste(project_name, "(\"Hello World\")", sep = ""),
"```"
)

dir.create(path, recursive = TRUE)
dir.create(file.path(path, "R"), recursive = TRUE)

writeLines(description_file, con = file.path(path, "DESCRIPTION"))
writeLines(namespace_file, con = file.path(path, "NAMESPACE"))
writeLines(readme_file, con = file.path(path, "README.Rmd"))

setwd(project_name)
scaffoldWidget(name = project_name, edit = FALSE, bowerPkg = bower)

TRUE
}
7 changes: 7 additions & 0 deletions inst/rstudio/templates/project/skeleton.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Title: R Package using htmlwidgets
Binding: projectTemplate
OpenFiles: README.Rmd

Parameter: bower
Widget: TextInput
Label: Bower package
16 changes: 16 additions & 0 deletions man/projectTemplate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.