smart_read {iNZightTools}R Documentation

Read a data file

Description

A simple function that imports a file without the users needing to specify information about the file type (see Details for more). The smart_read() function uses the file's extension to determine the appropriate function to read the data. Additionally, characters are converted to factors by default, mostly for compatibility with iNZight (https://inzight.nz).

Usage

smart_read(
  file,
  ext = tools::file_ext(file),
  preview = FALSE,
  column_types = NULL,
  ...
)

Arguments

file

the file path to read

ext

file extension, namely "csv" or "txt"

preview

logical, if TRUE only the first few rows of the data will be returned

column_types

vector of column types (see ?readr::read_csv)

...

additional parameters passed to read_* functions

Details

Currently, smart_read() understands the following file types:

Value

A dataframe with some additional attributes:

Reading delimited files

By default, smart_read() will detect the delimiter used in the file if the argument delimiter = NULL is passed in (the default). If this does not work, you can override this argument:

smart_read('path/to/file', delimiter = '+')

Author(s)

Tom Elliott


[Package iNZightTools version 2.0.1 Index]