Rev 35752 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R : Copyright 2005, The R Foundation for Statistical ComputingVersion 2.1.0 Under development (unstable) (2005-01-26), ISBN 3-900051-07-0R 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 a HTML browser interface to help.Type 'q()' to quit R.> ## NB: this file must be a DOS (CRLF) format file>> ## 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)> 2 + 3[1] 5> ls()[1] "z"> pi[1] 3.141593> 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:incomplete final line found by readLines on 'testIO.R'> source("testIO.R", echo=TRUE)> 2 + 3[1] 5> ls()[1] "last.warning" "z" "zz"> pi[1] 3.141593> 5 + 6[1] 11> unlink("testIO.R")>> ## ======== CRLF file> cat(z, file="testIO.R", sep="\r\n")> source("testIO.R", echo=TRUE)> 2 + 3[1] 5> ls()[1] "last.warning" "z" "zz"> pi[1] 3.141593> 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:incomplete final line found by readLines on 'testIO.R'> source("testIO.R", echo=TRUE)> 2 + 3[1] 5> ls()[1] "last.warning" "z" "zz"> pi[1] 3.141593> 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:incomplete final line found by readLines on 'testIO.R'> source("testIO.R", echo=TRUE)> 2 + 3[1] 5> ls()[1] "last.warning" "z" "zz"> pi[1] 3.141593> 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:incomplete final line found by readLines on 'testIO.R'> source("testIO.R", echo=TRUE)> 2 + 3[1] 5> ls()[1] "last.warning" "z" "zz"> pi[1] 3.141593> 5 + 6[1] 11> unlink("testIO.R")>> ## end of reg-IO.R: the next line has no EOL chars> 2 + 2[1] 4>