Skip to content

Commit ca8ec36

Browse files
author
kalibera
committed
Fix file.show for files in non-native encoding (PR#16738). From Mikko
Korpela. git-svn-id: https://svn.r-project.org/R/trunk@88494 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 1ea65a5 commit ca8ec36

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/library/base/R/files.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ file.show <-
5050
for(i in seq_along(files)) {
5151
f <- files[i]
5252
tf <- tempfile()
53-
tmp <- readLines(f, warn = FALSE)
53+
tmp <- list(readBin(f, "raw", file.size(f)))
5454
tmp2 <- try(iconv(tmp, encoding, "", "byte"))
5555
if(inherits(tmp2, "try-error")) file.copy(f, tf)
56-
else writeLines(tmp2, tf)
56+
else {
57+
tmp2 <- strsplit(tmp2, "\r\n?|\n", perl = TRUE)[[1L]]
58+
writeLines(tmp2, tf)
59+
}
5760
files[i] <- tf
5861
if(delete.file) unlink(f)
5962
}

0 commit comments

Comments
 (0)