From 9135e684293be29e26b24ee30a657899ed8d1722 Mon Sep 17 00:00:00 2001 From: Bai-Li-NOAA Date: Tue, 17 Sep 2024 17:12:06 -0400 Subject: [PATCH] fix: update rm_dollar_sign() to match a parenthesis --- R/rm_dollar_sign.R | 4 +- tests/testthat/_snaps/use_r_workflows.md | 105 +++-------------------- tests/testthat/test-rm_dollar_sign.R | 9 +- 3 files changed, 22 insertions(+), 96 deletions(-) diff --git a/R/rm_dollar_sign.R b/R/rm_dollar_sign.R index 20c250f..2b31433 100644 --- a/R/rm_dollar_sign.R +++ b/R/rm_dollar_sign.R @@ -66,13 +66,13 @@ rm_dollar_sign <- function(file, } # get rid of names in back ticks first: mod_lines <- gsub( - pattern = "([[:alnum:]]|\\.|\\_)\\$`([[:print:]]+)`", + pattern = "([[:alnum:]]|\\.|\\_|\\(|\\))\\$`([[:print:]]+)`", replacement = "\\1\\[\\[\"\\2\"\\]\\]", lines ) # all others not in back ticks pattern_no_backtick <- - "([[:alnum:]]|\\.|\\_|\\])\\$([[:alnum:]]+)(([[:alnum:]]|\\.|\\_)*)(\\s|[[:punct:]]|$)" + "([[:alnum:]]|\\.|\\_|\\]|\\(|\\))\\$([[:alnum:]]+)(([[:alnum:]]|\\.|\\_)*)(\\s|[[:punct:]]|$)" replace_no_backtick <- "\\1\\[\\[\"\\2\\3\"\\]\\]\\5" mod_lines <- gsub( pattern = pattern_no_backtick, diff --git a/tests/testthat/_snaps/use_r_workflows.md b/tests/testthat/_snaps/use_r_workflows.md index 43bfd62..30769de 100644 --- a/tests/testthat/_snaps/use_r_workflows.md +++ b/tests/testthat/_snaps/use_r_workflows.md @@ -217,61 +217,26 @@ [11] " call-workflow:" [12] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/update-pkgdown.yml@main" -# use_update_roxygen_docs() works +# use_build_pkgdown()) works Code test Output - [1] "# run devtools::document and open any changes as a pull request to the branch that started the workflow" - [2] "name: call-update-docs" - [3] "on:" - [4] "# workflow_dispatch requires pushing a button to run the workflow manually. uncomment the following line to add:" - [5] " #workflow_dispatch:" - [6] " # Runs the workflow on each push to the main or master branch:" - [7] " push:" - [8] " branches: [main, master]" - [9] "jobs:" - [10] " call-workflow:" - [11] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/update-roxygen-docs.yml@main" - -# use_style_r_code() works - - Code - test - Output - [1] "# use styler::style_active_package() to style code and open any changes as a pull request to the branch that started the workflow" - [2] "name: call-style" - [3] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows" - [4] "on:" - [5] "# workflow_dispatch requires pushing a button to run the workflow manually. uncomment the following line to add:" - [6] " #workflow_dispatch:" - [7] " # Runs the workflow on each push to the main or master branch:" + [1] "# Checks that the pkgdown site builds for a repository." + [2] "# this assumes pkgdown is already set up." + [3] "name: call-build-pkgdown" + [4] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows" + [5] "on:" + [6] "# this workflow runs on pushes to main or master or any time a new tag is pushed" + [7] "# it also runs everytime a pull request to main or master is opened." [8] " push:" [9] " branches: [main, master]" - [10] "jobs:" - [11] " call-workflow:" - [12] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/style-r-code.yml@main" - -# use_build_deploy_bookdown() works - - Code - txt - Output - [1] "# builds bookdown in a repo that is an R pkg, then deploys to a branch gh-pages" - [2] "name: call-build-deploy-bookdown" - [3] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows" - [4] "on:" - [5] "# this workflow runs on pushes to main or master or manually with the click of a button in actions." - [6] " push:" - [7] " branches: [main, master]" - [8] " workflow_dispatch:" - [9] "jobs:" - [10] " call-workflow:" - [11] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/build-deploy-bookdown.yml@main" - [12] " with:" - [13] " bookdown_input: . # where the bookdown .Rmd files are located" - [14] " bookdown_output_dir: _book # where the bookdown files are rendered to." - [15] " deployment_dir: _book # The subfolder of the gh-pages branch that the bookdown is deployed to." + [10] " tags: ['*']" + [11] " pull_request:" + [12] " branches: [main, master]" + [13] "jobs:" + [14] " call-workflow:" + [15] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/build-pkgdown.yml@main" # use_spell_check() works @@ -294,45 +259,3 @@ [14] " call-workflow:" [15] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/spell-check.yml@main" -# use_connect_publish() works - - Code - test - Output - [1] "# This action publishes to connect using the git-backed workflow. Note that" - [2] "# it is only necessary to do it this way if the product is in a private or" - [3] "# internal repository; otherwise, it is far easier to deploy following the" - [4] "# instructions in https://docs.posit.co/connect/user/git-backed/" - [5] "" - [6] "# To use this workflow, the user will need to generate the manifest.json," - [7] "# and add 2 secrets, one named" - [8] "# CONNECT_URL containing the connect url (complete with https:// in front of" - [9] "# the address) and one named CONNECT_API_KEY, containing an API Key from connect." - [10] "# To generate the manifest file, follow instructions in the create a manifest " - [11] "# from r setup and pushing it to github:" - [12] "# https://docs.posit.co/connect/user/git-backed/#creating-a-manifest-file-from-r" - [13] "# See https://docs.posit.co/connect/user/api-keys/#api-keys-creating for" - [14] "# instructions on creating and API key from connect and" - [15] "# https://octopus.com/blog/githubactions-secrets for instructions on creating" - [16] "# secrets." - [17] "name: call-connect-publish" - [18] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows" - [19] "on:" - [20] " push:" - [21] " branches: [main, master]" - [22] "# could change the build trigger to be specific to changes in the product, e.g.," - [23] "# for changes only in the R markdown product called my-prod.Rmd:" - [24] "#on:" - [25] "# push:" - [26] "# branches: [main, master]" - [27] "# paths:" - [28] "# - 'my-prod.Rmd' " - [29] "jobs:" - [30] " call-workflow:" - [31] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/connect-publish.yml@main" - [32] " secrets:" - [33] " # can change secrets.CONNECT_URL or secrets.CONNECT_API_KEY to a different " - [34] " # secret name if it is named differently in the repository." - [35] " CONNECT_URL: ${{ secrets.CONNECT_URL }} " - [36] " CONNECT_API_KEY: ${{ secrets.CONNECT_API_KEY }}" - diff --git a/tests/testthat/test-rm_dollar_sign.R b/tests/testthat/test-rm_dollar_sign.R index d23e6c6..fcf05d2 100644 --- a/tests/testthat/test-rm_dollar_sign.R +++ b/tests/testthat/test-rm_dollar_sign.R @@ -18,7 +18,8 @@ test_that("rm dollar sign works", { "x$`$$weirdcharacters`<-222", "x$`nameinbacktick`", "x$mylist$my_col$YetAnotherCol", - "x$mylist$my_col$`1_somename`" + "x$mylist$my_col$`1_somename`", + "x()$my_name <- y$test" ) expect_output <- c( "x[[\"my_name\"]] <- y[[\"test\"]]", @@ -29,7 +30,8 @@ test_that("rm dollar sign works", { "x[[\"$$weirdcharacters\"]]<-222", "x[[\"nameinbacktick\"]]", "x[[\"mylist\"]][[\"my_col\"]][[\"YetAnotherCol\"]]", - "x[[\"mylist\"]][[\"my_col\"]][[\"1_somename\"]]" + "x[[\"mylist\"]][[\"my_col\"]][[\"1_somename\"]]", + "x()[[\"my_name\"]] <- y[[\"test\"]]" ) writeLines(test_text, "test_rm_dollar_sign.txt") new_text <- rm_dollar_sign( @@ -64,7 +66,8 @@ test_that("rm dollar sign writes to file", { "x$`$$weirdcharacters`<-222", "x$`nameinbacktick`", "x$mylist$my_col$YetAnotherCol", - "x$mylist$my_col$`1_somename`" + "x$mylist$my_col$`1_somename`", + "x()$my_name <- y$test" ) writeLines(test_text, "test_rm_dollar_sign.txt") new_text <- rm_dollar_sign(