R: Create a connection to a fixed width file.

laf_open_fwf {LaF} | R Documentation

## Create a connection to a fixed width file.

### Description

A connection to the file filename is created. Column types have to be specified. These are not determined automatically as for example read.fwf does. This has been done to increase speed.

### Usage

    laf_open_fwf(
      filename,
      column_types,
      column_widths,
      column_names = paste("V", seq_len(length(column_types)), sep = ""),
      dec = ".",
      trim = TRUE,
      ignore_failed_conversion = FALSE
    )

### Arguments

`filename` | character containing the filename of the CSV-file.
`column_types` | character vector containing the types of data in each of the columns. Valid types are: double, integer, categorical and string.
`column_widths` | numeric vector containing the width in number of character of each of the columns.
`column_names` | optional character vector containing the names of the columns.
`dec` | optional character specifying the decimal mark.
`trim` | optional logical specifying whether or not whitespace at the end of factor levels or character strings should be trimmed.
`ignore_failed_conversion` | ignore (set to `NA`) fields that could not be converted.

### Details

After the connection is created data can be extracted using indexing (as in a normal data.frame) or methods such as read_lines and next_block can be used to read in blocks. For processing the file in blocks the (faster) convenience function process_blocks can be used.

Only use `ignore_failed_conversion` when you are sure that the column specification is correct. Otherwise, this option can hide an incorrect specification.

### Value

Object of type `laf`. Values can be extracted from this object using indexing, and methods such as `read_lines`, `next_block`.

### See Also

See `read.fwf` for conventional access of fixed width files.

[Package LaF version 0.8.4 Index]