Skip to content

Read and write fixed-width format data.

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

FinnishCancerRegistry/fwf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package fwf

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

R-CMD-check

Example

# 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

devtools::install_github("FinnishCancerRegistry/fwf")