---
title: "Manually Upload Data to TAXSIM 35"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Manually Upload Data to TAXSIM 35}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(usincometaxes)
```

`usincometaxes` sends data to the National Bureau of Economic Research's (NBER) [TAXSIM 35](http://taxsim.nber.org/taxsim35/) server. The data must meet TAXSIM 35's requirements for data types and column names. `usincometaxes` performs checks to ensure the data will be accepted by TAXSIM 35. It's possible, however, that issues will slip through. This can produce cryptic errors that might be hard to location. If you receive errors that you cannot correct it could be helpful to manually upload your data to TAXSIM 35's servers.

`usincometaxes` provides a function, `create_dataset_for_taxsim()`,  to format your data for manual uploading. To use the function, prepare your dataset as you normally would to use `taxsim_calculate_taxes()`. For example, follow the formatting required for [input columns](https://www.shaneorr.io/r/usincometaxes/articles/taxsim-input.html). Then, supply the dataset to `create_dataset_for_taxsim()`.

```{r}
data(taxpayer_finances)

taxsim_dataset <- create_dataset_for_taxsim(taxpayer_finances)

knitr::kable(head(taxsim_dataset))
```

Then, save this dataset as a csv file to your local computer. It is recommended to use `readr::read_csv()` to write out the dataset. `write.csv` tends to pose issues. Also note that you can name the `.csv` file anything you wish.

```{r eval = FALSE}
taxsim_filename <- 'taxsim_dataset.csv'

vroom::vroom_write(taxsim_dataset, taxsim_filename)
```

Now, manually upload the  file `taxsim_dataset.csv` to TAXSIM 35's server by going to (https://taxsim.nber.org/taxsim35/), navigating to the section titled 'OR...Upload a (not too large) file with TAXSIM data:', and uploading the `.csv` file:

Errors from the manual upload could guide you in solving any data formatting issues.
