An open API service indexing awesome lists of open source software.

https://github.com/finnishcancerregistry/fwf

Read and write fixed-width format data.
https://github.com/finnishcancerregistry/fwf

data-export data-import data-processing epidemiology file-format fixed-width-format fwf io r-package tabular-data text-data

Last synced: about 1 month ago
JSON representation

Read and write fixed-width format data.

Awesome Lists containing this project

README

        

# Package `fwf`

`fwf` is a tiny package to read and write fixed width format tables.

[![R-CMD-check](https://github.com/FinnishCancerRegistry/fwf/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/FinnishCancerRegistry/fwf/actions/workflows/R-CMD-check.yaml)

# Example
```r
# Remember, data types other than character, integer, and double may not
# be properly handled (because meta-information about datatype is lost when
# writing into a text file). See ?data.table::fread for more control.
# over reading behaviour.
exp <- data.frame(
col1 = c("abcdefghijklmn", "abc"),
col2 = c(1e6L, 1L),
col3 = as.Date(c("2000-01-01", "2001-01-01"))
)
tf <- tempfile(pattern = "fwf_file_", fileext = ".txt")
fwf::fwf_write(exp, tf)
obs <- fwf::fwf_read(
path = tf,
fread_arg_list = list(colClasses = c(col3 = "Date"))
)
stopifnot(
all.equal(exp, obs, check.attributes = FALSE),
identical(lapply(exp, class), lapply(obs, class))
)
```

# Installation
```r
devtools::install_github("FinnishCancerRegistry/fwf")
````