From 1c29c8dd09a0be66e64b5e544bf7c7b5384937be Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 20:45:21 +1300 Subject: [PATCH 01/14] Rbuildignore node_modules --- .Rbuildignore | 1 + Makefile | 3 +++ R/compile.R | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index b0dba58..2a010db 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^LICENSE\.md$ ^README\.Rmd$ ^Makefile$ +node_modules diff --git a/Makefile b/Makefile index 9c45c42..ff55248 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ document: install: document R CMD INSTALL . +check: + Rscript -e "devtools::check()" + README.md: README.Rmd install Rscript -e "rmarkdown::render('README.Rmd')" @rm README.html diff --git a/R/compile.R b/R/compile.R index 2a9aa7e..d3d11cd 100644 --- a/R/compile.R +++ b/R/compile.R @@ -50,10 +50,6 @@ ts_compile.character <- function( sprintf("export default {\n %s\n};", paste(ls(e), collapse = ",\n ")) ) - # if (file != "" && file.exists(file)) { - # stop(sprintf("File exists: %s", file)) - # return() - # } cat(src, file = file, sep = "\n") invisible() From adef247c2a00f5e9b883b006d5f341ddc4988d2e Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 20:47:57 +1300 Subject: [PATCH 02/14] add initial R CMD check CI --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 29 +++++++++++++++++++++++++++++ README.Rmd | 1 + 4 files changed, 32 insertions(+) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml diff --git a/.Rbuildignore b/.Rbuildignore index 2a010db..7c6536c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,4 @@ ^README\.Rmd$ ^Makefile$ node_modules +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..6d5c6a4 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,29 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: [push, pull_request] +name: R-CMD-check.yaml + +permissions: read-all + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/README.Rmd b/README.Rmd index ab8caf5..3645837 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,6 +16,7 @@ knitr::opts_chunk$set( # ts +[![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) The **ts** package makes it easy for users to write functions that can be used in [**rserve-ts**](https://www.npmjs.com/package/rserve-ts) applications. From da186429eb03238c56a000c828b0e8d146613e5c Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 20:51:34 +1300 Subject: [PATCH 03/14] 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) +} From 351e44ee2896810a510e3a3714b459d3d41045b8 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 20:58:39 +1300 Subject: [PATCH 04/14] remove cli --- DESCRIPTION | 1 - R/function.R | 9 ++++----- R/helpers.R | 12 ++++++++++++ R/types.R | 14 +++----------- 4 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 R/helpers.R diff --git a/DESCRIPTION b/DESCRIPTION index e34de35..df98b39 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,6 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Config/testthat/edition: 3 Imports: - cli, rlang, Rserve Suggests: diff --git a/R/function.R b/R/function.R index 40d17c4..41825bf 100644 --- a/R/function.R +++ b/R/function.R @@ -82,19 +82,18 @@ ts_function <- function(f, ..., result = ts_void()) { } - #' @export print.ts_function <- function(x, ...) { - cli::cli_h3("Ocap function") + h3("Ocap function") - cli::cli_text("Arguments:") + cat("Arguments:\n") args <- lapply(x$args, \(z) z$input_type) lapply(names(args), \(n) { cat("- ", n, ": ", args[[n]], "\n", sep = "") }) - cli::cli_text("\n\n") + cat("\n\n") - cli::cli_text("Return type:") + cat("Return type:\n") cat(x$result$return_type) } diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..eaee05f --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,12 @@ +h3 <- function(x) { + cat("\n---", x, "\n") +} + + + +format_js <- function(x) { + if (!requireNamespace("js", quietly = TRUE)) { + return(x) + } + js::uglify_reformat(x, beautify = TRUE) +} diff --git a/R/types.R b/R/types.R index 149c10c..ee02868 100644 --- a/R/types.R +++ b/R/types.R @@ -27,21 +27,20 @@ ts_object <- function(input_type = "any", #' @export print.ts_object <- function(x, ...) { # name <- deparse(substitute(x)) - cli::cli_ul() - cli::cli_h3("Input type: ") + h3("Input type: ") if (nchar(x$input_type) > 50) { cat(format_js(x$input_type), "\n") } else { cat(x$input_type, "\n") } - cli::cli_h3("Return type: ") + h3("Return type: ") if (nchar(x$return_type) > 50) { print(x$return_type) cat(format_js(x$return_type), "\n") } else { cat(x$return_type, "\n") } - cli::cli_end() + cat("\n") } #' @describeIn ts_object Check if an object is a ts object @@ -397,10 +396,3 @@ ts_void <- function() { } ) } - -format_js <- function(x) { - if (!requireNamespace("js", quietly = TRUE)) { - return(x) - } - js::uglify_reformat(x, beautify = TRUE) -} From 9ea8c962064d5e25fb55e1da2f7e24c7c2536ff6 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:02:24 +1300 Subject: [PATCH 05/14] remove js dependency --- DESCRIPTION | 3 +-- R/helpers.R | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index df98b39..828b6e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,5 +15,4 @@ Imports: rlang, Rserve Suggests: - testthat (>= 3.0.0), - js + testthat (>= 3.0.0) diff --git a/R/helpers.R b/R/helpers.R index eaee05f..e0a7d11 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -3,10 +3,7 @@ h3 <- function(x) { } - +# TODO: figure out how to format (modern) JS code from R? format_js <- function(x) { - if (!requireNamespace("js", quietly = TRUE)) { - return(x) - } - js::uglify_reformat(x, beautify = TRUE) + x } From d2121cc6ff8869eef7312c89117d389b681e7c8e Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:08:39 +1300 Subject: [PATCH 06/14] run sampler tests --- .github/workflows/check-demo.yaml | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/check-demo.yaml diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml new file mode 100644 index 0000000..8cba073 --- /dev/null +++ b/.github/workflows/check-demo.yaml @@ -0,0 +1,38 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: [push, pull_request] +name: R-CMD-check.yaml + +permissions: read-all + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: pnpm/action-setup@v4 + with: + version: 9.12 + + # the rest of this must run from tests/testthat/sampler + - run: pnpm install --frozen-lockfile + working-directory: tests/testthat/sampler + + - run: pnpm build + working-directory: tests/testthat/sampler + + - run: pnpm start + working-directory: tests/testthat/sampler From 00e4e754debc16abfcd078b685b86ebfccdc4749 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:09:14 +1300 Subject: [PATCH 07/14] udpate names --- .github/workflows/R-CMD-check.yaml | 2 +- .github/workflows/check-demo.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 6d5c6a4..27bc4e5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,7 +1,7 @@ # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: [push, pull_request] -name: R-CMD-check.yaml +name: R CMD check permissions: read-all diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml index 8cba073..08b6004 100644 --- a/.github/workflows/check-demo.yaml +++ b/.github/workflows/check-demo.yaml @@ -1,7 +1,7 @@ # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: [push, pull_request] -name: R-CMD-check.yaml +name: Check demo permissions: read-all From 14fa046caf1d575e82d28439cf3c700f104b483e Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:11:35 +1300 Subject: [PATCH 08/14] install local pkg --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 27bc4e5..85bcd31 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -20,7 +20,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck + extra-packages: any::rcmdcheck, local::. needs: check - uses: r-lib/actions/check-r-package@v2 From bcbdec710bdfcc1b4f8990ef6039af7944d67dde Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:12:05 +1300 Subject: [PATCH 09/14] fix wrong file --- .github/workflows/R-CMD-check.yaml | 2 +- .github/workflows/check-demo.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 85bcd31..27bc4e5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -20,7 +20,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck, local::. + extra-packages: any::rcmdcheck needs: check - uses: r-lib/actions/check-r-package@v2 diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml index 08b6004..e377dde 100644 --- a/.github/workflows/check-demo.yaml +++ b/.github/workflows/check-demo.yaml @@ -20,7 +20,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck + extra-packages: any::rcmdcheck, local::. needs: check - uses: pnpm/action-setup@v4 From 08e7d78d7a004bf931995d79453bce13807168b1 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:15:09 +1300 Subject: [PATCH 10/14] start the Rserve instance --- .github/workflows/check-demo.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml index e377dde..dfaa8b2 100644 --- a/.github/workflows/check-demo.yaml +++ b/.github/workflows/check-demo.yaml @@ -34,5 +34,8 @@ jobs: - run: pnpm build working-directory: tests/testthat/sampler + - name: Start Rserve + run: pnpm rserve & + - run: pnpm start working-directory: tests/testthat/sampler From 67f29d68865af1ccccecb19577bbb47e6c20d1fa Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:17:02 +1300 Subject: [PATCH 11/14] start in the correct dir --- .github/workflows/check-demo.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml index dfaa8b2..cf71790 100644 --- a/.github/workflows/check-demo.yaml +++ b/.github/workflows/check-demo.yaml @@ -36,6 +36,7 @@ jobs: - name: Start Rserve run: pnpm rserve & + working-directory: tests/testthat/sampler - run: pnpm start working-directory: tests/testthat/sampler From 48f4133e9be92d5c47d8dd5a7a82c4f9572349ae Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:17:31 +1300 Subject: [PATCH 12/14] rename job --- .github/workflows/check-demo.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml index cf71790..14ae130 100644 --- a/.github/workflows/check-demo.yaml +++ b/.github/workflows/check-demo.yaml @@ -6,7 +6,7 @@ name: Check demo permissions: read-all jobs: - R-CMD-check: + run-sampler: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} From afa297fd901c36eaec45eeca89404b8353b4ba1c Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:19:47 +1300 Subject: [PATCH 13/14] make readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e5cf272..6258324 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ +[![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) The **ts** package makes it easy for users to write functions that can From dd9e4b6d58e69d2903e81084aaa566b051259d6a Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 22 Jan 2025 21:20:31 +1300 Subject: [PATCH 14/14] add demo badge --- README.Rmd | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.Rmd b/README.Rmd index 3645837..4f752a0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,6 +17,7 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) +[![Demo](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml) The **ts** package makes it easy for users to write functions that can be used in [**rserve-ts**](https://www.npmjs.com/package/rserve-ts) applications. diff --git a/README.md b/README.md index 6258324..3a2f842 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) +[![Demo](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml) The **ts** package makes it easy for users to write functions that can