From da186429eb03238c56a000c828b0e8d146613e5c Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 20:51:34 +1300 Subject: [PATCH] move js to suggests --- DESCRIPTION | 6 +++--- R/types.R | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3da4cb1..e34de35 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,11 +10,11 @@ License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 -Suggests: - testthat (>= 3.0.0) Config/testthat/edition: 3 Imports: cli, - js, rlang, Rserve +Suggests: + testthat (>= 3.0.0), + js diff --git a/R/types.R b/R/types.R index 5bef6c0..149c10c 100644 --- a/R/types.R +++ b/R/types.R @@ -30,14 +30,14 @@ print.ts_object <- function(x, ...) { cli::cli_ul() cli::cli_h3("Input type: ") if (nchar(x$input_type) > 50) { - cat(js::uglify_reformat(x$input_type, beautify = TRUE), "\n") + cat(format_js(x$input_type), "\n") } else { cat(x$input_type, "\n") } cli::cli_h3("Return type: ") if (nchar(x$return_type) > 50) { print(x$return_type) - cat(js::uglify_reformat(x$return_type, beautify = TRUE), "\n") + cat(format_js(x$return_type), "\n") } else { cat(x$return_type, "\n") } @@ -397,3 +397,10 @@ ts_void <- function() { } ) } + +format_js <- function(x) { + if (!requireNamespace("js", quietly = TRUE)) { + return(x) + } + js::uglify_reformat(x, beautify = TRUE) +}