From 78958a581794efae3514884274a94869c1ccecd4 Mon Sep 17 00:00:00 2001 From: taddallas Date: Mon, 15 Oct 2018 22:51:05 +0300 Subject: [PATCH 1/3] package availability addressed --- DESCRIPTION | 8 +- R/createAnalysisProject.R | 10 +++ R/createBasicProject.R | 10 ++- R/createPackageProject.R | 8 ++ R/createTrainingProject.R | 8 ++ man/createPackageProject.Rd | 4 +- tests/testthat/test-createPackageProject.R | 36 ++++---- tests/testthat/test-createTrainingProject.R | 97 +++++++++++---------- 8 files changed, 113 insertions(+), 68 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a41ddf5..d33d0c3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,10 +20,11 @@ Depends: R (>= 3.3.0) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -Suggests: covr, +Suggests: + covr, testthat, knitr, - rmarkdown + available VignetteBuilder: knitr Imports: devtools, @@ -31,7 +32,8 @@ Imports: shiny, miniUI, methods, - usethis + usethis, + rmarkdown Roxygen: list(markdown = TRUE) RoxygenNote: 6.1.0 URL: https://github.com/lockedata/pRojects, https://itsalocke.com/pRojects/ diff --git a/R/createAnalysisProject.R b/R/createAnalysisProject.R index e785666..d212b32 100644 --- a/R/createAnalysisProject.R +++ b/R/createAnalysisProject.R @@ -16,7 +16,17 @@ createAnalysisProject <- function(name, dirs = c("data", "analysis", "outputs"), ...) { + cran <- available::available_on_cran(name) + gh <- available::available_on_github(name) + if(cran == FALSE){ + stop('package name is taken on CRAN') + } + if(gh$available == FALSE){ + stop('package name is taken on Github') + } createBasicProject(name, ...) createdirs(name, dirs) invisible(TRUE) + + } diff --git a/R/createBasicProject.R b/R/createBasicProject.R index 0cd3ced..e986257 100644 --- a/R/createBasicProject.R +++ b/R/createBasicProject.R @@ -20,6 +20,15 @@ createBasicProject <- function(name, packrat = TRUE, git = TRUE, readme = TRUE) { + + cran <- available::available_on_cran(name) + gh <- available::available_on_github(name) + if(cran == FALSE){ + stop('package name is taken on CRAN') + } + if(gh$available == FALSE){ + stop('package name is taken on Github') + } dir.create(name) devtools::setup(name,check = FALSE) file.remove(file.path(name,"NAMESPACE")) @@ -38,6 +47,5 @@ createBasicProject <- function(name, if (git) devtools::use_git(pkg = name) - invisible(TRUE) } diff --git a/R/createPackageProject.R b/R/createPackageProject.R index d27819f..7979b76 100644 --- a/R/createPackageProject.R +++ b/R/createPackageProject.R @@ -17,6 +17,14 @@ createPackageProject <- function(name, bestPractices = TRUE, coverage = c("codecov", "coveralls")) { + cran <- available::available_on_cran(name) + gh <- available::available_on_github(name) + if(cran == FALSE){ + stop('package name is taken on CRAN') + } + if(gh$available == FALSE){ + stop('package name is taken on Github') + } devtools::create(name) if (bestPractices) { devtools::use_travis(name) diff --git a/R/createTrainingProject.R b/R/createTrainingProject.R index 595f36b..518ddbe 100644 --- a/R/createTrainingProject.R +++ b/R/createTrainingProject.R @@ -20,6 +20,14 @@ createTrainingProject <- function(name, handoutEngine = "rmarkdown", slideEngine = "rmarkdown", ...) { + cran <- available::available_on_cran(name) + gh <- available::available_on_github(name) + if(cran == FALSE){ + stop('package name is taken on CRAN') + } + if(gh$available == FALSE){ + stop('package name is taken on Github') + } # Supported packages handoutEngine <- match.arg(handoutEngine, c("rmarkdown", "bookdown", "tufte")) slideEngine <- match.arg(slideEngine, c("rmarkdown", "revealjs", "xaringan")) diff --git a/man/createPackageProject.Rd b/man/createPackageProject.Rd index 1250253..d0d43e3 100644 --- a/man/createPackageProject.Rd +++ b/man/createPackageProject.Rd @@ -5,8 +5,8 @@ \title{Create a package the devtools way with a number of infrastructure commands executed to save you hassle} \usage{ -createPackageProject(name, bestPractices = TRUE, - coverage = c("codecov", "coveralls")) +createPackageProject(name, bestPractices = TRUE, coverage = c("codecov", + "coveralls")) } \arguments{ \item{name}{Project / package name} diff --git a/tests/testthat/test-createPackageProject.R b/tests/testthat/test-createPackageProject.R index ea8a612..d3195b4 100644 --- a/tests/testthat/test-createPackageProject.R +++ b/tests/testthat/test-createPackageProject.R @@ -1,26 +1,26 @@ context("createPackageProject") -project_name <- "packageProject" +project_name <- "packageProject2" test_that("createPackageProject() creates as expected when using defaults",{ - createPackageProject(project_name) - - expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) - expect_true(file.exists(file.path(project_name, "codecov.yml"))) - expect_true(file.exists(file.path(project_name, "CONDUCT.md"))) - expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) - expect_true(file.exists(file.path(project_name, "LICENSE"))) - expect_true(file.exists(file.path(project_name, "NAMESPACE"))) - expect_true(file.exists(file.path(project_name, "NEWS.md"))) - expect_true(file.exists(file.path(project_name, "R"))) - expect_true(file.exists(file.path(project_name, "README.Rmd"))) - expect_true(file.exists(file.path(project_name, "tests"))) - expect_true(file.exists(file.path(project_name, "vignettes"))) - expect_true(file.exists(file.path(project_name, ".git"))) - expect_true(file.exists(file.path(project_name, ".gitignore"))) - expect_true(file.exists(file.path(project_name, ".travis.yml"))) - + proj <- try(createPackageProject(project_name)) + if(!inherits(proj, 'try-error')){ + expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) + expect_true(file.exists(file.path(project_name, "codecov.yml"))) + expect_true(file.exists(file.path(project_name, "CONDUCT.md"))) + expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) + expect_true(file.exists(file.path(project_name, "LICENSE"))) + expect_true(file.exists(file.path(project_name, "NAMESPACE"))) + expect_true(file.exists(file.path(project_name, "NEWS.md"))) + expect_true(file.exists(file.path(project_name, "R"))) + expect_true(file.exists(file.path(project_name, "README.Rmd"))) + expect_true(file.exists(file.path(project_name, "tests"))) + expect_true(file.exists(file.path(project_name, "vignettes"))) + expect_true(file.exists(file.path(project_name, ".git"))) + expect_true(file.exists(file.path(project_name, ".gitignore"))) + expect_true(file.exists(file.path(project_name, ".travis.yml"))) + } }) unlink(project_name, recursive = TRUE, force = TRUE) diff --git a/tests/testthat/test-createTrainingProject.R b/tests/testthat/test-createTrainingProject.R index f145fe4..0565967 100644 --- a/tests/testthat/test-createTrainingProject.R +++ b/tests/testthat/test-createTrainingProject.R @@ -1,65 +1,74 @@ context("createTrainingProject") -project_name <- "trainingProject" +project_name <- "trainingProject2" test_that("createTrainingProject() creates as expected when using defaults",{ - createTrainingProject(project_name) - - expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) - expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) - expect_true(file.exists(file.path(project_name, "R"))) - expect_true(file.exists(file.path(project_name, "README.Rmd"))) - expect_true(file.exists(file.path(project_name, "packrat"))) - expect_true(file.exists(file.path(project_name, ".git"))) - expect_true(file.exists(file.path(project_name, ".gitignore"))) - expect_true(file.exists(file.path(project_name, ".travis.yml"))) - expect_true(file.exists(file.path(project_name, "data"))) - expect_true(file.exists(file.path(project_name, "handouts"))) - expect_true(file.exists(file.path(project_name, "slides"))) + proj <- try(createTrainingProject(project_name)) + + if(!inherits(proj, 'try-error')){ + expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) + expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) + expect_true(file.exists(file.path(project_name, "R"))) + expect_true(file.exists(file.path(project_name, "README.Rmd"))) + expect_true(file.exists(file.path(project_name, "packrat"))) + expect_true(file.exists(file.path(project_name, ".git"))) + expect_true(file.exists(file.path(project_name, ".gitignore"))) + expect_true(file.exists(file.path(project_name, ".travis.yml"))) + expect_true(file.exists(file.path(project_name, "data"))) + expect_true(file.exists(file.path(project_name, "handouts"))) + expect_true(file.exists(file.path(project_name, "slides"))) + } }) unlink(project_name, recursive = TRUE, force = TRUE) test_that("createTrainingProject() creates as expected when using bookdown and revealjs",{ - createTrainingProject(project_name, handoutEngine = "bookdown", slideEngine = "revealjs") - - expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) - expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) - expect_true(file.exists(file.path(project_name, "R"))) - expect_true(file.exists(file.path(project_name, "README.Rmd"))) - expect_true(file.exists(file.path(project_name, "packrat"))) - expect_true(file.exists(file.path(project_name, ".git"))) - expect_true(file.exists(file.path(project_name, ".gitignore"))) - expect_true(file.exists(file.path(project_name, ".travis.yml"))) - expect_true(file.exists(file.path(project_name, "data"))) - expect_true(file.exists(file.path(project_name, "handouts"))) - expect_true(file.exists(file.path(project_name, "handouts", "index.Rmd"))) - expect_true(file.exists(file.path(project_name, "slides", "revealjs_slides.Rmd"))) - + proj <- try( + createTrainingProject(project_name, + handoutEngine = "bookdown", slideEngine = "revealjs") + ) + if(!inherits(proj, 'try-error')){ + expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) + expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) + expect_true(file.exists(file.path(project_name, "R"))) + expect_true(file.exists(file.path(project_name, "README.Rmd"))) + expect_true(file.exists(file.path(project_name, "packrat"))) + expect_true(file.exists(file.path(project_name, ".git"))) + expect_true(file.exists(file.path(project_name, ".gitignore"))) + expect_true(file.exists(file.path(project_name, ".travis.yml"))) + expect_true(file.exists(file.path(project_name, "data"))) + expect_true(file.exists(file.path(project_name, "handouts"))) + expect_true(file.exists(file.path(project_name, "handouts", "index.Rmd"))) + expect_true(file.exists(file.path(project_name, "slides", "revealjs_slides.Rmd"))) + } }) unlink(project_name, recursive = TRUE, force = TRUE) test_that("createTrainingProject() creates as expected when using tufte and xaringan",{ - createTrainingProject(project_name, handoutEngine = "tufte", slideEngine = "xaringan") - - expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) - expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) - expect_true(file.exists(file.path(project_name, "R"))) - expect_true(file.exists(file.path(project_name, "README.Rmd"))) - expect_true(file.exists(file.path(project_name, "packrat"))) - expect_true(file.exists(file.path(project_name, ".git"))) - expect_true(file.exists(file.path(project_name, ".gitignore"))) - expect_true(file.exists(file.path(project_name, ".travis.yml"))) - expect_true(file.exists(file.path(project_name, "data"))) - expect_true(file.exists(file.path(project_name, "handouts"))) - expect_true(file.exists(file.path(project_name, "handouts", "tufte_handout.Rmd"))) - expect_true(file.exists(file.path(project_name, "slides", "xaringan_slides.Rmd"))) - + proj <- try( + createTrainingProject(project_name, + handoutEngine = "tufte", slideEngine = "xaringan") + ) + + if(!inherits(proj, 'try-error')){ + expect_true(file.exists(file.path(project_name, paste0(project_name, ".Rproj")))) + expect_true(file.exists(file.path(project_name, "DESCRIPTION"))) + expect_true(file.exists(file.path(project_name, "R"))) + expect_true(file.exists(file.path(project_name, "README.Rmd"))) + expect_true(file.exists(file.path(project_name, "packrat"))) + expect_true(file.exists(file.path(project_name, ".git"))) + expect_true(file.exists(file.path(project_name, ".gitignore"))) + expect_true(file.exists(file.path(project_name, ".travis.yml"))) + expect_true(file.exists(file.path(project_name, "data"))) + expect_true(file.exists(file.path(project_name, "handouts"))) + expect_true(file.exists(file.path(project_name, "handouts", "tufte_handout.Rmd"))) + expect_true(file.exists(file.path(project_name, "slides", "xaringan_slides.Rmd"))) + } }) unlink(project_name, recursive = TRUE, force = TRUE) From 5296bfd525eb3358e18a6cfc0b1b6e8752ee68ff Mon Sep 17 00:00:00 2001 From: taddallas Date: Wed, 17 Oct 2018 17:12:17 +0300 Subject: [PATCH 2/3] updated to not double check availability --- R/createAnalysisProject.R | 8 -------- R/createTrainingProject.R | 8 -------- 2 files changed, 16 deletions(-) diff --git a/R/createAnalysisProject.R b/R/createAnalysisProject.R index d212b32..c3f3c50 100644 --- a/R/createAnalysisProject.R +++ b/R/createAnalysisProject.R @@ -16,14 +16,6 @@ createAnalysisProject <- function(name, dirs = c("data", "analysis", "outputs"), ...) { - cran <- available::available_on_cran(name) - gh <- available::available_on_github(name) - if(cran == FALSE){ - stop('package name is taken on CRAN') - } - if(gh$available == FALSE){ - stop('package name is taken on Github') - } createBasicProject(name, ...) createdirs(name, dirs) invisible(TRUE) diff --git a/R/createTrainingProject.R b/R/createTrainingProject.R index 518ddbe..595f36b 100644 --- a/R/createTrainingProject.R +++ b/R/createTrainingProject.R @@ -20,14 +20,6 @@ createTrainingProject <- function(name, handoutEngine = "rmarkdown", slideEngine = "rmarkdown", ...) { - cran <- available::available_on_cran(name) - gh <- available::available_on_github(name) - if(cran == FALSE){ - stop('package name is taken on CRAN') - } - if(gh$available == FALSE){ - stop('package name is taken on Github') - } # Supported packages handoutEngine <- match.arg(handoutEngine, c("rmarkdown", "bookdown", "tufte")) slideEngine <- match.arg(slideEngine, c("rmarkdown", "revealjs", "xaringan")) From 797d249aa29d53650a87c7ad74fd5920572ccf6e Mon Sep 17 00:00:00 2001 From: taddallas Date: Wed, 17 Oct 2018 17:19:34 +0300 Subject: [PATCH 3/3] implemented as utils function --- R/createBasicProject.R | 39 ++++++++++++++++----------------------- R/createPackageProject.R | 34 ++++++++++++++-------------------- R/utils.R | 19 +++++++++++++++++++ man/is_available.Rd | 14 ++++++++++++++ 4 files changed, 63 insertions(+), 43 deletions(-) create mode 100644 man/is_available.Rd diff --git a/R/createBasicProject.R b/R/createBasicProject.R index e986257..b6dfb5b 100644 --- a/R/createBasicProject.R +++ b/R/createBasicProject.R @@ -20,32 +20,25 @@ createBasicProject <- function(name, packrat = TRUE, git = TRUE, readme = TRUE) { + if(is_available(name)){ + dir.create(name) + devtools::setup(name,check = FALSE) + file.remove(file.path(name,"NAMESPACE")) - cran <- available::available_on_cran(name) - gh <- available::available_on_github(name) - if(cran == FALSE){ - stop('package name is taken on CRAN') - } - if(gh$available == FALSE){ - stop('package name is taken on Github') - } - dir.create(name) - devtools::setup(name,check = FALSE) - file.remove(file.path(name,"NAMESPACE")) + if (travis) + devtools::use_travis(name) - if (travis) - devtools::use_travis(name) + if (packrat) { + devtools::use_package("packrat", pkg = name) + packrat:::augmentRprofile(name) + packrat::init(name, enter = FALSE) + } - if (packrat) { - devtools::use_package("packrat", pkg = name) - packrat:::augmentRprofile(name) - packrat::init(name, enter = FALSE) - } + if (readme) + use_readme_rmd(name) - if (readme) - use_readme_rmd(name) - - if (git) - devtools::use_git(pkg = name) + if (git) + devtools::use_git(pkg = name) + } invisible(TRUE) } diff --git a/R/createPackageProject.R b/R/createPackageProject.R index 7979b76..2a83613 100644 --- a/R/createPackageProject.R +++ b/R/createPackageProject.R @@ -17,26 +17,20 @@ createPackageProject <- function(name, bestPractices = TRUE, coverage = c("codecov", "coveralls")) { - cran <- available::available_on_cran(name) - gh <- available::available_on_github(name) - if(cran == FALSE){ - stop('package name is taken on CRAN') - } - if(gh$available == FALSE){ - stop('package name is taken on Github') - } - devtools::create(name) - if (bestPractices) { - devtools::use_travis(name) - devtools::use_code_of_conduct(name) - devtools::use_coverage(name, coverage) - devtools::use_mit_license(name) - use_news_md(name) - use_package_doc(name) - use_readme_rmd(name) - devtools::use_testthat(name) - devtools::use_vignette(name, name) - devtools::use_git(pkg = name) + if(is_available(name)){ + devtools::create(name) + if (bestPractices) { + devtools::use_travis(name) + devtools::use_code_of_conduct(name) + devtools::use_coverage(name, coverage) + devtools::use_mit_license(name) + use_news_md(name) + use_package_doc(name) + use_readme_rmd(name) + devtools::use_testthat(name) + devtools::use_vignette(name, name) + devtools::use_git(pkg = name) + } } invisible(TRUE) } diff --git a/R/utils.R b/R/utils.R index 54d4b9f..43e7b94 100644 --- a/R/utils.R +++ b/R/utils.R @@ -64,3 +64,22 @@ createdesc <- function(name) { ) devtools:::write_dcf(file.path(name,"DESCRIPTION"),desc) } + + +#' Check availability +#' +#' @param name Package / project + +is_available <- function(name) { + cran <- available::available_on_cran(name) + gh <- available::available_on_github(name) + if(cran == FALSE){ + stop('package name is taken on CRAN') + } + if(gh$available == FALSE){ + stop('package name is taken on Github') + } + invisible(TRUE) +} + + diff --git a/man/is_available.Rd b/man/is_available.Rd new file mode 100644 index 0000000..15c8828 --- /dev/null +++ b/man/is_available.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{is_available} +\alias{is_available} +\title{Check availability} +\usage{ +is_available(name) +} +\arguments{ +\item{name}{Package / project} +} +\description{ +Check availability +}