Skip to content

Commit

Permalink
write_vc() gains an append argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Oct 11, 2024
1 parent 2e58657 commit e099674
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 17 additions & 3 deletions R/write_vc.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ write_vc.default <- function(
#' @importFrom git2r hash
write_vc.character <- function(
x, file, root = ".", sorting, strict = TRUE, optimize = TRUE,
na = "NA", ..., split_by = character(0)
na = "NA", ..., append = FALSE, split_by = character(0)
) {
assert_that(
inherits(x, "data.frame"), is.string(file), is.string(root), is.string(na),
noNA(na), no_whitespace(na), is.flag(strict), is.flag(optimize)
inherits(x, "data.frame"), is.string(file), is.string(root), is.string(na),
noNA(na), no_whitespace(na), is.flag(strict), is.flag(optimize),
is.flag(append), noNA(append), noNA(strict), noNA(optimize)
)
if (append) {
x <- append_df(x = x, file = file, root = root)
}
root <- normalizePath(root, winslash = "/", mustWork = TRUE)
file <- clean_data_path(root = root, file = file)
if (!file.exists(dirname(file["raw_file"]))) {
Expand Down Expand Up @@ -331,3 +335,13 @@ remove_root <- function(file, root) {
file[has_root] <- substr(file[has_root], n_root + 1, nchar(file[has_root]))
return(file)
}

#' @importFrom assertthat assert_that
append_df <- function(x, file, root) {
assert_that(inherits(x, "data.frame"))
if (!is_git2rdata(file = file, root = root, message = "none")) {
return(x)
}
read_vc(file = file, root = root) |>
rbind(x)
}
5 changes: 5 additions & 0 deletions man/write_vc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e099674

Please sign in to comment.