R Under development (unstable) (2011-11-01 r57541)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-apple-darwin9.8.0/i386 (32-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
>