Skip to content

Commit

Permalink
Fix codefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Oct 24, 2024
1 parent ffe1b82 commit f302f1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 3 additions & 8 deletions R/compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,14 @@ compare_files <- function(target, current, files, root, search_options) {
orderly_copy_files(current, dest = path_current, files = files,
options = search_options, root = root)

readFile <- function(path) {
# This tries to be robust even in the face of bad characters.
iconv(readLines(path, warn = FALSE), "UTF-8", "UTF-8", sub="byte")
}

ret <- lapply(files, function(p) {
if (is_binary_file(file.path(path_target, p)) ||
is_binary_file(file.path(path_current, p))) {
NULL
} else {
diffobj::diffChr(
readFile(file.path(path_target, p)),
readFile(file.path(path_current, p)),
read_file_lossy(file.path(path_target, p)),
read_file_lossy(file.path(path_current, p)),
tar.banner = file.path(target, p),
cur.banner = file.path(current, p),
rds = FALSE,
Expand Down Expand Up @@ -225,7 +220,7 @@ print.orderly_compare_packets <- function(x, ...) {

#' @export
`[.orderly_compare_packets` <- function(x, paths) {
x$files <- x$files[x$files$path %in% paths,, drop=FALSE]
x$files <- x$files[x$files$path %in% paths, , drop = FALSE]
x
}

Expand Down
6 changes: 6 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,9 @@ fill_missing_names <- function(x) {
orderly_quiet <- function() {
getOption("orderly.quiet", is_testing())
}

#' Read a file, replacing any invalid UTF-8 characters
#' @noRd
read_file_lossy <- function(path) {
iconv(readLines(path, warn = FALSE), "UTF-8", "UTF-8", sub = "byte")
}

0 comments on commit f302f1a

Please sign in to comment.