Skip to content

Commit

Permalink
version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjohnst86 authored and cran-robot committed Jul 29, 2016
1 parent fffd6d0 commit e2ab932
Show file tree
Hide file tree
Showing 47 changed files with 886 additions and 587 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: prodigenr
Title: Research Project Directory Generator
Version: 0.2.7
Version: 0.3.0
Authors@R: person("Luke", "Johnston", , "lwjohnst@gmail.com", c("aut", "cre"))
Description: Create a project directory structure, along with typical files
for that project. This allows projects to be quickly and easily created,
Expand All @@ -9,14 +9,15 @@ Description: Create a project directory structure, along with typical files
Depends: R (>= 3.1.2)
License: MIT + file LICENSE
LazyData: true
Suggests: rmarkdown, git2r, packrat, knitr, testthat
Suggests: rmarkdown, knitr, testthat, rvest, xml2, rfigshare
RoxygenNote: 5.0.1
VignetteBuilder: knitr
URL: https://github.com/lwjohnst86/prodigenr
BugReports: https://github.com/lwjohnst86/prodigenr/issues
Imports: devtools, stats, utils
NeedsCompilation: no
Packaged: 2016-05-13 19:41:13 UTC; luke
Packaged: 2016-07-29 02:42:23 UTC; luke
Author: Luke Johnston [aut, cre]
Maintainer: Luke Johnston <lwjohnst@gmail.com>
Repository: CRAN
Date/Publication: 2016-05-14 09:10:15
Date/Publication: 2016-07-29 06:41:09
65 changes: 33 additions & 32 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
e37abead8b388798535378184b86cd3d *DESCRIPTION
ad069562c459fb5d22ead8755f2a5448 *DESCRIPTION
ddb53d8ec14a4592849266ac05157e5e *LICENSE
8faea9a4680950417c132141bfee75bc *NAMESPACE
1454c005558cf700e29273d6492ef3a0 *NEWS.md
ce221787641d1ed5844f28754184f4dc *R/list_templates.R
4192a5c05e64f7666aab6a151ce75614 *R/prodigen.R
14c889f3fa53d4051b0e6425898b540e *README.md
060c3c6fc3d055687dd54b63ceaf6a82 *build/vignette.rds
3ff2055d4844bd21aab5b429efc415e1 *inst/doc/introduction.R
f9128e5f5764852cf28d0fbf10948eb7 *inst/doc/introduction.Rmd
c7ac089975d291e84a0352343f6d39cc *inst/doc/introduction.html
bb92aaaf3f0bbb1be7ce62e99da5a5ad *inst/templates/files/R/fetch_data.R
b83f6ec5d25726cd87ef3189fdbed33b *inst/templates/files/R/functions.R
d79fa66d7f1a85d11fbb18095bc48331 *inst/templates/files/R/load_data.R
092ab4df59fd1ea8f984a4d58b59b834 *inst/templates/files/R/setup.R
0f57d75254a0e7625d240f7443c9bd86 *inst/templates/files/README.md
099a501ac2a4cd0f8093fc3a19281e10 *inst/templates/files/Rprofile
4019fadb95f0337dd231ace5c6895f3b *inst/templates/files/rstudio
fee8a18773f6a58061cf7aef69a6c9b6 *inst/templates/projects/abstract/README-append.md
f3566f0b5172098d11d1f60ab7391f87 *inst/templates/projects/abstract/abstract.Rmd
ac754814e641869e0d2ce4b76ac9402a *inst/templates/projects/manuscript/README-append.md
55658a0e8e31ba29da81389cc53c054c *inst/templates/projects/manuscript/doc/manuscript.Rmd
4c7635a8de8b8c4d9f57f48f7a70cb1b *inst/templates/projects/poster/README-append.md
0902a70397f07d23b8aee6a14df41bf3 *inst/templates/projects/poster/beamerthemeCustomPoster.sty
d40ce241c60b815789f69333621a8f1e *inst/templates/projects/poster/poster.Rmd
fc71f152dec9d2fbcc04a17212e68428 *inst/templates/projects/poster/template.tex
18a13da95db5d5dcfcf21647630dddf4 *inst/templates/projects/slides/README-append.md
66ef33c363ef0e9d8e8fedf0353aeb77 *inst/templates/projects/slides/slides.Rmd
b08302683d33c2deb73b2fbd566a5e09 *inst/templates/projects/slides/template.tex
689560a39942f835159b1c9af082af6b *man/list_templates.Rd
c0ef83876a625c902c099a9e5dac2240 *man/prodigen.Rd
8ce13d783f49dcfb287f03a57f0b8c90 *NAMESPACE
a5567f83a8dfc85e135b8756f9e7d3ad *NEWS.md
566b9a92ad8934d988473bfec492f760 *R/includes.R
9d302cb7beb20244c197e1a46e7235b1 *R/prodigen.R
edf9e54d0c01ea34cec3ad230fff589c *R/template_list.R
965d672dd08f0eba690463caa42db4b2 *R/utils.R
e9bf3d2a04362adf5155375af303035d *README.md
f43fa768e61ed4fabae7b3b2a929da97 *build/vignette.rds
2a8bfc48281c61059480fa33421bb4e3 *inst/doc/introduction.R
a6d1a3b347737486ca57f352f4adcd2c *inst/doc/introduction.Rmd
907f73229bcbdca617f1850669d3573a *inst/doc/introduction.html
cfbb5010b3e802b463be44b0658df36a *inst/templates/R/fetch_data.R
dde2c6ee88469bce15696d20aedaae77 *inst/templates/R/functions.R
175645936217c01e2e5ddd8b7f4d6d24 *inst/templates/R/load_data.R
05946e941c66614264aab0d8ac73095b *inst/templates/R/setup.R
f3566f0b5172098d11d1f60ab7391f87 *inst/templates/abstract/abstract.Rmd
ca226ae8ea6e3b68c7640e0a2142734b *inst/templates/manuscript/manuscript.Rmd
0902a70397f07d23b8aee6a14df41bf3 *inst/templates/poster/beamerthemeCustomPoster.sty
d40ce241c60b815789f69333621a8f1e *inst/templates/poster/poster.Rmd
fc71f152dec9d2fbcc04a17212e68428 *inst/templates/poster/template.tex
065c1868f44eb317a7b0a8ac8a2d8a1e *inst/templates/readme/README.md
19976612495ae36e940ec7208413fd2e *inst/templates/rfigshare/rfigshare.R
66ef33c363ef0e9d8e8fedf0353aeb77 *inst/templates/slides/slides.Rmd
b08302683d33c2deb73b2fbd566a5e09 *inst/templates/slides/template.tex
68eccc45cb7e38f1146b82737df704b4 *man/include_mit_license.Rd
68b13700f83b70747d6353ff3f72ab39 *man/include_rfigshare_script.Rd
a3c0d7149c5ff6b4ac7bdf3817db118b *man/include_strobe.Rd
4377444a3a00d49e84b1a4c8a451c138 *man/prodigen.Rd
8fb573986cb7ea5c332b7913126b6384 *man/template_list.Rd
2ffba69e65ca57623c926451edbcc829 *tests/testthat.R
1096499c7940187ae91226d0db3f308b *tests/testthat/test-projects.R
f9128e5f5764852cf28d0fbf10948eb7 *vignettes/introduction.Rmd
d0ff5428f998342ea9ea78c28d9c12f1 *tests/testthat/test-projects.R
c52db57710e3e1ea76626a3a3ff5c4eb *vignettes/file_structure.txt
a6d1a3b347737486ca57f352f4adcd2c *vignettes/introduction.Rmd
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(list_templates)
export(include_mit_license)
export(include_rfigshare_script)
export(include_strobe)
export(prodigen)
export(template_list)
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# prodigenr 0.3.0

## New features/functionality

* `prodigen()` now creates a new project structure that mimics R package development
more, specifically `devtools` (since it is well documented and actively
maintained) (#18, #15, #14). The old style has been removed.
* Added a function to include a [STROBE](http://www.strobe-statement.org/index.php?id=strobe-home)
checklist for reporting guidelines (#21).
* Added function to include an `rfigshare` script to send to [figshare](https://figshare.com/) (#19).
* Added function to include a more complete MIT license (#20).

# prodigenr 0.2.7

* Added a `NEWS.md` file to track changes to the package.
Expand Down
78 changes: 78 additions & 0 deletions R/includes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

include_readme <- function(path) {
message('* Adding a README.md file to the project.')
copy_template_files('readme', path)
}

include_project_document <- function(type, path) {
message('* Adding the main project ', type, ' document to the doc/ folder.')
dir.create(file.path(path, 'doc'))
copy_template_files(type, file.path(path, 'doc'))
}

include_extra_analyses <- function(path) {
message('* Creating a vignette file for documenting additional analyses.')
devtools::use_vignette('extra-analyses', path)
}

include_rbase_files <- function(path) {
message('* Adding some basic R functions to the R/ folder.')
copy_template_files('R', file.path(path, 'R'))
}

#' License the project under MIT.
#'
#' @param path Path to the project.
#'
#' @return Creates a MIT LICENSE file.
#' @export
include_mit_license <- function(path = '.') {
if (!requireNamespace('xml2', quietly = TRUE))
stop('Please install the `xml2` package.')
if (!requireNamespace('rvest', quietly = TRUE))
stop('Please install the `rvest` package.')
path <- devtools::as.package(path)$path
message("* Adding MIT license to project.")
mit <- xml2::read_html("http://choosealicense.com/licenses/mit/")
mit <- rvest::html_node(mit, "#license-text")
mit <- rvest::html_text(mit)
devtools::use_mit_license(path)
license_path <- file.path(path, 'LICENSE')
utils::capture.output(cat(readLines(license_path), mit, file = license_path))
invisible()
}

#' Add an R script to send code to figshare.
#'
#' @param path Path to the project.
#'
#' @return Creates an rfigshare script.
#' @export
include_rfigshare_script <- function(path = '.') {
if (!requireNamespace('rfigshare', quietly = TRUE))
stop('Please install the `rfigshare` package.')
message('* Adding rfigshare.R to the R/ folder. Use this to send code to figshare.')
path <- devtools::as.package(path)$path
devtools::use_package('rfigshare', pkg = path)
copy_template_files('rfigshare', file.path(path, 'R'))
}

#' Include a STROBE checklist in the project.
#'
#' @param path Path to the project.
#'
#' @return Creates a file with the STROBE checklist.
#' @export
include_strobe <- function(path = '.') {
if (!requireNamespace('xml2', quietly = TRUE))
stop('Please install the `xml2` package.')
if (!requireNamespace('rvest', quietly = TRUE))
stop('Please install the `rvest` package.')
path <- devtools::as.package(path)$path
message('* Adding the STROBE checklist to the vignettes/ folder (this is for observational research).')
strobe <- xml2::read_html('https://raw.githubusercontent.com/lwjohnst86/scientific-checklists/master/STROBE.md')
strobe <- rvest::html_text(strobe)
file_path <- file.path(path, 'vignettes', 'strobe-checklist.md')
utils::capture.output(cat(strobe, file = file_path))
invisible()
}
20 changes: 0 additions & 20 deletions R/list_templates.R

This file was deleted.

150 changes: 55 additions & 95 deletions R/prodigen.R
Original file line number Diff line number Diff line change
@@ -1,97 +1,57 @@
##' Create a project directory and associated files.
##'
##' The main workhorse of the \pkg{prodigenr} package. Creates a
##' project directory layout, with template files and helper scripts.
##' @title Create a project directory based on a template
##'
##' @param proj.type type of project to create, based on the templates found in
##' \code{\link[prodigenr]{list_templates}} function
##' @param proj.name name of the new project directory
##' @param proj.path location of where the new project will be created
##' @param git.init Logical, whether to initialize the new project with git
##' @param packrat.init Logical, whether to track the R package usage with
##' packrat.
##' @return Creates a project directory with files and subdirectories
##' @export
##' @author Luke W. Johnston
##' @examples
##'
##' \dontrun{
##' ## Get a list of possible project templates
##' list_templates('projects')
##' # Create a project. Best done in a fresh R console.
##' prodigen('poster', 'poster', 'dev/', TRUE, FALSE)
##' prodigen('poster', 'poster', 'path/to/dir/', FALSE)
##' prodigen('poster', 'posterName', git.init = FALSE)
##' prodigen('slides', 'conference-presentation', packrat.init = FALSE)
##' prodigen('abstract', 'name', './', FALSE)
##' prodigen('manuscript', proj.path = './', git.init = TRUE)
##' }
prodigen <- function(proj.type, proj.name = NULL, proj.path = getwd(),
git.init = FALSE, packrat.init = FALSE) {

proj.type <- match.arg(proj.type, list_templates())
if (is.null(proj.name)) {
proj.name <- proj.type
} else if (!is.character(proj.name)) {
stop('Please use a character string (ie. in quotes) for the project name.')
}

if (!dir.exists(proj.path))
stop('Please use a proj.path that currently exists on your computer.')

proj_old <- file.path(proj.path, proj.type)
proj_new <- file.path(proj.path, proj.name)

if (file.exists(proj_new))
stop('Project already exists, please use a different proj.name.')

proj.files <- system.file('templates', 'projects', proj.type, package = 'prodigenr')
file.copy(proj.files,
proj.path, recursive = TRUE)
file.rename(proj_old, proj_new)

# Copy over the RStudio, Rprofile, and R/ files
template.files <- system.file('templates', 'files',
package = 'prodigenr')
template.files <- list.files(template.files, all.files = TRUE,
full.names = TRUE,
include.dirs = FALSE)[-1:-2]
file.copy(template.files,
file.path(proj_new), recursive = TRUE)

file.rename(file.path(proj_new, 'rstudio'),
file.path(proj_new, paste0(proj.name, '.Rproj')))

file.rename(file.path(proj_new, 'Rprofile'),
file.path(proj_new, '.Rprofile'))

file.append(file.path(proj_new, 'README.md'),
file.path(proj_new, 'README-append.md'))
file.remove(file.path(proj_new, 'README-append.md'))

if (git.init & requireNamespace('git2r', quietly = TRUE)) {
repo <- git2r::init(proj_new)
gitignore.file <- file.path(proj_new, '.gitignore')
if (!file.exists(gitignore.file))
file.create(gitignore.file, showWarnings = FALSE)
write('.RData\n.Rout\ndata/\n.Rhistory\n.Rproj.user',
file = gitignore.file, append = TRUE)
}

if (packrat.init & requireNamespace('packrat', quietly = TRUE)) {
packrat::init(
proj_new, enter = FALSE,
options = list(
vcs.ignore.lib = TRUE,
vcs.ignore.src = TRUE
)
)
}

if (git.init & requireNamespace('git2r', quietly = TRUE)) {
git2r::add(repo, unlist(git2r::status(repo, verbose = FALSE)))
git2r::commit(repo, 'Initial commit')
#' Create a project directory based on a template.
#'
#'
#' Create a project directory and associated files. Is based on using RStudio
#' and the \link[devtools]{devtools} package development way of working with
#' files and code. So commands/keybindings like
#' \code{\link[devtools]{load_all}} (Ctrl-Shift-L) and
#' \code{\link[devtools]{document}} (Ctrl-Shift-D) work to update your code and
#' allow an continuous and integrated approach to analyzing your data and
#' writing up your research product.
#'
#' @param type type of project to create, based on the templates found in
#' \code{\link[prodigenr]{template_list}} function
#' @param name name of the new project directory
#' @param path location of where the new project will be created
#' @param git.init Logical, whether to initialize the new project with git
#' @return Creates a project directory with files and subdirectories
#' @export
#' @examples
#'
#' \dontrun{\donttest{
#' # Get a list of possible project templates
#' template_list
#' # Create a project. Best done in a fresh R console.
#' prodigen('poster', 'poster', 'dev/', TRUE, FALSE)
#' prodigen('poster', 'poster', 'path/to/dir/', FALSE)
#' prodigen('poster', 'posterName', git.init = FALSE)
#' prodigen('abstract', 'name', './', FALSE)
#' prodigen('manuscript', path = './', git.init = TRUE)
#' }}
prodigen <-
function(type,
name = NULL,
path = getwd(),
git.init = FALSE) {
type <- match.arg(type, template_list)
stopifnot(is.character(name))
if (is.null(name)) {
name <- type
}

proj_path <- file.path(path, name)
message("* Creating project '", name, "' in '", proj_path, "'.")
null <- utils::capture.output(suppressMessages(devtools::create(proj_path)))
include_readme(proj_path)
include_project_document(type, proj_path)
include_extra_analyses(proj_path)
include_rbase_files(proj_path)
suppressMessages(devtools::use_package('devtools', pkg = proj_path))
if (git.init) {
devtools::use_git(pkg = proj_path)
} else {
null <- file.remove(file.path(proj_path, '.gitignore'))
}
invisible(TRUE)
}

}
10 changes: 10 additions & 0 deletions R/template_list.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' List project templates within \pkg{prodigenr}.
#'
#' Get a list of available templates in a package.
#'
#' @return Vector of templates available
#' @export
#' @examples
#' template_list
#'
template_list <- c('abstract', 'manuscript', 'poster', 'slides')
11 changes: 11 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

copy_template_files <- function(from, to) {
template_files <- system.file('templates', from,
package = 'prodigenr')
template_files <- list.files(template_files, all.files = TRUE,
full.names = TRUE,
include.dirs = FALSE)[-1:-2]
file.copy(template_files, to, recursive = TRUE)
}


Loading

0 comments on commit e2ab932

Please sign in to comment.