fread_fwf: Fast read a fixed-width file.

Description Usage Arguments Value See Also Examples

Description

fread_fwf takes as basic input a fixed-width filename and its schema and wraps around fread from package data.table or around read_fwf to provide the contents of the file.

This method is indeed either (i) a wrapper for the function fread followed by the application of stri_sub or (ii) a direct wrapper for the function read_fwf.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
fread_fwf(
  filename,
  StfwfSchema,
  validate = FALSE,
  convert = TRUE,
  outFormat = "data.table",
  perl = FALSE,
  ...
)

## S4 method for signature 'character,StfwfSchema'
fread_fwf(
  filename,
  StfwfSchema,
  validate = FALSE,
  convert = TRUE,
  outFormat = "data.table",
  perl = FALSE,
  encoding = "unknown",
  ...
)

Arguments

filename

Character vector of length 1 with the name of the file to read.

StfwfSchema

Object of class StfwfSchema with the schema of the file to read.

validate

Logical vector of length 1 with default value FALSE to indicate whether to validate the content of filename with the regular expressions in StfwfSchema. This step is done before converting the types.

convert

Logical vector of length 1 with default value TRUE to indicate whether to convert the content of filename to the types in StfwfSchema.

outFormat

Character vector of length 1 whose default value is "data.table". Other option is "tibble".

perl

Logical vector of length 1 with default value FALSE to indicate whether to use perl or not in the application of the column regexp.

...

Other parameters from fread or read_fwf according to the value of outFormat above.

encoding

Optional argument with the encoding to be used by fread, by default 'unknown' (see fread).

Value

Returns a data.table or a tibble with the contents of the file.

See Also

fread

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
path <- system.file('extdata', package = 'fastReadfwf')
stSchema <- fastReadfwf::StxlsxToSchema(file.path(path, 'SchemaSNHS.xlsx'), 'stSchema')

# For data.tables
data.DT <- fread_fwf(
file.path(path, 'MicroDataSNHS.txt'), stSchema, outFormat = 'data.table', perl = TRUE)
head(data.DT)

# For tibbles
data.tibble <- fread_fwf(
file.path(path, 'MicroDataSNHS.txt'), stSchema, outFormat = 'tibble')
head(data.tibble)

david-salgado/fastReadfwf documentation built on Dec. 25, 2021, 12:43 p.m.