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

added quiet feature to read_params #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ 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.4.2

### New Features

- Introducing `quiet` argument to `read_params`

## v0.4.1

### Improvements

- Improve the readability of `dsoParams` object using `read_params()`
- Improve the readability of `dsoParams` object using `read_params()`

## v0.4.0

Expand Down
2 changes: 1 addition & 1 deletion 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.4.0
Version: 0.4.2
Author: Daniel Schreyer<[email protected]>,
Gregor Sturm<[email protected]>,
Thomas Schwarzl<[email protected]>
Expand Down
53 changes: 46 additions & 7 deletions R/read_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,44 @@
#'
#' @param stage_path relative path to stage directory from project root
#' @param return_list returns a list if TRUE, by default it return `dsoParams` class which is a list with secure access
#'
#' @param quiet suppresses the warnings and errors of the `dso get-config` execution
#'
#' @return parameters as list of list as `dsoParams` or conventional list when `return_list` is set.
#' @importFrom yaml read_yaml
#' @export
read_params <- function(stage_path, return_list = FALSE) {
stage_path <- set_stage(stage_path)
read_params <- function(stage_path, return_list = FALSE, quiet = FALSE) {
if (!is.logical(quiet))
stop("quiet argument must be either TRUE or FALSE.")

if (!is.logical(return_list))
stop("return_list argument must be either TRUE or FALSE.")

arg_stderr = ""
if (quiet) {
arg_stderr = FALSE
}

# set the stage path
stage_path <- set_stage(stage_path, quiet = quiet)

# creating a temp file to store output of dso get-config
tmp_config_file <- tempfile()
result <- system2(DSO_EXEC, c("get-config", shQuote(stage_path)), stdout = tmp_config_file)

# execute dso get-config and store ouput in temp file
result <- system2(
DSO_EXEC,
c("get-config", shQuote(stage_path)),
stdout = tmp_config_file,
stderr = arg_stderr
)

# read the output of dso get-config as yaml
yaml <- read_yaml(tmp_config_file)

# remove the temp file
unlink(tmp_config_file)

# return as list or dsoParams object
if(return_list) {
yaml
} else {
Expand All @@ -38,6 +65,7 @@ read_params <- function(stage_path, return_list = FALSE) {
#' stage from the project root.
#'
#' @param stage_path relative path to stage directory from project root
#' @param quiet surpresses messages if TRUE
#'
#' @importFrom here here
#' @importFrom here i_am
Expand All @@ -46,12 +74,23 @@ read_params <- function(stage_path, return_list = FALSE) {
#' @return absolute path to stage
#'
#' @export
set_stage <- function(stage_path) {
set_stage <- function(stage_path, quiet = F) {
tschwarzl marked this conversation as resolved.
Show resolved Hide resolved
# assuming there's a dvc.yaml in every stage
# force the project dir to bet setup correctly.
here::i_am(file.path(stage_path, "dvc.yaml"))
# Surpresses messages if quiet is TRUE
withCallingHandlers(
here::i_am(file.path(stage_path, "dvc.yaml")),
message = function(e) if (quiet) invokeRestart("muffleMessage")
)

# call here::here
stage_dir <- here::here(stage_path)
message(glue::glue("stage_here() starts at {stage_dir}"))

# report stage dir if quite is FALSE
if(!quiet)
message(glue::glue("stage_here() starts at {stage_dir}"))

# sets the stage_dir variable
assign("stage_dir", stage_dir, envir = config_env)
stage_dir
}
Expand Down
4 changes: 3 additions & 1 deletion man/read_params.Rd

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

4 changes: 3 additions & 1 deletion man/set_stage.Rd

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