---
title: "cleanYourFrame"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{cleanYourFrame}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---


```{r message=F, warning=F}
library(framecleaner)
library(dplyr)
```

Data imported from excel and csv in business situations can have messy characteristics and data formats. This package provides functions to tidy your data frame using the power of `tidyselect`.

**create sample data**

```{r}
tibble::tibble(
  date = c("20190101", "20190305", "20201012"),
  numeric_val = c(1, NA, 5),
  char_val = c("", "    val ", "-")
) -> sample_table

sample_table
```

# set nas

Data occasionally has different ways to represent NA values. `set_na` checks as default `c("-", "", " ", "null")` but any values can be supplied to automatically be set to NA. This is helpful when you want to check the NA profile of a data frame using `validata::diagnose`

```{r}
sample_table %>% 
  make_na()
```

# remove whitespace

remove whitespace from the ends of character variables that may be otherwise undetectable by inspection.

```{r}
sample_table %>% 
  remove_whitespace()
```

# set dates

automatically convert character columns that should be dates.

```{r}
sample_table %>% 
  set_date()
```
# relocate all

relocates an unorganized dataframe using heuristics such as putting character and date columns first, and organizing by alphabetical order. 

```{r}
sample_table %>% 
  relocate_all()
```


# clean frame

Wrapper function to apply all cleaning operations to a data frame using sensible defaults. 

```{r}
sample_table %>% 
  clean_frame()
```

# fill nas

use tidyselect to fill NAs with a single value

```{r}
sample_table %>% 
  fill_na()
```
