Skip to content

Commit

Permalink
Merge 17b17fa into 2d19784
Browse files Browse the repository at this point in the history
  • Loading branch information
stephlocke authored Oct 24, 2018
2 parents 2d19784 + 17b17fa commit 94adc93
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 48 deletions.
10 changes: 8 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ LazyData: true
Suggests:
covr,
testthat,
knitr,
available
rmarkdown,
xaringan,
tufte,
revealjs,
bookdown
VignetteBuilder: knitr
Imports:
devtools,
packrat,
shiny,
miniUI,
checkpoint,
knitr,
available,
methods,
usethis,
rmarkdown,
Expand Down
30 changes: 18 additions & 12 deletions R/createBasicProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @param name Project
#' @param travis Configure Travis-CI
#' @param packrat Configure Packrat
#' @param packagedeps Set a tool for package reproducibility
#' @param git Configure Git
#' @param readme Include a README
#'
Expand All @@ -17,9 +17,12 @@
#' }
createBasicProject <- function(name,
travis = TRUE,
packrat = TRUE,
packagedeps = "packrat",
git = TRUE,
readme = TRUE) {

packagedeps<-match.arg(packagedeps, c("none","packrat","checkpoint"))

tryCatch({
if (is_available(name)) {
dir.create(name)
Expand All @@ -35,20 +38,23 @@ createBasicProject <- function(name,
#placeholder, BADGE stuff
}

if (packrat) {

if (packagedeps == "packrat") {
desc::desc_set_dep(package = "packrat",
type = "Imports",
file = usethis::proj_get())
packrat::init(file.path(getwd(),
name), enter = FALSE)
}
if (readme) {
usethis::use_readme_rmd(open = FALSE)
}
packrat::init(name, enter = FALSE)
}

if (git) {
usethis::use_git()
}
if (packagedeps == "checkpoint") {
desc::desc_set_dep(package = "checkpoint",
type = "Imports",
file = usethis::proj_get())
checkpoint::setSnapshot(Sys.Date(), online = TRUE)
}

if (readme) usethis::use_readme_rmd(open = FALSE)
if (git) usethis::use_git()
}
}
,
Expand Down
22 changes: 13 additions & 9 deletions R/createTrainingProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ createTrainingProject <- function(name,
handoutEngine <- match.arg(handoutEngine, c("rmarkdown", "bookdown", "tufte"))
slideEngine <- match.arg(slideEngine, c("rmarkdown", "revealjs", "xaringan"))

# Installation dir
usePackrat <- !methods::hasArg("packrat")
if (!usePackrat)
usePackrat <- list(...)[["packrat"]]
installDir <- ifelse(usePackrat, name, .libPaths())
if(!requireNamespace(handoutEngine, quietly = TRUE)){
stop("You need to install ",handoutEngine, " first")
}
if(!requireNamespace(slideEngine, quietly = TRUE)){
stop("You need to install ",slideEngine, " first")
}

# Skeleton
message("Creating skeleton")
Expand All @@ -40,7 +41,6 @@ createTrainingProject <- function(name,
desc::desc_set_dep(package = handoutEngine,
type = "Imports",
file = usethis::proj_get())

if (handoutEngine != "rmarkdown") {
message(paste(handoutEngine, "demo added"))
file.copy(
Expand Down Expand Up @@ -71,9 +71,13 @@ createTrainingProject <- function(name,

}

if (usePackrat) {
packrat::snapshot(name)
packrat::restore(name)
# Perform some basic packrat initialisation
if("packagedeps" %in% names(list(...))){
pkgdeps <- list(...)[["packagedeps"]]
if(pkgdeps == "packrat"){
packrat::snapshot(name)
packrat::restore(name)
}
}

invisible(TRUE)
Expand Down
8 changes: 4 additions & 4 deletions R/shinyGadget.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ projectGadget <- function() {
shiny::checkboxInput("readme", "Create README", value = TRUE),
shiny::checkboxInput("git", "Use Git", value = TRUE),
shiny::checkboxInput("travis", "Use Travis", value = TRUE),
shiny::checkboxInput("packrat", "Use Packrat", value = TRUE)
shiny::selectInput("packagedeps",label="Use a package for handling reproducibility",choices = c("none","packrat","checkpoint"), selected = "packrat")
)
)
)
Expand Down Expand Up @@ -75,12 +75,12 @@ projectGadget <- function() {
"Basic" = createBasicProject(
name = input$name, readme = input$readme,
git = input$git, travis = input$travis,
packrat = input$packrat),
packagedeps = input$packagedeps),

"Analysis" = createAnalysisProject(
name = input$name, dirs = input$dirs,
readme = input$readme, git = input$git,
travis = input$travis, packrat = input$packrat),
travis = input$travis, packagedeps = input$packagedeps),

"Package" = createPackageProject(
name = input$name, bestPractices = input$bestPractices,
Expand All @@ -91,7 +91,7 @@ projectGadget <- function() {
handoutEngine = input$handoutE,
slideEngine = input$slideE,
readme = input$readme, git = input$git,
travis = input$travis, packrat = input$packrat)
travis = input$travis, packagedeps = input$packagedeps)

)

Expand Down
11 changes: 6 additions & 5 deletions inst/rstudio/templates/project/createAnalysisProject.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Label: Use Git
Default: On
Position: right

Parameter: packrat
Widget: CheckboxInput
Label: Use Packrat
Default: On
Position: right
Parameter: packagedeps
Widget: SelectInput
Label: Reproducibility
Default: packrat
Fields: none, packrat, checkpoint
Position: left
11 changes: 6 additions & 5 deletions inst/rstudio/templates/project/createBasicProject.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Label: Use Git
Default: On
Position: right

Parameter: packrat
Widget: CheckboxInput
Label: Use Packrat
Default: On
Position: right
Parameter: packagedeps
Widget: SelectInput
Label: Reproducibility
Default: packrat
Fields: none, packrat, checkpoint
Position: left
11 changes: 6 additions & 5 deletions inst/rstudio/templates/project/createTrainingProject.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Label: Use Git
Default: On
Position: right

Parameter: packrat
Widget: CheckboxInput
Label: Use Packrat
Default: On
Position: right
Parameter: packagedeps
Widget: SelectInput
Label: Reproducibility
Default: packrat
Fields: none, packrat, checkpoint
Position: left
6 changes: 3 additions & 3 deletions man/createBasicProject.Rd

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

11 changes: 8 additions & 3 deletions vignettes/BasicProjects.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ The basic project contains a [`.travis.yml` file](https://docs.travis-ci.com/use

[READ MORE ON TRAVIS-CI](https://docs.travis-ci.com/user/languages/r/)

### Packrat
[Packrat](https://rstudio.github.io/packrat/) is developed with reproducibility in mind. (Un)fortunately, R moves at an incredible pace and there is the risk that if we're always using the latest versions of packages we can't make our results consistent over time or between users.
### Reproducibility
A problem with programming using other people's code is that other people's code changes. This risks your results changing over time. To prevent this, there are some R packages which can help us address this.

Packrat will build a manifest of package versions based on what you use at the point of production. It will then ensure people use the Packrat defined packages, instead of whatever version they have installed.
[`packrat`](https://rstudio.github.io/packrat/) will build a manifest of package versions based on what you use at the point of production. It will then ensure people use the Packrat defined packages, instead of whatever version they have installed.

[READ MORE ON PACKRAT](https://rstudio.github.io/packrat/)

[`checkpoint`](https://rdrr.io/cran/checkpoint) moves away from using your default CRAN repository and points to a specific repository that has daily snapshots. You then work with CRAN as of a specific date (by default the date you created the project). This is lighter weight than `packrat` but does not help with non-CRAN packages.


[READ MORE ON CHECKPOINT](https://rdrr.io/cran/checkpoint)

### What else?
We're working on what else should be an optional extra for basic projects and we want your opinions. Contribute your opinion on our [GitHub Issues](https://github.com/lockedata/pRojects/issues).

Expand Down

0 comments on commit 94adc93

Please sign in to comment.