Examples for 'base::scan'


Read Data Values

Aliases: scan

Keywords: file connection

### ** Examples

cat("TITLE extra line", "2 3 5 7", "11 13 17", file = "ex.data", sep = "\n")
pp <- scan("ex.data", skip = 1, quiet = TRUE)
scan("ex.data", skip = 1)
[1]  2  3  5  7 11 13 17
scan("ex.data", skip = 1, nlines = 1) # only 1 line after the skipped one
[1] 2 3 5 7
scan("ex.data", what = list("","","")) # flush is F -> read "7"
Warning in scan("ex.data", what = list("", "", "")): number of items read is
not a multiple of the number of columns
[[1]]
[1] "TITLE" "2"     "7"     "17"   

[[2]]
[1] "extra" "3"     "11"    ""     

[[3]]
[1] "line" "5"    "13"   ""    
scan("ex.data", what = list("","",""), flush = TRUE)
[[1]]
[1] "TITLE" "2"     "11"   

[[2]]
[1] "extra" "3"     "13"   

[[3]]
[1] "line" "5"    "17"  
unlink("ex.data") # tidy up

## "inline" usage
scan(text = "1 2 3")
[1] 1 2 3

[Package base version 4.2.3 Index]