Examples for 'utils::read.fwf'


Read Fixed Width Format Files

Aliases: read.fwf

Keywords: file connection

### ** Examples

ff <- tempfile()
cat(file = ff, "123456", "987654", sep = "\n")
read.fwf(ff, widths = c(1,2,3))    #> 1 23 456 \ 9 87 654
  V1 V2  V3
1  1 23 456
2  9 87 654
read.fwf(ff, widths = c(1,-2,3))   #> 1 456 \ 9 654
  V1  V2
1  1 456
2  9 654
unlink(ff)
cat(file = ff, "123", "987654", sep = "\n")
read.fwf(ff, widths = c(1,0, 2,3))    #> 1 NA 23 NA \ 9 NA 87 654
  V1 V2 V3  V4
1  1 NA 23  NA
2  9 NA 87 654
unlink(ff)
cat(file = ff, "123456", "987654", sep = "\n")
read.fwf(ff, widths = list(c(1,0, 2,3), c(2,2,2))) #> 1 NA 23 456 98 76 54
  V1 V2 V3  V4 V5 V6 V7
1  1 NA 23 456 98 76 54
unlink(ff)

[Package utils version 4.2.3 Index]