diff --git a/NAMESPACE b/NAMESPACE index c37ce80f..4109486d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(getDependency) export(onRender) export(onStaticRenderComplete) export(prependContent) +export(projectTemplate) export(saveWidget) export(scaffoldWidget) export(setWidgetIdSeed) diff --git a/R/project.R b/R/project.R new file mode 100644 index 00000000..f362d916 --- /dev/null +++ b/R/project.R @@ -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 ", + "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 +} diff --git a/inst/rstudio/templates/project/skeleton.dcf b/inst/rstudio/templates/project/skeleton.dcf new file mode 100644 index 00000000..5277dba2 --- /dev/null +++ b/inst/rstudio/templates/project/skeleton.dcf @@ -0,0 +1,7 @@ +Title: R Package using htmlwidgets +Binding: projectTemplate +OpenFiles: README.Rmd + +Parameter: bower +Widget: TextInput +Label: Bower package diff --git a/man/projectTemplate.Rd b/man/projectTemplate.Rd new file mode 100644 index 00000000..a9a92bca --- /dev/null +++ b/man/projectTemplate.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/project.R +\name{projectTemplate} +\alias{projectTemplate} +\title{Creates an RStudio Project Template} +\usage{ +projectTemplate(path, ...) +} +\arguments{ +\item{path}{Destination path where this project will be created.} + +\item{...}{Additional parameters, currently not used.} +} +\description{ +Creates an RStudio Project Template +}