Skip to content

Commit f942ba3

Browse files
authored
Merge pull request #80 from plietar/allow-no-nl
Allow reading from files with no trailing newlines.
2 parents 53600f3 + 743b474 commit f942ba3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

R/util.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ get_string <- function(x, what = deparse(substitute(x))) {
77
}
88

99
if (refers_to_file(x)) {
10-
x <- paste(readLines(x), collapse = "\n")
10+
x <- paste(readLines(x, warn = FALSE), collapse = "\n")
1111
} else if (length(x) > 1L) {
1212
x <- paste(x, collapse = "\n")
1313
}

tests/testthat/test-util.R

+11
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,14 @@ test_that("can check if path includes dir", {
6666
expect_false(path_includes_dir("file.json"))
6767
expect_true(path_includes_dir("the/file.json"))
6868
})
69+
70+
test_that("can read file with no trailing newline", {
71+
path <- tempfile()
72+
writeLines("12345678", path, sep="")
73+
74+
# Check that we wrote just what we wanted and no more.
75+
expect_equal(file.info(path)$size, 8)
76+
77+
result <- expect_silent(get_string(path))
78+
expect_equal(result, "12345678")
79+
})

0 commit comments

Comments
 (0)