---
title: "How to use the Pandora Data Package"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{How to use the Pandora Package}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

os_linux <- Sys.info()["sysname"] == "Linux"
```

```{r setup}
library(Pandora)
library(magrittr)
```

# Introduction

This vignette provides an overview of the basic functions within the Pandora 
Data package, allowing users to explore and retrieve information about networks, 
repositories, file types, and resources.


# Show all Networks

To show all available networks use the `getNetworks()` function:

```{r networks}
networks <- getNetworks()
networks %>% 
  knitr::kable()
```

# List Repositories

To list all available repositories use the `getRepositories()` function. You can 
filter the output using the `network` and `pattern` arguments. For instance, to 
list all repositories in the `IsoMemo` network:

```{r repositories}
reposIsomemo <- getRepositories(
  network = "IsoMemo"
  )

reposIsomemo[c("Repository")]  %>% 
  knitr::kable()
```

# List Available File Types

Use the `getFileTypes()` function to list all available file types. The 
following example showcases file types available in the 'IsoMemo' network:

```{r filetypes}
fileTypesIsomemo <- getFileTypes(network = "isomemo")
fileTypesIsomemo  %>% 
  knitr::kable()
```

# Filter Resources by pattern or File Type

To list all available resources, employ the `getResources()` function. Filter 
the output using the `network`, `repository`, `fileType`, and `pattern` 
arguments. For instance, to list all CSV files whose meta information contains the string `plants`:


```{r resources}
resourcesPlants <- getResources(
  fileType = c("csv"),
  pattern = "plant"
  )

resourcesPlants[c("name", "format")]  %>% 
  knitr::kable()
```

# Get the data of a Specific Resource

To retrieve data from a specific resource, use the `getData()` function. For text files one can 
specify e.g. the separator using the helper function `dataOptions()`. The example below demonstrates
fetching data from the `"CIMA Humans 29.05.2021 CSV"` resource:

```{r getdata}
isotopicData <- getData(
  name = "CIMA Animals 29.05.2021 CSV",
  options = dataOptions(sep = ";")) 
isotopicData  %>% 
  head(5)  %>% 
  dplyr::select(c("Entry_ID", "General_Category_Family", "Common_Name", "Sampled_Element", "Analysed_Component")) %>%
  knitr::kable()
```
