diff --git a/.github/workflows/R-packages.yaml b/.github/workflows/R-packages.yaml index ff580bb..b387acd 100644 --- a/.github/workflows/R-packages.yaml +++ b/.github/workflows/R-packages.yaml @@ -34,6 +34,7 @@ jobs: with: extra-packages: any::lintr, local::. needs: lint + working-directory: packages/r/${{ matrix.package }} - name: Lint -- run `styler::style_pkg()` if this fails! working-directory: packages/r/${{ matrix.package }} diff --git a/packages/r/openproblems/.Rbuildignore b/packages/r/openproblems/.Rbuildignore index 6be1490..6e89cb4 100644 --- a/packages/r/openproblems/.Rbuildignore +++ b/packages/r/openproblems/.Rbuildignore @@ -1,3 +1,4 @@ ^LICENSE\.md$ ^\.gitignore$ -^CHANGELOG\.md$ \ No newline at end of file +^CHANGELOG\.md$ +^\.lintr$ \ No newline at end of file diff --git a/packages/r/openproblems/.lintr b/packages/r/openproblems/.lintr new file mode 100644 index 0000000..5576807 --- /dev/null +++ b/packages/r/openproblems/.lintr @@ -0,0 +1,3 @@ +linters: linters_with_defaults( + line_length_linter(120) + ) diff --git a/packages/r/openproblems/CHANGELOG.md b/packages/r/openproblems/CHANGELOG.md index 9cfa812..25af0e8 100644 --- a/packages/r/openproblems/CHANGELOG.md +++ b/packages/r/openproblems/CHANGELOG.md @@ -20,6 +20,8 @@ Initial release * `find_project_root`: simplify implementation (PR #11). +* Clean up code formatting with `styler::style_pkg()` (PR #13). + ## TESTING * Add tests for `find_project_root` (PR #11). diff --git a/packages/r/openproblems/R/deep_merge.R b/packages/r/openproblems/R/deep_merge.R index 505fa7d..c3233d8 100644 --- a/packages/r/openproblems/R/deep_merge.R +++ b/packages/r/openproblems/R/deep_merge.R @@ -1,14 +1,14 @@ #' Deep merge two lists -#' +#' #' This function will merge two lists recursively. If both lists #' are named lists, the keys will be merged. If both lists are #' lists, they will be appended. Otherwise, the second list will #' override the first list. -#' +#' #' @param obj1 The first object #' @param obj2 The second object #' @return The merged list -#' +#' #' @noRd #' @examples #' deep_merge(list(a = 1, b = 2), list(b = 3, c = 4)) @@ -44,4 +44,4 @@ deep_merge <- function(obj1, obj2) { # else override list1 with list2 obj2 } -} \ No newline at end of file +} diff --git a/packages/r/openproblems/R/find_project_root.R b/packages/r/openproblems/R/find_project_root.R index 091c35f..43a06ff 100644 --- a/packages/r/openproblems/R/find_project_root.R +++ b/packages/r/openproblems/R/find_project_root.R @@ -24,4 +24,4 @@ find_project_root <- function(path) { } as.character(path) -} \ No newline at end of file +} diff --git a/packages/r/openproblems/R/is_named_list.R b/packages/r/openproblems/R/is_named_list.R index fbacd08..30006fc 100644 --- a/packages/r/openproblems/R/is_named_list.R +++ b/packages/r/openproblems/R/is_named_list.R @@ -1,16 +1,16 @@ #' Check if an object is a named list -#' +#' #' @param obj An object #' @return TRUE if the object is a named list, FALSE otherwise -#' +#' #' @noRd -#' -#' @examples -#' is_named_list(list(a = 1, b = 2)) # TRUE -#' is_named_list(list(1, 2)) # FALSE -#' is_named_list(NULL) # TRUE -#' is_named_list(list()) # TRUE -#' is_named_list(c(1, 2, 3)) # FALSE +#' +#' @examples +#' is_named_list(list(a = 1, b = 2)) # TRUE +#' is_named_list(list(1, 2)) # FALSE +#' is_named_list(NULL) # TRUE +#' is_named_list(list()) # TRUE +#' is_named_list(c(1, 2, 3)) # FALSE is_named_list <- function(obj) { is.null(obj) || (is.list(obj) && (length(obj) == 0 || !is.null(names(obj)))) -} \ No newline at end of file +} diff --git a/packages/r/openproblems/R/read_nested_yaml.R b/packages/r/openproblems/R/read_nested_yaml.R index 40e2774..0b8efe8 100644 --- a/packages/r/openproblems/R/read_nested_yaml.R +++ b/packages/r/openproblems/R/read_nested_yaml.R @@ -17,25 +17,28 @@ #' } read_nested_yaml <- function(path, project_path = find_project_root(path)) { path <- normalizePath(path, mustWork = FALSE) - data <- tryCatch({ - suppressWarnings(yaml::read_yaml(path)) - }, error = function(e) { - stop("Could not read ", path, ". Error: ", e) - }) + data <- tryCatch( + { + suppressWarnings(yaml::read_yaml(path)) + }, + error = function(e) { + stop("Could not read ", path, ". Error: ", e) + } + ) process_nested_yaml(data, data, path, project_path) } #' Process the merge keys in a YAML -#' +#' #' This function will recursively process the merge keys in a YAML -#' +#' #' @param data The YAML data #' @param root_data The root YAML data #' @param path The path to the current YAML file #' @param project_path The path to the root of the Viash project -#' +#' #' @noRd -process_nested_yaml <- function(data, root_data, path, project_path) { +process_nested_yaml <- function(data, root_data, path, project_path) { # nolint cyclocomp_linter if (is_named_list(data)) { # check whether children have `__merge__` entries processed_data <- lapply(data, function(dat) { @@ -72,11 +75,14 @@ process_nested_yaml <- function(data, root_data, path, project_path) { new_data_path <- normalizePath(new_data_path, mustWork = FALSE) # read in the new data - tryCatch({ - suppressWarnings(yaml::read_yaml(new_data_path)) - }, error = function(e) { - stop("Could not read ", new_data_path, ". Error: ", e) - }) + tryCatch( + { + suppressWarnings(yaml::read_yaml(new_data_path)) + }, + error = function(e) { + stop("Could not read ", new_data_path, ". Error: ", e) + } + ) } x_root <- x diff --git a/packages/r/openproblems/R/read_viash_config.R b/packages/r/openproblems/R/read_viash_config.R index a2c56e5..69fcbba 100644 --- a/packages/r/openproblems/R/read_viash_config.R +++ b/packages/r/openproblems/R/read_viash_config.R @@ -19,9 +19,8 @@ #' #' @export read_viash_config <- function( - target_config_path, - project_root_dir = find_project_root(target_config_path) -) { + target_config_path, + project_root_dir = find_project_root(target_config_path)) { # note: if this config was not generated by viash, use `viash config view` first? config <- read_nested_yaml(target_config_path) diff --git a/packages/r/openproblems/R/resolve_path.R b/packages/r/openproblems/R/resolve_path.R index 5679731..92f017e 100644 --- a/packages/r/openproblems/R/resolve_path.R +++ b/packages/r/openproblems/R/resolve_path.R @@ -28,4 +28,4 @@ resolve_path <- function(path, project_path, parent_path) { paste0(project_path, path), fs::path_abs(path, parent_path) ) -} \ No newline at end of file +} diff --git a/packages/r/openproblems/R/strip_margin.R b/packages/r/openproblems/R/strip_margin.R index d9f3a72..dd779f3 100644 --- a/packages/r/openproblems/R/strip_margin.R +++ b/packages/r/openproblems/R/strip_margin.R @@ -1,4 +1,3 @@ - #' Strip margin from a string #' #' @param text A character vector. @@ -13,4 +12,4 @@ #' |") strip_margin <- function(text, symbol = "\\|") { gsub(paste0("(^|\n)[ \t]*", symbol), "\\1", text) -} \ No newline at end of file +} diff --git a/packages/r/openproblems/tests/testthat/test-find_project_root.R b/packages/r/openproblems/tests/testthat/test-find_project_root.R index 8d0371e..204ce85 100644 --- a/packages/r/openproblems/tests/testthat/test-find_project_root.R +++ b/packages/r/openproblems/tests/testthat/test-find_project_root.R @@ -1,4 +1,3 @@ - test_that("find_project_root works", { # create a temporary directory with a _viash.yaml file # project/ @@ -54,4 +53,4 @@ test_that("find_project_root works", { expect_null( find_project_root(temp_dir) ) -}) \ No newline at end of file +})