Skip to content

Commit

Permalink
fix to rm dollar sign from lines that have quotes
Browse files Browse the repository at this point in the history
fixes #150
  • Loading branch information
e-perl-NOAA authored and k-doering-NOAA committed Dec 19, 2024
1 parent 499d1d5 commit 50a5576
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/doc-and-style-r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: setup env using GITHUB_TOKEN, if no pat
if: env.GITHUB_PAT == ''
run: echo "GITHUB_PAT=${{ secrets.GITHUB_TOKEN}}" >> "$GITHUB_ENV"

- name: checkout, make changes and submit as pr on new branch
if: inputs.commit-directly == false
uses: actions/checkout@v4
Expand Down
10 changes: 10 additions & 0 deletions R/rm_dollar_sign.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ rm_dollar_sign <- function(file,
lines
)
# all others not in back ticks
# address situations in quotation marks
pattern_no_backtick_in_quotes <-
'(".*)([[:alnum:]]|\\.|\\_|\\]|\\(|\\))\\$([[:alnum:]]+)(([[:alnum:]]|\\.|\\_)*)(.*")'
replace_no_backtick_in_quotes <- "\\1\\2\\[\\[\'\\3\\4\'\\]\\]\\6"
mod_lines <- gsub(
pattern = pattern_no_backtick_in_quotes,
replacement = replace_no_backtick_in_quotes,
mod_lines
)

pattern_no_backtick <-
"([[:alnum:]]|\\.|\\_|\\]|\\(|\\))\\$([[:alnum:]]+)(([[:alnum:]]|\\.|\\_)*)(\\s|[[:punct:]]|$)"
replace_no_backtick <- "\\1\\[\\[\"\\2\\3\"\\]\\]\\5"
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-rm_dollar_sign.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ test_that("rm dollar sign works", {
"x$`nameinbacktick`",
"x$mylist$my_col$YetAnotherCol",
"x$mylist$my_col$`1_somename`",
"x()$my_name <- y$test"
"x()$my_name <- y$test",
"\"test object$item with additional quoted text\""
)
expect_output <- c(
"x[[\"my_name\"]] <- y[[\"test\"]]",
Expand All @@ -31,7 +32,8 @@ test_that("rm dollar sign works", {
"x[[\"nameinbacktick\"]]",
"x[[\"mylist\"]][[\"my_col\"]][[\"YetAnotherCol\"]]",
"x[[\"mylist\"]][[\"my_col\"]][[\"1_somename\"]]",
"x()[[\"my_name\"]] <- y[[\"test\"]]"
"x()[[\"my_name\"]] <- y[[\"test\"]]",
"\"test object[['item']] with additional quoted text\""
)
writeLines(test_text, "test_rm_dollar_sign.txt")
new_text <- rm_dollar_sign(
Expand Down

0 comments on commit 50a5576

Please sign in to comment.