diff --git a/.Rbuildignore b/.Rbuildignore index 28f2ccb..f8aa16f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,6 @@ tests/testthat/.remake ^remake_.*\.tar\.gz$ ^.*\.Rproj$ ^\.Rproj\.user$ +.DS_Store +.Rapp.history + diff --git a/.gitignore b/.gitignore index fd55545..f13c623 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ docker/ TODO.md Rplots.pdf .Rproj.user +.DS_Store +.Rapp.history + diff --git a/DESCRIPTION b/DESCRIPTION index 5471a0c..65d3981 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,24 +1,25 @@ Package: remake -Title: Make-like build management +Title: Make-Like Build Management Version: 0.3.0 -Authors@R: "Rich FitzJohn [aut, cre]" +Authors@R: person(family = "FitzJohn", given = "Rich", + email = "rich.fitzjohn@gmail.com", role = c("aut", "cre")) Description: Make-like build management in R. The idea is to have some sort of declarative programming to build analysis pipelines, without having to use/install make. -Depends: +Depends: R (>= 3.0.0) License: BSD_2_clause + file LICENSE LazyData: true -Imports: +Imports: R6 (>= 2.0.0), crayon, digest, optparse, storr (>= 0.5.0), yaml -Suggests: +Suggests: DiagrammeR, devtools, knitr, testthat -RoxygenNote: 5.0.1.9000 +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 34affb6..61b0318 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(delete) export(delete_bindings) export(diagram) export(dump_environment) +export(example_remake) export(fetch) export(fetch_archive) export(file_extensions) @@ -18,6 +19,7 @@ export(is_archive) export(is_current) export(list_archive) export(list_dependencies) +export(list_examples_remake) export(list_targets) export(make) export(make_environment) diff --git a/R/examples.R b/R/examples.R new file mode 100644 index 0000000..2fef9bd --- /dev/null +++ b/R/examples.R @@ -0,0 +1,24 @@ +#' @title Function \code{example_remake} +#' @description Copy a remake example to the current working directory. +#' To see the names of all the examples, run \code{\link{list_examples_remake}}. +#' @seealso \code{\link{list_examples_remake}}, \code{\link{make}} +#' @export +#' @param example name of the example. To see all the available example names, +#' run \code{\link{list_examples_remake}}. +example_remake = function(example = list_examples_remake()){ + example <- match.arg(example) + dir <- system.file(file.path("examples", example), package = "remake", mustWork = TRUE) + if(file.exists(example)) + stop("There is already a file or folder named ", example, ".", sep = "") + file.copy(from = dir, to = getwd(), recursive = TRUE) + invisible() +} + +#' @title Function \code{list_examples_remake} +#' @description Return the names of all the remake examples. +#' @seealso \code{\link{example_remake}}, \code{\link{make}} +#' @export +#' @return a names of all the remake examples. +list_examples_remake = function(){ + list.dirs(system.file("examples", package = "remake"), full.names = FALSE, recursive = FALSE) +} diff --git a/inst/examples/README.md b/inst/examples/README.md new file mode 100644 index 0000000..65434e0 --- /dev/null +++ b/inst/examples/README.md @@ -0,0 +1 @@ +These are the `remake` examples managed by functions `example_remake()` and `list_examples_remake()`. To add your own example, simply make a new folder in `inst/examples` and put your files inside. If you create (and hopefully populate) `inst/examples/my_example`, then, `"my_example"` will be automatically included in the output of `list_examples_remake()`, and `example_remake(example = "my_example")` will copy `inst/examples/my_example` to the current working directory of your R session. diff --git a/inst/examples/quickstart/code.R b/inst/examples/quickstart/code.R new file mode 100644 index 0000000..fe2becc --- /dev/null +++ b/inst/examples/quickstart/code.R @@ -0,0 +1,11 @@ +get_data = function(){ + random_numbers() +} + +random_numbers = function(){ + rnorm(1000) # Change 1000 to 2000 and rerun remake::make() to see what remake does. +} + +produce_plot = function(data, title){ + hist(data, main = title, col = "black") +} diff --git a/inst/examples/quickstart/remake.yml b/inst/examples/quickstart/remake.yml new file mode 100644 index 0000000..6c913c8 --- /dev/null +++ b/inst/examples/quickstart/remake.yml @@ -0,0 +1,16 @@ +sources: code.R +# packages: MASS + +targets: + all: + depends: + plot.pdf + + plot.pdf: # Change the title and rerun remake::make() to see what remake does. + command: + produce_plot(data = my_data, title = I("Plot title")) # Use I() for character arguments. + plot: TRUE + + my_data: + command: + get_data() diff --git a/man/example_remake.Rd b/man/example_remake.Rd new file mode 100644 index 0000000..5191445 --- /dev/null +++ b/man/example_remake.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/examples.R +\name{example_remake} +\alias{example_remake} +\title{Function \code{example_remake}} +\usage{ +example_remake(example = list_examples_remake()) +} +\arguments{ +\item{example}{name of the example. To see all the available example names, +run \code{\link{list_examples_remake}}.} +} +\description{ +Copy a remake example to the current working directory. +To see the names of all the examples, run \code{\link{list_examples_remake}}. +} +\seealso{ +\code{\link{list_examples_remake}}, \code{\link{make}} +} + diff --git a/man/list_examples_remake.Rd b/man/list_examples_remake.Rd new file mode 100644 index 0000000..3988414 --- /dev/null +++ b/man/list_examples_remake.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/examples.R +\name{list_examples_remake} +\alias{list_examples_remake} +\title{Function \code{list_examples_remake}} +\usage{ +list_examples_remake() +} +\value{ +a names of all the remake examples. +} +\description{ +Return the names of all the remake examples. +} +\seealso{ +\code{\link{example_remake}}, \code{\link{make}} +} + diff --git a/tests/testthat/test-examples.R b/tests/testthat/test-examples.R new file mode 100644 index 0000000..a0fc13a --- /dev/null +++ b/tests/testthat/test-examples.R @@ -0,0 +1,19 @@ +# library(remake); library(testthat); +context("examples") + +test_that("Basic checks on functions for examples are met.", { + expect_silent(list_examples_remake()) + expect_gt(length(list_examples_remake()), 0) + nonsense = "alskdjfoijpaskjdfhasdhflkajhsdfkahdfkdsjf" + expect_error(example_remake(nonsense)) +}) + +test_that("Quickstart example runs properly.", { + example = "quickstart" + expect_silent(example_remake(example)) + expect_error(example_remake(example)) + setwd(example) + make(verbose = F) + setwd("..") + unlink(example, recursive = TRUE) +})