File: reg-IO.R

package info (click to toggle)
r-base 4.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,924 kB
  • sloc: ansic: 291,338; fortran: 111,889; javascript: 14,798; yacc: 6,154; sh: 5,689; makefile: 5,239; tcl: 4,562; perl: 963; objc: 791; f90: 758; asm: 258; java: 31; sed: 1
file content (60 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
## 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)
print(4+5)

## 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")
source("testIO.R", echo=TRUE)
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")
source("testIO.R", echo=TRUE)
unlink("testIO.R")

## ======== CRLF file
cat(z, file="testIO.R", sep="\r\n")
source("testIO.R", echo=TRUE)
readLines("testIO.R")
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")
source("testIO.R", echo=TRUE)
unlink("testIO.R")

## ======== CR file
cat(z, file="testIO.R", sep="\r")
readLines("testIO.R")
source("testIO.R", echo=TRUE)
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")
source("testIO.R", echo=TRUE)
unlink("testIO.R")

## end of reg-IO.R: the next line has no EOL chars
2 + 2