-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Substituting enc's read and write functionality with xfun and re-implement enc::transform_lines_enc() in R/io.R
- Loading branch information
1 parent
7f61328
commit 8458b93
Showing
12 changed files
with
77 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' Apply a function to the contents of a file | ||
#' | ||
#' Transforms a file with a function. | ||
#' @param path A vector with file paths to transform. | ||
#' @param fun A function that returns a character vector. | ||
#' @param write_back Whether or not the results of the transformation should | ||
#' be written back to the file. | ||
#' @importFrom magrittr set_names | ||
#' @keywords internal | ||
transform_lines_utf8 <- function(path, fun, write_back = TRUE) { | ||
map_lgl(path, transform_lines_utf8_one, fun = fun, write_back = write_back) %>% | ||
set_names(path) | ||
} | ||
|
||
transform_lines_utf8_one <- function(path, fun, write_back = write_back) { | ||
old <- xfun::read_utf8(path) | ||
tryCatch({ | ||
new <- fun(old) | ||
if (write_back) { | ||
xfun::write_utf8(new, path) | ||
} | ||
!identical(unclass(old), unclass(new)) | ||
}, error = function(e) { | ||
warning("When processing ", path, ": ", conditionMessage(e), call. = FALSE) | ||
NA | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.