setChar: Set the class of each variable in data to character.

Description Usage Arguments Value See Also Examples

Description

setChar Set the class of each variable in data to character and the NA values to empty string.

Usage

1

Arguments

data

It can be a data.table or a tibble.

Value

Returns a data.table or a tibble with the content of data but with all the columns set to character.

See Also

fwrite_fwf setTypes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)
data.DT.back <- setChar(data.DT.types)
head(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)
 data.tibble.back <- setChar(data.tibble.types)
 head(data.tibble.types)

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