Skip to content

Commit

Permalink
Merge pull request #103 from NovoNordisk-OpenSource/feat/use_whirl
Browse files Browse the repository at this point in the history
feat: add use_whirl utility function
  • Loading branch information
akselthomsen authored Nov 1, 2024
2 parents fbb560f + 3fcd214 commit f869a4e
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: whirl
Title: Logging package
Version: 0.1.3
Version: 0.1.4
Authors@R: c(
person("Aksel", "Thomsen", , "[email protected]", role = c("aut", "cre")),
person("Lovemore", "Gakava", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -50,7 +50,8 @@ Imports:
parallelly,
glue
Suggests:
testthat (>= 3.0.0)
testthat (>= 3.0.0),
usethis
Remotes:
NovoNordisk-OpenSource/zephyr
Config/testthat/edition: 3
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(log_delete)
export(log_read)
export(log_write)
export(run)
export(use_whirl)
importFrom(R6,R6Class)
importFrom(callr,r_session)
importFrom(dplyr,.data)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# whirl 0.1.4 (2024-11-01)
* Add `use_whirl()` utility function.

# whirl 0.1.3 (2024-10-23)
* Adding additional arguments to `run()` allowing the user to:
- control the verbosity level
Expand Down
34 changes: 34 additions & 0 deletions R/use_whirl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Use whirl
#'
#' @description
#'
#' Utility function to setup execution with whirl in your project:
#'
#' 1. Creates configuration file (default `_whirl.yaml`)
#' 1. Updates `.gitignore` to not include log files
#'
#' See `vignette("whirl")` for how to specify paths inside the configuration file.
#'
#' @param config_file Path to the whirl config file, relative to the project
#' @export

use_whirl <- function(config_file = "_whirl.yaml") {
cli::cli_h1("Setup {.pkg whirl}")

rlang::check_installed("usethis")

usethis::use_git_ignore(ignores = "*_log.(html|json|md)")

config <- system.file("use_whirl/_whirl.yaml", package = "whirl") |>
readLines()

config_file_path <- usethis::proj_path(config_file)
usethis::write_over(path = config_file_path, lines = config)
usethis::edit_file(path = config_file_path)

cli::cli_alert_info("Run project with {.run whirl::run(\"{config_file}\")}")

cli::cli_h1("")

return(invisible(config_file))
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ reference:
- title: "Execute scripts"
contents:
- run
- use_whirl
- options

- title: "Log custom actions"
Expand Down
11 changes: 11 additions & 0 deletions inst/use_whirl/_whirl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- name: "Run single script"
paths:
- "path/to/script.R"
- name: "Run multiple scripts in same step"
paths:
- "path/to/script_1.R"
- "path/to/script_2.R"
- name: "Run all R scripts in folder"
paths:
- "path/to/folder/*.R"
20 changes: 20 additions & 0 deletions man/use_whirl.Rd

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

23 changes: 23 additions & 0 deletions tests/testthat/test-use_whirl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("use_whirl", {
withr::with_tempdir({
rlang::local_interactive(FALSE)

usethis::create_project(path = ".")

use_whirl()

expect_true(file.exists("_whirl.yaml"))

expect_equal(
readLines("_whirl.yaml"),
readLines(system.file("use_whirl/_whirl.yaml", package = "whirl"))
)

expect_true(file.exists(".gitignore"))

expect_contains(
readLines(".gitignore"),
"*_log.(html|json|md)"
)
})
})

0 comments on commit f869a4e

Please sign in to comment.