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 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.5.1

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

- Introduced the rstudio addin to `dso repro` the current stage

## v0.5.0

### New Features
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.0
Version: 0.5.1
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ S3method(print,dsoParams)
export(compile_config)
export(create_stage)
export(dsoParams)
export(dso_repro_addin)
export(init)
export(read_params)
export(reload)
Expand Down
49 changes: 49 additions & 0 deletions R/addin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' Execute dso repro and display the result
#'
#' This function runs the `dso repro` command on the specified `dvc.yaml` file
#' and displays the resulting report in the RStudio Viewer pane.
#'
#' @return None
#' @export
#' @examples
#' \dontrun{
#' dso_repro_addin()
#' }
#' @export
dso_repro_addin <- function() {
tryCatch({
if (length(stage_here()) == 0) {
stop("stage_here() is not defined. Please read in your config file using read_params().")
} else {
stage_path <- stage_here()
}

dvc_yaml_path <- file.path(stage_path, "dvc.yaml")

tryCatch({
message(glue::glue("Reproducing the current stage"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to "#' @importFrom glue glue" for roxygen to resolve import dependencies

result <- system2(DSO_EXEC,
c("repro -s", shQuote(dvc_yaml_path)))
if (result != 0) {
stop("System command failed with status: {result}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glue seems to be missing here

}
message("System command executed successfully")
}, error = function(e) {
glue::glue("An error occurred while executing dso repro")
})

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}"))
message(glue::glue("Displaying report file: {report_file}"))
# Check the file extension and display in the viewer
rstudioapi::viewer(report_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import / importFrom with rstudioapi

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically not necessary when using ::.
Afaik the pre-commit checks also ensure that one does not forget to add it to DESCRIPTION

} else {
stop("No report file or multiple report files were identified. Please check the report directory.")
}
}, error = function(e) {
message(glue::glue("An error occurred: {e$message}"))
})
}
4 changes: 2 additions & 2 deletions R/class-dsoParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ setMethod(

#' @title reload function
#' @description
#'
#' Generic for function reload
#' Generic function for reloading configurations.
#'
#' @param object dsoParams config object
#' @param ... Additional arguments passed to the method.
#' @export
setGeneric("reload", function(object,...) standardGeneric("reload"))

Expand Down
4 changes: 4 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: dso repro stage
Description: Execute dso repro and display the result in the viewer
Binding: dso_repro_addin
Interactive: false
20 changes: 20 additions & 0 deletions man/dso_repro_addin.Rd

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

Loading