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

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

`Metaboprep` can export data to various formats. 

## Setup

### load the metaboprep library

```{r}
library(metaboprep)
```


### Read in the data and make a Metaboprep object

Create a `Metaboprep` object as described in the [Getting Started](index.html) vignette. 

```{r setup, results='hide'}
# read in the metabolon data as a list object
datain     <- read_metabolon(system.file("extdata", "metabolon_v1.1_example.xlsx", package = "metaboprep"), 
                            sheet="OrigScale", 
                            return_Metaboprep = FALSE)

# build the Metaboprep class object
mydata      <- Metaboprep(data = datain$data, samples = datain$samples, features = datain$features)

```

## Run the quality control

```{r, warnngs=FALSE}
## Adding suppressWarnings() to avoid deparse() error when rendering vignette with S7 method warnings
mydata         <- suppressWarnings( quality_control(mydata) )
```


## Export Metaboprep
```{r export_metaboprep}
# where to put the files
output_dir <- file.path(getwd(), "output")

# run export
export(mydata, directory = output_dir, format = "metaboprep")

# view output directory files
files <- list.files(output_dir, full.names = TRUE, recursive = TRUE)
unname(sapply(files, function(path) {
  parts <- strsplit(path, .Platform$file.sep)[[1]]
  paste(tail(parts, 4), collapse = .Platform$file.sep)
}))
```