Generate fixed width file in R
write_fwf.Rd
https://gist.github.com/haozhu233/28d1309b58431f4929f78243054f1f58
Usage
write_fwf(dt, width, con = stdout(), align = "l", na = "NA", col.names = TRUE)
Arguments
- dt
The data to be printed
- width
Either a single number or a vector of widths
- con
Connection, as in
writeLines()
; default isstdout()
.- align
"l", "r" or something like "lrl" for left, right, left.
- na
What to print in places of missing values; default: "NA"
- col.names
Print column names? Default: TRUE
Examples
dt <- data.frame(a = 1:3, b = NA, c = c('a', 'b', 'c'))
write_fwf(dt, width = c(4, 4, 3))
#> a b c
#> 1 NA a
#> 2 NA b
#> 3 NA c
write_fwf(dt, 5)
#> a b c
#> 1 NA a
#> 2 NA b
#> 3 NA c
X <- matrix(LETTERS[1:9], 3, 3, dimnames=list(1:3, paste0('V', 1:3)))
write_fwf(X, 6)
#> V1 V2 V3
#> A D G
#> B E H
#> C F I