-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from NovoNordisk-OpenSource/feat/use_whirl
feat: add use_whirl utility function
- Loading branch information
Showing
8 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
) | ||
}) | ||
}) |