setTypes: Set the types in the schema as class of each variable in...

Description Usage Arguments Value See Also Examples

Description

setTypes Set the types in the schema as class of each variable in data.

Usage

1
2
3
4
5
6
7
setTypes(data, StfwfSchema)

## S4 method for signature 'data.frame,StfwfSchema'
setTypes(data, StfwfSchema)

## S4 method for signature 'data.frame'
setChar(data)

Arguments

data

It can be a data.table or a tibble with all its columns of class character.

StfwfSchema

Object of class StfwfSchema with the schema used to read the object data.

Value

Returns a data.table or a tibble with the content of data but with the columns set to the class corresponding to the types in StfwfSchema.

See Also

fread_fwf

Examples

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

# For data.tables
data.DT.char <- fread_fwf(
     file.path(path, 'MicroDataSNHS.txt'), stSchema, validate = FALSE, convert = FALSE,
       outFormat = 'data.table', perl = TRUE)
data.DT.types <- setTypes(data.DT.char, stSchema)
str(data.DT.types)

# For tibbles
 data.tibble.char <- fread_fwf(
      file.path(path, 'MicroDataSNHS.txt'), stSchema, validate = FALSE, convert = FALSE,
       outFormat = 'tibble')
 data.tibble.types <- setTypes(data.tibble.char, stSchema)
 str(data.tibble.types)

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