Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introducing rstudio addin for dso repro stage #19

Merged
merged 17 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.6

### New Features
grst marked this conversation as resolved.
Show resolved Hide resolved

- Introduced the `repro` function that performs `dso repro` of a single stage with or without its dependencies
- Introduced the corresponding rstudio addins for the `repro` function

### Fixes

- Removed `...` in reload function


## v0.5.1

### Improvements
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dso
Type: Package
Title: dso R companion package
Version: 0.5.1
Version: 0.6
Author: Daniel Schreyer<[email protected]>,
Gregor Sturm<[email protected]>,
Thomas Schwarzl<[email protected]>
Expand All @@ -18,7 +18,8 @@ Imports:
here,
stringr,
methods,
rlang
rlang,
rstudioapi (>= 0.11)
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0)
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ S3method(print,dsoParams)
export(compile_config)
export(create_stage)
export(dsoParams)
export(dso_repro_stage_addin)
export(dso_repro_stage_w_dependencies_addin)
export(init)
export(read_params)
export(reload)
export(repro)
export(safe_get)
export(set_stage)
export(stage_here)
Expand All @@ -20,6 +23,7 @@ importFrom(here,here)
importFrom(here,i_am)
importFrom(methods,show)
importFrom(rlang,caller_env)
importFrom(rstudioapi,viewer)
importFrom(stringr,coll)
importFrom(stringr,str_match_all)
importFrom(stringr,str_replace)
Expand Down
73 changes: 73 additions & 0 deletions R/addin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#' Execute dso repro and display the result
#'
#' This function reproduces the current stage without its dependencies
#' and displays the resulting report in the RStudio Viewer pane.
#'
#' @return None
#' @export
#' @importFrom glue glue
#' @importFrom rstudioapi viewer
#' @examples
#' \dontrun{
#' dso_repro_stage_addin()
#' }
dso_repro_stage_addin <- function() {
check_stage_here()

repro(stage_here(), single_stage = TRUE)

check_report()
}

#' Execute dso repro with dependencies and display the result
#'
#' This function reproduces the current stage along its dependencies
#' and displays the resulting report in the RStudio Viewer pane.
#'
#' @return None
#' @export
#' @importFrom glue glue
#' @importFrom rstudioapi viewer
#' @examples
#' \dontrun{
#' dso_repro_stage_w_dependencies_addin()
#' }
dso_repro_stage_w_dependencies_addin <- function() {
check_stage_here()

repro(stage_here(), single_stage = FALSE)

check_report()
}

#' Get the current stage path
#'
#' This function retrieves the absolute path to the current stage.
#' If the stage is not defined, it stops with an error message.
#'
#' @return The absolute path to the current stage.
#' @noRd
check_stage_here <- function() {
if (length(stage_here()) == 0) {
stop(glue::glue("stage_here() is not defined. Please read in your config file using read_params()."))
}
}

#' Check and display the report
#'
#' This function checks for the generated report files in the stage directory
#'
#' @return None
#' @noRd
#' @importFrom glue glue
#' @importFrom rstudioapi viewer
check_report <- function() {
report_files <- list.files(stage_here("report"), pattern = "\\.pdf$|\\.html$", full.names = TRUE)

if (length(report_files) == 1) {
report_file <- report_files[1]
message(glue::glue("Report generated: {report_file}"))
} else {
stop(glue::glue("No report file or multiple report files were identified. Please check the report directory."))
}
}
32 changes: 32 additions & 0 deletions R/repro.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' @title Reproduce a dso stage
#' @description
#' Reproduce a dso stage with or without its dependencies.
#' @details
#' This function reproduces a stage specified by `stage_path`.
#' If `single_stage` is set to `TRUE`,
#' it reproduces the stage without its dependencies.
#' Otherwise, it reproduces the current stage
#' along with all its dependency stages.
#' By default, the current stage will be reproduced.
#' @param stage_path The path to a stage. Defaults to the current stage by using `stage_here()`.
#' @param single_stage Logical flag indicating whether to reproduce only the current stage (`TRUE`) or the current stage with all dependencies (`FALSE`). Defaults to `FALSE`.
#' @export
repro <- function(stage_path = stage_here(), single_stage = F) {
if (single_stage) {
message(glue::glue("Reproducing the current stage with all its dependency stages."))
repro_cmd <- "repro"
} else {
message(glue::glue("Reproducing the current stage without dependencies."))
repro_cmd <- "repro -s"
}
result <- system2(
DSO_EXEC,
c(repro_cmd, shQuote(file.path(stage_path, "dvc.yaml")))
)

if (result != 0) {
stop(glue::glue("DSO {repro_cmd} failed with status: {result}"))
} else {
message("dso repro was executed successfully")
}
}
9 changes: 9 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Name: dso repro stage
Description: Execute dso repro -s
Binding: dso_repro_stage_addin
Interactive: false

Name: dso repro stage with dependencies
Description: Execute dso repro
Binding: dso_repro_stage_w_dependencies_addin
Interactive: false
20 changes: 20 additions & 0 deletions man/dso_repro_stage_addin.Rd

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

20 changes: 20 additions & 0 deletions man/dso_repro_stage_w_dependencies_addin.Rd

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

24 changes: 24 additions & 0 deletions man/repro.Rd

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

Loading