| |
| R version 3.6.2 Patched (2020-02-12 r77795) -- "Dark and Stormy Night" |
| Copyright (C) 2020 The R Foundation for Statistical Computing |
| Platform: x86_64-pc-linux-gnu (64-bit) |
| |
| R is free software and comes with ABSOLUTELY NO WARRANTY. |
| You are welcome to redistribute it under certain conditions. |
| Type 'license()' or 'licence()' for distribution details. |
| |
| R is a collaborative project with many contributors. |
| Type 'contributors()' for more information and |
| 'citation()' on how to cite R or R packages in publications. |
| |
| Type 'demo()' for some demos, 'help()' for on-line help, or |
| 'help.start()' for an HTML browser interface to help. |
| Type 'q()' to quit R. |
| |
| > ## NB: this file must be a DOS (CRLF) format file |
| > |
| > ## Keep comments and original formatting |
| > options(keep.source=TRUE) |
| > |
| > ## simple tests that multiple lines are read correctly |
| > print(2+3) |
| [1] 5 |
| > print(4+5) |
| [1] 9 |
| > |
| > ## generate some files to source |
| > |
| > z <- c("# line 1", "2+3", "ls()", "pi", "# last line") |
| > |
| > ## ======== LF file |
| > cat(z, file="testIO.R", sep="\n") |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > unlink("testIO.R") |
| > |
| > ## ======== LF file, incomplete final line |
| > zz <- file("testIO.R", "wt") |
| > cat(z, file=zz, sep="\n") |
| > cat("5+6", file=zz) |
| > close(zz) |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| [6] "5+6" |
| Warning message: |
| In readLines("testIO.R") : incomplete final line found on 'testIO.R' |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" "zz" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > 5+6 |
| [1] 11 |
| > unlink("testIO.R") |
| > |
| > ## ======== CRLF file |
| > cat(z, file="testIO.R", sep="\r\n") |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" "zz" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| > unlink("testIO.R") |
| > |
| > ## ======== CRLF file, incomplete final line |
| > zz <- file("testIO.R", "wt") |
| > cat(z, file=zz, sep="\r\n") |
| > cat("5+6", file=zz) |
| > close(zz) |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| [6] "5+6" |
| Warning message: |
| In readLines("testIO.R") : incomplete final line found on 'testIO.R' |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" "zz" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > 5+6 |
| [1] 11 |
| > unlink("testIO.R") |
| > |
| > ## ======== CR file |
| > cat(z, file="testIO.R", sep="\r") |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| Warning message: |
| In readLines("testIO.R") : incomplete final line found on 'testIO.R' |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" "zz" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > unlink("testIO.R") |
| > |
| > ## ======== CR file, incomplete final line |
| > zz <- file("testIO.R", "wt") |
| > cat(z, file=zz, sep="\r") |
| > cat("\r5+6", file=zz) |
| > close(zz) |
| > readLines("testIO.R") |
| [1] "# line 1" "2+3" "ls()" "pi" "# last line" |
| [6] "5+6" |
| Warning message: |
| In readLines("testIO.R") : incomplete final line found on 'testIO.R' |
| > source("testIO.R", echo=TRUE) |
| |
| > # line 1 |
| > 2+3 |
| [1] 5 |
| |
| > ls() |
| [1] "z" "zz" |
| |
| > pi |
| [1] 3.141593 |
| |
| > # last line |
| > 5+6 |
| [1] 11 |
| > unlink("testIO.R") |
| > |
| > ## end of reg-IO.R: the next line has no EOL chars |
| > 2 + 2 |
| [1] 4 |
| > |