Skip to content

Commit

Permalink
package availability addressed (#52)
Browse files Browse the repository at this point in the history
* package availability addressed

* updated to not double check availability

* implemented as utils function
  • Loading branch information
taddallas authored and stephlocke committed Oct 18, 2018
1 parent c2e591a commit cc8bb2e
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 94 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ 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,
packrat,
shiny,
miniUI,
methods,
usethis
usethis,
rmarkdown
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.0
URL: https://github.com/lockedata/pRojects, https://itsalocke.com/pRojects/
Expand Down
2 changes: 2 additions & 0 deletions R/createAnalysisProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ createAnalysisProject <- function(name,
createBasicProject(name, ...)
createdirs(name, dirs)
invisible(TRUE)


}
31 changes: 16 additions & 15 deletions R/createBasicProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@ createBasicProject <- function(name,
packrat = TRUE,
git = TRUE,
readme = TRUE) {
dir.create(name)
devtools::setup(name,check = FALSE)
file.remove(file.path(name,"NAMESPACE"))
if(is_available(name)){
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 (readme)
use_readme_rmd(name)
if (packrat) {
devtools::use_package("packrat", pkg = name)
packrat:::augmentRprofile(name)
packrat::init(name, enter = FALSE)
}

if (git)
devtools::use_git(pkg = name)
if (readme)
use_readme_rmd(name)

if (git)
devtools::use_git(pkg = name)
}
invisible(TRUE)
}
26 changes: 14 additions & 12 deletions R/createPackageProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
createPackageProject <- function(name,
bestPractices = TRUE,
coverage = c("codecov", "coveralls")) {
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)
}
19 changes: 19 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


4 changes: 2 additions & 2 deletions man/createPackageProject.Rd

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

14 changes: 14 additions & 0 deletions man/is_available.Rd

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

36 changes: 18 additions & 18 deletions tests/testthat/test-createPackageProject.R
Original file line number Diff line number Diff line change
@@ -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)
97 changes: 53 additions & 44 deletions tests/testthat/test-createTrainingProject.R
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit cc8bb2e

Please sign in to comment.