load_csv: Load CSV with info about original header

View source: R/all.R

load_csvR Documentation

Load CSV with info about original header

Description

A wrapper for readr::read_csv that uses alrtools::repair_header to fix the header, but keeps a copy of the original values in an attribute.

Usage

load_csv(
  path,
  col_types = NULL,
  na = c("", "NA", "#N/A", "#DIV/0!", "#NAME?", "#REF!", "#VALUE!", "#NULL!"),
  ...
)

Arguments

path

path to the CSV file to load

col_types

One of NULL, a cols() specification, or a string. See vignette("readr") for more details.

na

values to replace with NA – defaults to Excel errors

...

other arguments passed to readr::read_csv

Value

Returns a tibble of the CSV file

Examples

my_data <- data.frame(
  'Seq No' = 1:26,
  'Uppercase Letters' = LETTERS,
  'Lowercase Letters' = letters,
  check.names = FALSE)

temp_path <- tempfile(fileext = '.csv')
write.csv(x = my_data, file = temp_path, row.names = FALSE)

my_data_reloaded <- load_csv(temp_path)

# Fixed Names
names(my_data_reloaded)

# Original Names
attr(my_data_reloaded, 'original_header')

# Clean Up
unlink(temp_path)


adamleerich/alrtools documentation built on Dec. 16, 2024, 8:49 a.m.