# Import - Export app guide

## Introduction

The aim of this shiny app is to provide a simple way to convert (import and export) data sets between the most common formats such as plain text (.txt, .csv), SPSS (.sav) or Excel (.xlsx, .xls) keeping the user to having to search the most appropiate R function or tool in each case. Also, the implemented functions guarantee the least loss of the data information, giving special attention to the date variables and the labelled ones.

This app also offers multiple ways to check the database making easier to find out any potential problem during the import / export process.

The user must follow three steps in order to complete all the process and receive the data set in the desired extension. But, before introducing each step, we will see the structure of the app.

## App form structure

The form of this app is divided into two panels:

- A left panel with three sections ("Step1", "Step2" and "Step3") or panels which are collapsed by default. To uncollapse them (display their contents) we need to click on their headers. These options can be different depending on the extension (e.g. Excel, SPSS, etc.). Note that you can find some butttons which display even more options on a pop-up.

- In the right panel you will see a set of panels with the file panel opened by default. We can switch between them by clicking on the name of each one, but at start they all will be empty. This whole section displays information about the database we are converting in different ways, which will be explained at "Step2" section.

## Step1) Format detection + import

In this first step we need to select the file (maybe placed locally in our computer) containing the database we want to convert. Once the file is selected, if we still have the "file" panel open in the right section we will see the format that has been automatically detected. Then, we can see a selected checkbox that assumes the format is correct. If not, we can unselect it and choose the right format.

When we have the selected file with its appropriate format we will see a button labelled "Show import options" which will display a pop-up containing mandatory and optional options to perform the import process. The pop-ups may also contain a link to the description of the used R function.

Finally, we can close the pop-up, press the import button and go to the next step.

## Step2) Database checkup

Even though this step has few options in the scroll panel, the most important elements are at the right panel.

In the scroll panel we can see a checkbox to run format_corrector (a function to fix some format problems, detailed in the help link from above) and a list with the variables stored in the dataset. We can select which of these variables we want to keep.

In the right panel we can see four tabs with relevant information of the dataset.

- File: In this table the status of the dataset we are working with is displayed. We can see the format used to read it, the selected variables and know if the data has been modified using format_corrector function.

- Var_view: In this tab the output of the var_view function is displayed, which provides a table containing relevant information about the variables, such as their class or their labels.

- Datatable: In this tab the values contained in the read dataset are displayed under the shiny Datatable format which provide several tools to filter, sort, etc. the table.

- Summary: In this tab, some descriptives are displayed making use of the compareGroups package.

## Step3) Export

##

This is the last step and is pretty similar to the first one. The first list allows us to select the format we want. Similar to the first step, each format will have different options, and most of them will have an "export options" button which will display a pop-up with more options.

Most of the formats can be just downloaded using the "download" button, but there are special formats like Microsoft Access or SPSS which will be downloaded in a different way:

- Microsoft Access: The function to export data to Microsoft Office Access can not create new files, it can just add tables to an existing file so instead of downloading a file, the last step of the Access export will be selecting an existing file in our computer to add the data we have in the app.

- SPSS: The function to export data to SPSS does not create the .sav file directly so it can't be downloaded. The function needs an environment (a folder) to export the data and the spss code and then run the spss runsyntax to finally create the .sav file.

## Import and export R functions

### Import:

File format | Function | Description
--- | --- | ---
Plain text (.txt, .csv) | table_import | Created function that calls read.table and automatically detects the field separator.
Excel (.xls, .xlsx) | read_excel | Function from the readxl package. It can read both .xls and .xlsx.
SPSS (.sav) | spss_import | Created function that calls spss.get from Hmisc package and detects date variables automatically.
Microsoft Acces (.mdb) | access_import | Created function that simplifies the RODBC package functions to read from Access in a rather simple way.
Stata (.dta) | read_dta | Function from haven package.
SAS | read_sas, read.xport | Function from the foreign and haven package respectively, depending on the data extension we will need one or another.

### Export

File format | Function | Description
--- | --- | ---
Plain text (.txt) | write.table | Function from R base package.
Plain text (.csv) | write.csv | Function from R base package to export data to comma or semicolon separated variables.
Excel (.xls, .xlsx) | excel_export | Created function that calls write_xlsx from writexl package. It can write to multiple sheets.
SPSS (.sav) | spss_export | Created function that builds the SPSS file by executing SPSS software (or alternatively PSPP) from generated plain text data and code files.
Microsoft Acces (.mdb) | access_export | Created function that simplifies the RODBC package functions to write ACCESS tables in a rather simple way.
Stata (.dta) | write_dta | Function from haven package.
SAS | write, read.xport | Function from foreign package.