Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comma in comment - write_derived #218

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mrgda
Title: Tools for Data Assembly
Version: 0.12.0
Version: 0.12.0.8000
Authors@R:
c(
person(given = "Eric", family = "Anderson", email = "[email protected]", role = c("aut", "cre")),
Expand Down
6 changes: 6 additions & 0 deletions R/write-derived.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ write_derived <- function(.data, .spec, .file, .comment = NULL, .subject_col = "


# Update history ----------------------------------------------------------

# Protect against commas in comment
if (!is.null(.comment)) {
.comment <- gsub(",", " ", .comment, fixed=TRUE)
}

.history <-
gather_data_history(
.cur_data = .data,
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-write-derived.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ test_that("if yspec check fails write derived does not continue", {
expect_error(write_derived(.data = nm, .spec = nm_spec, .file = paste0(tempfile(), ".csv"), .compare_from_svn = FALSE))
})

test_that("comma is automatically removed from comment", {
file_loc <- tempfile()
write_derived(.data = nm,
.spec = nm_spec,
.file = paste0(file_loc, ".csv"),
.comment = "Add var1, var2, var3",
.compare_from_svn = FALSE)
df <- read_csv_dots(paste0(file_loc, "/history.csv"))
expect_true(df$Comment == "Add var1 var2 var3")
})