Skip to content

Commit

Permalink
Added the argument parallel_plan to the Project class and defineProje…
Browse files Browse the repository at this point in the history
…ct()
  • Loading branch information
jasenfinch committed May 22, 2023
1 parent df66efe commit 74c574d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Imports: projecttemplates,
crayon,
gh,
glue,
jfmisc,
magrittr,
methods,
purrr,
Expand All @@ -25,6 +26,7 @@ Imports: projecttemplates,
yaml
Suggests:
covr,
future,
hrmtargets,
knitr,
metaboData,
Expand All @@ -45,6 +47,7 @@ RoxygenNote: 7.2.3
VignetteBuilder: knitr
Remotes:
jasenfinch/chunky,
jasenfinch/jfmisc,
jasenfinch/hrmtargets,
jasenfinch/projecttemplates

3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export("host<-")
export("input<-")
export("instrument<-")
export("name<-")
export("parallelPlan<-")
export("path<-")
export("port<-")
export("private<-")
Expand Down Expand Up @@ -51,6 +52,7 @@ export(modules)
export(modulesKeep)
export(modulesRemove)
export(name)
export(parallelPlan)
export(path)
export(port)
export(private)
Expand Down Expand Up @@ -104,6 +106,7 @@ importFrom(purrr,flatten_chr)
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,walk)
importFrom(rlang,enexpr)
importFrom(rlang,enexprs)
importFrom(rlang,eval_tidy)
importFrom(rlang,expr)
Expand Down
44 changes: 44 additions & 0 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @slot github creation of a GitHub repository
#' @slot private private GitHub repository
#' @slot github_actions creation of GitHub actions infrastructure
#' @slot parallel_plan an expression to define the parallel future plan to use
#' @slot force force project creation if the project directory already exists

setClass('Project',
Expand All @@ -18,6 +19,7 @@ setClass('Project',
github = 'logical',
private = 'logical',
github_actions = 'logical',
parallel_plan = 'call',
force = 'logical'
),
prototype = list(
Expand All @@ -28,6 +30,7 @@ setClass('Project',
github = FALSE,
private = FALSE,
github_actions = FALSE,
parallel_plan = rlang::expr(jfmisc::suitableParallelPlan()),
force = FALSE
))

Expand All @@ -40,6 +43,7 @@ setMethod('show',signature = 'Project',
cat('GitHub repository:',github(object),'\n')
cat('Private repository:',private(object),'\n')
cat('GitHub Actions:',githubActions(object),'\n')
cat('Parallel plan:',expr_text(parallelPlan(object)),'\n')
cat('Force creation:',force(object),'\n')
})

Expand Down Expand Up @@ -92,6 +96,12 @@ setMethod('show',signature = 'Project',
#'
#' ## Set the project github actions option
#' githubActions(workflow_project) <- TRUE
#'
#' ## Return the expression project parallel plan
#' parallelPlan(workflow_project)
#'
#' ## Set the expression for the project parallel plan
#' parallelPlan(workflow_project) <- rlang::expr(future::plan(strategy = 'multisession',workers = 2))
#'
#' ## Return the project force option
#' force(workflow_project)
Expand Down Expand Up @@ -289,6 +299,33 @@ setMethod('githubActions<-',signature = 'Project',
#' @rdname Project-accessors
#' @export

setGeneric('parallelPlan',function(x)
standardGeneric('parallelPlan'))

#' @rdname Project-accessors

setMethod('parallelPlan',signature = 'Project',
function(x){
x@parallel_plan
})

#' @rdname Project-accessors
#' @export

setGeneric('parallelPlan<-',function(x,value)
standardGeneric('parallelPlan<-'))

#' @rdname Project-accessors

setMethod('parallelPlan<-',signature = 'Project',
function(x,value){
x@parallel_plan <- value
return(x)
})

#' @rdname Project-accessors
#' @export

setGeneric('force',function(x)
standardGeneric('force'))

Expand Down Expand Up @@ -322,12 +359,14 @@ setMethod('force<-',signature = 'Project',
#' @param github TRUE/FALSE. Create a GitHub repository?
#' @param private TRUE/FALSE. Should the GitHub repository be private? Evaluated only if argument `github` is TRUE.
#' @param github_actions TRUE/FALSE. Add Github actions infrastructure? Evaluated only if argument `github` is TRUE.
#' @param parallel_plan An expression denoting the `future` parallel plan to use in the project template. See `future::plan()` for more information on `future` parallel plans.
#' @param force force project creation if project directory already exists
#' @return An S4 object of class `Project`.
#' @examples
#' workflow_project <- defineProject('A metabolomics project')
#'
#' workflow_project
#' @importFrom rlang enexpr
#' @export

defineProject <- function(project_name,
Expand All @@ -337,7 +376,11 @@ defineProject <- function(project_name,
github = FALSE,
private = FALSE,
github_actions = FALSE,
parallel_plan = jfmisc::suitableParallelPlan(),
force = FALSE){

parallel_plan <- enexpr(parallel_plan)

new('Project',
project_name = project_name,
path = path,
Expand All @@ -346,6 +389,7 @@ defineProject <- function(project_name,
github = github,
private = private,
github_actions = github_actions,
parallel_plan = parallel_plan,
force = force)

}
18 changes: 18 additions & 0 deletions man/Project-accessors.Rd

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

2 changes: 2 additions & 0 deletions man/Project-class.Rd

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

3 changes: 3 additions & 0 deletions man/defineProject.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-project.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test_that('Project elements can be returned',{
FALSE)
expect_identical(githubActions(workflow_project),
FALSE)
expect_identical(parallelPlan(workflow_project),
rlang::expr(jfmisc::suitableParallelPlan()))
expect_identical(force(workflow_project),
FALSE)
})
Expand All @@ -34,6 +36,7 @@ test_that('Project elements can be set',{
github(workflow_project) <- TRUE
private(workflow_project) <- TRUE
githubActions(workflow_project) <- TRUE
parallelPlan(workflow_project) <- rlang::expr(future::plan())
force(workflow_project) <- TRUE

expect_identical(projectName(workflow_project),
Expand All @@ -49,6 +52,8 @@ test_that('Project elements can be set',{
TRUE)
expect_identical(githubActions(workflow_project),
TRUE)
expect_identical(parallelPlan(workflow_project),
rlang::expr(future::plan()))
expect_identical(force(workflow_project),
TRUE)
})

0 comments on commit 74c574d

Please sign in to comment.