Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change pRojects to allow the use of the checkpoint package #32

Merged
merged 10 commits into from
Oct 24, 2018
Merged
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
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.

6 changes: 2 additions & 4 deletions tests/testthat/test-createTrainingProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ project_name <- "trainingProject2"
test_that("createTrainingProject() creates as expected when using defaults",{


proj <- try(createTrainingProject(project_name,
packrat = FALSE))
proj <- try(createTrainingProject(project_name))

if(!inherits(proj, 'try-error')){
expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj"))))
Expand Down Expand Up @@ -65,8 +64,7 @@ test_that("createTrainingProject() creates as expected when using tufte and xari

proj <- try(
createTrainingProject(project_name,
handoutEngine = "tufte", slideEngine = "xaringan",
packrat = FALSE)
handoutEngine = "tufte", slideEngine = "xaringan", packagedeps = "none")
)

if(!inherits(proj, 'try-error')){
Expand Down
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